[antlr-interest] Syntactic predicate Issue

Jim Idle jimi at temporal-wave.com
Wed Aug 25 11:18:11 PDT 2010


Please use http://antlr.markmail.org  where you will find this issue
addressed many times. It is because the reference to the local input
variable is not available to the DFA code, you have to use scopes instead.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Massimiliano D
> Sent: Wednesday, August 25, 2010 11:16 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Syntactic predicate Issue
> 
> 
> Hi, i have some problem in generated java code form one rule like this:
> 
> grant_statement
>     :    'GRANT'
>     (    grant_system_privilege
>     |    grant_object_privilege
>     )
>     ;
> 
> grant_object_privilege
>     :    privilege[false] (COMMA privilege[false])* 'ON' on_object_clause
>         grantee_clause ('WITH' 'HIERARCHY' 'OPTION')? ('WITH' 'GRANT'
> 'OPTION')?
>     ;
> 
> privilege[boolean isSystemPriv]
>     :    {isSystemPriv }? priv_sys
>     |    {!isSystemPriv}? priv_obj
>     ;
> 
> grant_system_privilege
>     :    privilege[true] (COMMA privilege[true])*
>         grantee_clause ('IDENTIFIED' 'BY' .+)? ('WITH' 'ADMIN' 'OPTION')?
>     ;
> 
> grantee_clause
>     :    'TO' (IDENTIFIER
>     |    'PUBLIC'
>     )    (COMMA (IDENTIFIER | 'PUBLIC'))*
>     ;
> 
> whe i try to debug i got this error: cannot find symbol because in 2
generated
> classes called DFAXXX the code looks like this:
> 
> public int specialStateTransition(int s, IntStream _input) throws
> NoViableAltException {
>             TokenStream input = (TokenStream)_input;
>             int _s = s;
>             switch ( s ) {
>                     case 0 :
>                         int LA97_8 = input.LA(1);
> 
> 
>                         int index97_8 = input.index();
>                         input.rewind();
>                         s = -1;
>                         if ( (evalPredicate(isSystemPriv ,"isSystemPriv
")) ) {s = 1;}
> 
>                         else if (
(evalPredicate(!isSystemPriv,"!isSystemPriv")) ) {s = 27;}
> 
> 
>                         input.seek(index97_8);
>                         if ( s>=0 ) return s;
>                         break;
>                     case 1 :
>                         int LA97_15 = input.LA(1);
> 
> 
>                         int index97_15 = input.index();
>                         input.rewind();
>                         s = -1;
>                         if ( (evalPredicate(isSystemPriv ,"isSystemPriv
")) ) {s = 1;}
> 
>                         else if (
(evalPredicate(!isSystemPriv,"!isSystemPriv")) ) {s = 27;}
> 
> 
>                         input.seek(index97_15);
>                         if ( s>=0 ) return s;
>                         break;
>                     case 2 :
>                        ........................
>                        ........................
>                        .......................
>             }
>             if (state.backtracking>0) {state.failed=true; return -1;}
>             NoViableAltException nvae =
>                 new NoViableAltException(getDescription(), 97, _s, input);
>             error(nvae);
>             throw nvae;
>         }
>     }
> 
> but obviusly the isSystemPriv variable is not defined, am i missing
> something??
> 
> Thanks Max.
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address



More information about the antlr-interest mailing list