A newbie question?

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

A newbie question?

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Message
Hi there...I'm trying to construct an abstract syntax tree production that takes three productions in any order, but they cant be repeated, nor can they be left out. How does one construct such a production with SableCC, short of expressing all of the different permutations of the three production names?
 
For example:
 
precedence    =        defaults rows columns
    |                        rows columns defaults
    |                        columns rows defaults
    |                        columns defaults rows
    |                        rows defaults columns
;
 
I thought of this:
 
precedence = token token token;
 
token = row | column | default;
 
but that permits row row row, etc, which are invalid.  
 
I suppose this could be handled in a semantic step, but is there a better way? 
 
 
 
 

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

RE: A newbie question?

by Alastair Donaldson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

RE: A newbie question?

I think handling this in a semantic step is preferable, that way you can give the user a good message if they make a mistake.

The only other way I can think of is:

precedence = defaults rows_or_columns |
             rows defaults_or_columns |
             columns defaults_or_rows ;

rows_or_columns = rows | columns ;

defaults_or_columns = defaults | columns ;

defaults_or_rows = defaults | rows ;

This is still pretty bad, but at least it structures the options a little more than a straight list of all combinations.

-Alastair.


-----Original Message-----
From: sablecc-discussion-bounces+ally=dcs.gla.ac.uk@... on behalf of Christopher Van Kirk
Sent: Thu 31/01/2008 6:31 AM
To: sablecc-discussion@...
Subject: A newbie question?

Hi there...I'm trying to construct an abstract syntax tree production that
takes three productions in any order, but they cant be repeated, nor can
they be left out. How does one construct such a production with SableCC,
short of expressing all of the different permutations of the three
production names?

For example:

precedence    =        defaults rows columns
    |                        rows columns defaults
    |                        columns rows defaults
    |                        columns defaults rows
    |                        rows defaults columns
;

I thought of this:

precedence = token token token;

token = row | column | default;

but that permits row row row, etc, which are invalid. 

I suppose this could be handled in a semantic step, but is there a better
way?






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

RE: A newbie question?

by S'orlok Reaves :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I agree with Alastair; just do:
  precedence = token token token;
  token = row | column | default;
...and then catch errors like "each token must be used
once and only once" in your parser. But it's up to
you.

-->Seth



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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