Fwd: Re: nested lists in SableCC 3

View: New views
5 Messages — Rating Filter:   Alert me  

Fwd: Re: nested lists in SableCC 3

by fedewi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi Ethiene

 

I have the following grammar

 

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 ?

 

 

Thank very much you for your help !

 

Federico Wiecko

MSc Student, LSIS,

Luxembourg University

This message was written in a character set (UTF-8) other than your ow.

If it is not displayed correctly, click here to open it in a new window.
Hi Federico,

SableCC 3 flattens nested lists. This behavior was chosen as:
  1. it is simple to understand, and
  2. to allow them, we would have had to either:
    1. add some notation for nested lists in the AST section (and in generated code!), or
    2. forbid the use of nested lists in CST to AST transformations.
So, this translates into the following notation:
role_field {->role_field} =
{role} role role_field_name+ {->New
role_field.role ([role_field_name.name], [role_field_name.type])}
This will create two lists: a list of names and a list of types. The list of names will contain names (not lists of names); this is what I mean by flattening.

Etienne

fedewi wrote:

How should I deal with a list of tuples of lists both in the CST and AST ? (I was looking without success for examples of this cain of transformations).


-- 
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


--- Ехжы дроеп? Явюедк пв п.о хюрб тражрюиб хнигчи! http://www.pochta.ru/partner/

----- End forwarded message -----


--- еУФШ ДПНЕО? ъБЧЕДЙ ОБ О.Н УЧПА РПЮФПЧХА УМХЦВХ! http://www.pochta.ru/partner/
_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Fwd: Re: nested lists in SableCC 3

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Fwd: Re: nested lists in SableCC 3

by fedewi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

 Hi Etienne

 

I have read your answer many times but I am still having problems with this.

 

Why did you say that defining an object with many field names in this case is incorrectly at the philosophical level ?

I think that you mean that defining
object_field = {object} object object_field_name+
is icorrectly and should be written in another way, in that case how ?

In my languaje I want to permit expressions like this:


object obj1, obj2,obj3 : type;
       obj4, obj5, obj6 : type2;

where object is a reserved word.

 

I think I understand what you mean in your email but I still need a way to match from
[ ([object_field_name.name], object_field_name.type ) ] ---> [ ([names], type)]

I don't want to create object_field_name objects in the AST because it is only useful for parsing.
I also know that having list of list in SableCC is forbidden, but the solution that you propose below is not useful in this case because of the lost of  the associations between names and types.

Do you know if there is any documentation about all of these things ?

 

Thank you very much for your help and patience. 

 

 Federico Wiecko .-

 

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


--- еУФШ ДПНЕО? ъБЧЕДЙ ОБ О.Н УЧПА РПЮФПЧХА УМХЦВХ! http://www.pochta.ru/partner/
_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Fwd: Re: nested lists in SableCC 3

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Federico,

You really want an AST that looks similarly to:

  objects = declaration+;
  declaration = name+ type;

This will keep the two levels of list that you need for keeping the
relation between names and types.

Have fun,

Etienne

fedewi wrote:

>
> In my languaje I want to permit expressions like this:
>
> object obj1, obj2,obj3 : type;
>        obj4, obj5, obj6 : type2;
>
> where object is a reserved word.
>
> I think I understand what you mean in your email but I still need a
> way to match from
> [ ([object_field_name.name], object_field_name.type ) ] ---> [
> ([names], type)]
>
--
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

How to get line#?

by Dehua Zhang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi guys,

I had transformed my CST to AST.

but for most situations, I did not keep Tokens in the AST, for example,

...
exp =
  {l_value} l_value
| {eq} [lhs]:exp [rhs]:exp
| {lt} [lhs]:exp [rhs]:exp
| {gt} [lhs]:exp [rhs]:exp
...

however, when traversing the AST by extends the DepthFirstAdapter, I can not get the line# of an exp.

How to solve it?

--
Dehua (Andy) Zhang
Sable Research Group, McGill University
Montréal, Québec, Canada
http://www.cs.mcgill.ca/~dzhang25

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion
LightInTheBox - Buy quality products at wholesale price