« Return to Thread: Fwd: Re: nested lists in SableCC 3

Re: Fwd: Re: nested lists in SableCC 3

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View in Thread

Hi Federico,

In your parsing grammar, you define an object field as an object with many field names. I think that this is the source of your problem (at the philosophical level). Of course, the immediate technical problem is that SableCC is detecting an incoherency in your transformations.

You transform every object_field_name into a list of names and a type. That's fine.

You also try to transform a CST object which is composed of a list of object_field_name into an AST object which is composed of a list of name and a single type.  Of course, SableCC is complaining, as every object_field_name has its own type. You are trying to replace a whole list of types by a single type; SableCC does not do this kind of transformation. SableCC's error message is less than clear, I admit (I didn't write this code). I promise that SableCC 4 will have clearer messages.

A "technical" (yet wrong) solution to your problem is to keep a list of types:

Productions
 ...
  {object} ... {->New object_field.object(..., [object_field_name.type])}
...
Abstract Syntax Tree
...
  {object} name+ type+
...

But this is probably not what you want at the philosophical (i.e. semantic) level.  I'll let you find the good solution as an exercise.

Have fun!

Etienne


fedewi wrote :

object_field =
{object} object object_field_name+ {->New object_field.object([object_field_name.name], object_field_name.type)}
| {objects} objects object_field_name+ {->New object_field.objects([object_field_name.name], object_field_name.type)};

object_field_name {-> name* type } =
name_list colon type semi {-> [name_list.name] type};

Abstract Syntax Tree

object_field =
{object} name+ type
| {objects} name+ type;

but the parser complains with this message

java.lang.RuntimeException: [138,93] object_field_name must be one of the elements on the left side of the arrow or is already refered to in this alternative
at org.sablecc.sablecc.ResolveTransformIds.error3(ResolveTransformIds.java:1012)
at org.sablecc.sablecc.ResolveTransformIds.inASimpleTerm(ResolveTransformIds.java:380)
at org.sablecc.sablecc.analysis.DepthFirstAdapter.caseASimpleTerm(DepthFirstAdapter.java:875)

What do you think is wrong here ?


-- 
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org
SableVM:                                            http://sablevm.org


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

signature.asc (257 bytes) Download Attachment

 « Return to Thread: Fwd: Re: nested lists in SableCC 3

LightInTheBox - Buy quality products at wholesale price!