Hi Steve,
SableCC 3.x (stable) does not have precedence directives. The
reason is that the Bison/Yacc-like directives can easily modify
the parsed
language without issuing warnings about it. The
generated parser could parse a language that is not described by
the (directive-less) grammar. This is scary; you end up not
knowing exactly what the parsed language is. By design, SableCC
does not allow for such unsafe directives.
But, this is not a big limitation. Rewriting a grammar to
implement precedence levels is pretty straight forward. You will
find a detailed explanation of how to do it in the old
mailing-list archive:
http://lists.sablecc.org/pipermail/sablecc-discussion/msg00433.html
You can see a real life example in the Java grammar that has many
precedence levels (was it 17 levels?):
http://sablecc3.sablecc.org/wiki/Java-1.5
SableCC 4 will support precedence directives in a restricted but
safe manner. Precedence directives, in SableCC 4, do not modify
the
language described by the
grammar; they can
only serve as a
disambiguation mechanism.
Definitions:
- Language: The (possibly infinite) set of accepted
strings (i.e. the set of syntactically accepted programs).
- Grammar: Finite description of a language (using
productions, etc.).
- Ambiguity: A grammar is ambiguous if it allows for
two (or more) distinct syntax trees for the same string (i.e.
program).
- Disambiguation: Selecting one specific tree among the
many syntax trees of a string, given an ambiguous grammar.
Have fun!
Etienne
Etienne Gagnon, Ph.D.
http://sablecc.org