On Thu, 2008-10-23 at 15:24 -0500, Sam Harwell wrote:
> When this grammar is given the following input, a few bugs are
> observed, as shown in the output.
I think that your grammar just has a path encoded that allows it to try
accessing the scope when there is nothing in it. Move the scope up to a
level where this cannot happen, or test for the stack being empty and
assume that this means false or true or whatever it means to your
logic ;-)
Jim
>
>
>
> Input: “ident ident” (no quotes)
>
>
>
> Output:
>
> Setting scope at level 1 to true
>
> 4: b is false size = 2 bt = 2
>
> 3: b is false size = 2 bt = 2
>
> 2: b is false size = 2 bt = 2
>
> 4: b is true size = 1 bt = 1
>
> 4: b is false size = 2 bt = 1
>
> 3: b is false size = 2 bt = 1
>
> 2: b is false size = 2 bt = 1
>
> 1: b is true size = 1 bt = 1
>
> Exception in thread "main" java.util.EmptyStackException
>
> at java.util.Stack.peek(Unknown Source)
>
> at
> TestSemPredScopesParser.test(TestSemPredScopesParser.java:98)
>
> at __Test__.main(__Test__.java:14)
>
>
>
> Grammar:
>
>
>
> grammar TestSemPredScopes;
>
>
>
> scope MyScope { boolean b; }
>
>
>
> @parser::members {
>
> boolean report( int n, boolean b ) {
>
> System.err.println( n + ": b is " + b + " size = " +
> MyScope_stack.size() + " bt = " + state.backtracking);
>
> return true;
>
> }
>
> }
>
>
>
> test
>
> : ( (subrule1) => subrule1
>
> | subrule2
>
> )
>
> EOF
>
> ;
>
>
>
> subrule1
>
> scope MyScope;
>
> : nest1subrule1
>
> ;
>
>
>
> nest1subrule1
>
> @init
>
> {
>
> System.err.println( "Setting scope at level " +
> MyScope_stack.size() + " to true" );
>
> $MyScope::b = true;
>
> }
>
> : (nest2subrule1) => nest2subrule1 {report(1,
> $MyScope::b)}?
>
> | subrule2
>
> ;
>
>
>
> nest2subrule1
>
> scope MyScope;
>
> : nest3subrule1 {report(2,$MyScope::b)}? ;
>
>
>
> nest3subrule1
>
> : {report(4,$MyScope::b) /*&& !$MyScope::b*/}? =>
> {report(3,$MyScope::b)}? IDENTIFIER IDENTIFIER
>
> ;
>
>
>
> subrule2 : IDENTIFIER ;
>
>
>
> IDENTIFIER : ('a'..'z')+ ;
>
> WS : (' ' | '\t')+ {$channel = HIDDEN;} ;
>
>
>
>
>
> _______________________________________________
> antlr-dev mailing list
> [email protected]
> http://www.antlr.org:8080/mailman/listinfo/antlr-dev
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org:8080/mailman/listinfo/antlr-dev