[antlr-interest] Problem with Syntactic Predicate

Alexander Gängel alexander at gaengel.de
Tue Feb 26 08:58:30 PST 2008


I just don't get this Syntactic Predicate to work

the Problem is variableDeclaration I just don't see what I'm doing wrong 
to get Input like:

test; test:Type;test to work.

Alexander

grammar test;

options  {
    output=AST;
    ASTLabelType=CommonTree;
    }
 
tokens {
    PATH;
    Var;
    Type;
    TupleType;
    }

start    :    variableDeclarationPart EOF;

variableDeclaration   
    :(variableDeclarationPart SEMICOLON )=> variableDeclarationPart 
SEMICOLON variableDeclaration
    |variableDeclarationPart
    ;
   
variableDeclarationPart
    :Identifier (COLON typeCS)?;
   
typeCS    :
    (Identifier DOUBLE_COLON )=> Identifier DOUBLE_COLON typeCS ->^(Type 
^(PATH Identifier typeCS))
    |Identifier -> ^(Type ^(PATH Identifier))
    |tupleTypes -> ^(Type  tupleTypes)
    ;
   
tupleTypes
    :
    'TupleType' '(' variableDeclaration ')' -> ^(TupleType 
variableDeclaration)
    ;
   
DOUBLE_COLON
    :'::';
COMMA    :',';
SEMICOLON    :';';
COLON    :':';
Identifier    :   ('a'..'z'|'A'..'Z'|'_') (Letter)*;
fragment
Letter    :'a'..'z'|'A'..'Z'|'0'..'9'|'_'|'$';
WS    :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};




More information about the antlr-interest mailing list