[antlr-interest] problem with TreeParser grammar -> <AST>:
unexpected AST node: 'abc'
Oliver.Kowalke at infineon.com
Oliver.Kowalke at infineon.com
Tue Dec 20 00:19:19 PST 2005
Hello,
I don't know why the tree parser grammar doesn't work if I try to parse
" otype in ('abc','efg') ":
<AST>: unexpected AST node: 'abc'
Could please help me?
Regards,
Oliver
Grammar:
header "pre_include_hpp"
{
#include <string>
#include <antlr/AST.hpp>
}
options
{
language="Cpp";
namespace="ymfl";
}
/////////////////////////////////////////////////////////////////////
// Lexer
/////////////////////////////////////////////////////////////////////
class FilterLexer extends Lexer;
options
{
k=2;
exportVocab=YMFL;
charVocabulary='\u0000'..'\u007F';
caseSensitive=false;
caseSensitiveLiterals=false;
}
tokens
{
ADDER = "adder";
IN = "in";
OTYPE = "otype";
REPEATER = "repeater";
XSIZE = "xsize";
YSIZE = "ysize";
}
protected MINUS
options { paraphrase = "-"; }
: '-'
;
protected PLUS
options { paraphrase = "+"; }
: '+'
;
protected POINT
options { paraphrase = "."; }
: '.'
;
protected SIGNUM
options { paraphrase = "'-' or '+'"; }
: MINUS | PLUS
;
protected DIGIT
options { paraphrase = "an digit"; }
: '0'..'9'
;
protected INT
options { paraphrase = "an integer"; }
: ( SIGNUM )? ( DIGIT )+
;
protected EXPONENT
options { paraphrase = "an signed exponent"; }
: 'e' ( SIGNUM )? ( DIGIT )+
;
protected REAL
options { paraphrase = "an real"; }
: ( SIGNUM )?
( POINT ( DIGIT )+ ( EXPONENT )?
| ( DIGIT )+ POINT ( ( DIGIT )+ )? ( EXPONENT )?
)
;
protected LETTER
options { paraphrase = "an letter"; }
: 'a'..'z'
;
COMMA
options { paraphrase = ","; }
: ","
;
AND
options { paraphrase = "&&"; }
: "&&"
;
OR
options { paraphrase = "||"; }
: "||"
;
NOT
options { paraphrase = "!"; }
: '!'
;
LPAREN
options { paraphrase = "("; }
: '('
;
RPAREN
options { paraphrase = ")"; }
: ')'
;
EQ
options { paraphrase = "=="; }
: "=="
;
NEQ
options { paraphrase = "!="; }
: "!="
;
STRING
options { paraphrase = "an string"; }
: '\''
( ~( '\'' | '"' | '\n' | '\r' ) )*
( '\''
| // nothing -- write error message
)
;
REAL_or_INT
: ( ( SIGNUM )? ( DIGIT )+ POINT ) => REAL { $setType( REAL ); }
| ( ( SIGNUM )? POINT ( DIGIT )+ ) => REAL { $setType( REAL ); }
| ( ( SIGNUM )? ( DIGIT )+ ) => INT { $setType( INT ); }
;
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;
buildAST=true;
}
otype_in_op
:
OTYPE IN^ strlist
;
existence_op
:
ADDER | REPEATER
;
relation_op
:
( XSIZE | YSIZE ) ( EQ^ | NEQ^ ) ( INT | REAL )
;
primitive
:
existence_op | relation_op | otype_in_op | LPAREN^ expression
RPAREN!
;
negation_expression
:
primitive | NOT^ primitive
;
expression
:
negation_expression ( ( AND^ | OR^ ) negation_expression )*
;
run
:
expression EOF
;
strlist
:
LPAREN ( STRING | ( STRING COMMA )+ STRING ) RPAREN
;
/////////////////////////////////////////////////////////////////////
// TreeParser
/////////////////////////////////////////////////////////////////////
class FilterTreeParser extends TreeParser;
options
{
k=2;
importVocab=YMFL;
}
existence_op
:
ADDER | REPEATER
;
number
:
INT | REAL
;
strlist
:
LPAREN ( STRING | ( STRING COMMA )+ STRING ) RPAREN
;
expression
:
#(AND expression expression)
|
#(OR expression expression)
|
#(NOT expression)
|
#(LPAREN expression)
|
#(EQ ( XSIZE number | YSIZE number ) )
|
#(NEQ ( XSIZE number | YSIZE number) )
|
#(IN OTYPE strlist)
|
existence_op
;
More information about the antlr-interest
mailing list