[antlr-interest] why will this be parsed (no exception)?

Alexey Demakov demakov at ispras.ru
Thu Nov 24 05:07:56 PST 2005


It's because you don't have EOF at the end of run rule:

run
: expression EOF
;

and parser simply returns after it found something that is not a part of expression

Now it will try to match EOF but wil find IDENT
 
Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com


----- Original Message ----- 
From: <Oliver.Kowalke at infineon.com>
To: <antlr-interest at antlr.org>
Sent: Thursday, November 24, 2005 3:55 PM
Subject: [antlr-interest] why will this be parsed (no exception)?


> Hello,
> if I let parse the string "adder && repeater quatsch" I doen't get an
> exception thrown. Why? 'quatsch' is not be recognized in the
> productions.
> I hope you can give me some advice how to get this right (throw an
> exception).
> With best regards,
> Oliver
> 
> options
> {
> language="Cpp";
> namespace="ymfl";
> }
> 
> class FilterLexer extends Lexer;
> options 
> {
>    k=2;
>    exportVocab=YMFL;
>    charVocabulary='\u0000'..'\u007F';
>    caseSensitive=false;
>    caseSensitiveLiterals=false;
> }
> 
> tokens
> {
> ADDER = "adder";
> REPEATER = "repeater";
> }
> 
> AND
> options { paraphrase = "&&"; }
> : "&&"
> ;
> 
> OR
> options { paraphrase = "||"; }
> : "||"
> ;
> 
> NOT
> options { paraphrase = "!"; }
> : '!'
> ;
> 
> DELIM 
> options { paraphrase = "an delimeter (' ' \t \f \r \n)"; }
> : ( ' '
> | '\t'
> | '\f'
> | ( "\r\n"
> | '\r'
> | '\n'
> )
> { newline(); }
> )
> { $setType( antlr::Token::SKIP ); }
> ;
> 
> IDENT
> options {testLiterals=true;}
> : ('a'..'z') ('a'..'z'|'0'..'9')*
> ;
> 
> /////////////////////////////////////////////////////////////////////
> // Parser
> /////////////////////////////////////////////////////////////////////
> 
> class FilterParser extends Parser;
> 
> options 
> { 
>    k=2;
>    exportVocab=YMFL;
> }
> 
> existence_op
> : 
> (
> ADDER
> | REPEATER
> )
> ;
> 
> primitive
> : 
> existence_op
> ;
> 
> negation_expression
> : 
> (
> primitive
> | NOT primitive
> )
> ;
> 
> expression
> : negation_expression
> ( 
> (
> AND 
> | OR 
> ) 
> negation_expression
> )*
> ;
> 
> run
> : expression
> ;
> 
>



More information about the antlr-interest mailing list