[antlr-interest] Re: syn pred / lookahaed doesn't work
Gunnar Wagenknecht
kreismeister at yahoo.de
Tue Mar 11 12:06:14 PST 2003
--- In antlr-interest at yahoogroups.com, "cintyram" <cintyram at y...>
wrote:
> from what you have given i assume the follwoing :
> 1. a compilation unit is a statement list followed by zero or more
> functions
> 2. a statementlist is a list of zero or more statements
> 3. and a statement is a variable declaration or "exit" or something
> else ..
That is right. The functions are function declarations. All
statements before the first function declaration belongs to a non-
declared "main" function and all statements after a function
declaration belongs to the declared function.
> in this case it is clear that for a look ahead of 1, ie at k=1 ,
That's why I configured a lookahead of "k=2".
> also i am asking out of personal suspicion did you have an alt
which
> means that a statement rule can match a function also?
> like
> statement : other alts
> | function /// do you have this in your grammar?
> | other alts
> ;
No, this is not allowed. A statement is not allowed to have a
function declaration.
> however i suggest that you should post the actual predicates that
you
> used, to know why they dont seem to work ;
I tried LA in the statement rule to ensure a variable declaration is
only matched if (("static"|"public"|...) IDENTIFIER) is found. But
the generated parser ignores this completly.
The parser only contains a switch-case block in the statement rule
similar to:
switch(LA(1))
{
...
case LITERAL_static:
variableDeclaration();
...
}
So any "static" causes the parser to matched asvariable declaration.
It doesn't care about a "function" or IDENTIFIER after this.
Cu, Gunnar
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list