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


The top-level rule in the SableCC grammar is

grammar = P.package? P.Helpers? P.states? P.tokens? ign_tokens? P.productions?;

But it's convenient for a grammar writer to have a stock template, especially because the order of these sections is fixed.

/* Stock header for my template */
Package ;
Helpers ;
States ;
Tokens ;
Ignored  Tokens ;
Productions ;

In the current grammar for SableCC, the above is invalid. In fact, any time any of those sections is empty, you're not allowed to use the keyword for that section.

A few small changes to the grammar would allow empty sections without invalidating the grammar or having to comment out a section.

helper_def = helper? semicolon;
helper = id equal reg_exp;

token_def = token? semicolon;
token = state_list? id equal reg_exp look_ahead?;

prod = production? semicolon;
production = id equal alts;

The ramification of this is that extra semicolons can be used without getting syntax errors, at the cost of recognizing (and ignoring) empty helpers/tokens/productions.

Steven Kelem, Ph.D.