Date: Wed, 24 Sep 1997 10:45:53 -0400 From: Binoy Samuel To: Karl Lieberherr CC: binoy@ccs.neu.edu Subject: Lookahead ll(k) usage ** *lookahead* keyword Parser lookahead directives can be specified at choice points in the class dictionary grammar with "*lookahead* (@ @)". A choice point is one of: * An alternation: Foo : *lookahead* (@ 2 @) Bar | Baz. // lookahead 2 applies only to Bar * An optional part: Foo = [ *lookahead* (@ 2 @) Bar ]. * A repetition part: Foo ~ { *lookahead* (@ 2 @) Bar }. A lookahead directive is one of: * An integer: the number of tokens to look ahead. (default is 1) * A parser rule or set of rules: each class Foo has a rule _Foo(); a lookahead directive (@ _Foo() _Bar() @) means to look ahead until Foo and Bar have been matched. * A lookahead directive (@ ("x" | "y") "z" @) means to lookahead until you find token 'x' followed by 'z' or 'y' followed by 'z'. * An arbitrary boolean Java expression, inside curly brackets. See the file examples/Lookahead/README in the JavaCC distribution for more detail on how this works and when it is needed. ------- We recommend that you make your class dictionaries LL(1) (use no lookahead rules) if the language is under your control. The language will be easier to learn and read.