[antlr-interest] Problem with Syntactic Predicate
David Sweet
edsweet at swbell.net
Tue Feb 26 09:21:10 PST 2008
Hello Alexander,
Should your start line read as follows:
start : variableDeclaration EOF;
I found that running your grammar ran emitted some "MismatchedToken"
errors (SEMICOLONS were not expected I guess), but changing
variableDeclarationPart to variableDeclaration parsed the input test;
test:Type and created the AST I sort of expected.
Regards,
David Sweet
Alexander Gängel wrote:
> 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