[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (probably very naive) question regarding production grammar


> Their grammar allows for [] and {} sections in productions (see
> http://cui.unige.ch/db-research/Enseignemen),
> which sablecc does not (at least not the {} sections). I didn't 

Sablecc does support these productions. Optional terms have a ? after 
them, 0-or-more have a *, and 1-or-more have a +. (Same as for tokens)
See http://sablecc.org/thesis/thesis.html#PAGE46

> think it
> would be hard to rewrite them as recursive rules, but I apparently 
> musthave done something wrong because sablecc will not process the 
> grammarincluded below. It does not like the first rule in this 
> production:

>    logical_factor =
>        {compare} exp_simple compare exp_simple |
>        {condition} lparen condition rparen;

The parser cannot distinguish between either exp_simple... which one 
would getExpSimple() refer to? They need names:

    logical_factor =
        {compare} [left]:exp_simple compare [right]:exp_simple |
        {condition} lparen condition rparen;

Now you could use getLeft() and getRight().