[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Lookahead -- javacc vs sablecc
On Thu 2006-11-16 at 10:45h, Artur Rataj wrote on sablecc-user:
> Hello. I am evaluating whether to use javacc or sablecc, and I was
> browsing the java grammars written in both. In javacc, there seems
> to be a substantial amount of some explicit lookahead definitions,
> while in sablecc I have not seen any.
>
> What is the reason of this? Are sablecc grammars on some higher
> level or what?
SableCC supports LALR(1) grammars while JavaCC only supports the more
restricted set of LL(1) grammars. To compensate, JavaCC supports
lookahead specifications, which formally are not part of the actual
grammar. In a sense, JavaCC is more "hackish" or "ad hoc" here (and
testing input for lookahead conditions can also sometimes be costly),
while SableCC has a "purer" approach.
It often appears to be easier to just write lookahead specifications
than to write a proper LALR(1) grammar, but that doesn't necessarily
mean that it's really preferable. In particular, lookahead
specifications can make it harder to understand or verify what
language the generated parser will actually parse.
Note also that SableCC's "inlining" feature can automatically resolve
certain conflict situations where it might otherwise seem to be
attractive to use a lookahead specification.
-- Niklas Matthies