dcsimg
Puzzled about the outcome of Antlrworks 1.3
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Harry_Bakker
Posted On:   Wednesday, October 28, 2009 10:02 AM

I've entered the following grammar in Antlrworks 1.3: grammar test; fragment LOWER : 'a'..'z' ; fragment UPPER : 'A'..'Z' ; fragment LETTER : LOWER | UPPER ; fragment SIGN : '+' | '-' ; fragment DIGIT : '0'..'9' ; fragment EXPONENT : ('e'|'E') SIGN? '0'..'9'+ ; fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; fragment ESC_SEQ : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\') | UNICODE_ESC ; fragment UNICODE_ESC : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ; fragment APOSTROPHE : '\'' ; fragment QUOTE : '"' ; ID : LETTER (LETTER | DIGIT | '_')* ; WS : ( ' ' | ' ' | ' ' | ' ' ) {$channel=H   More>>

I've entered the following grammar in Antlrworks 1.3:



			
grammar test;

fragment LOWER : 'a'..'z' ;
fragment UPPER : 'A'..'Z' ;
fragment LETTER : LOWER | UPPER ;
fragment SIGN : '+' | '-' ;
fragment DIGIT : '0'..'9' ;
fragment EXPONENT : ('e'|'E') SIGN? '0'..'9'+ ;
fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment ESC_SEQ : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\') | UNICODE_ESC ;
fragment UNICODE_ESC : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ;
fragment APOSTROPHE : '\'' ;
fragment QUOTE : '"' ;

ID : LETTER (LETTER | DIGIT | '_')* ;
WS : ( ' ' | ' ' | '
' | '
' ) {$channel=HIDDEN;} ;
COMMA : ',' ;
LPAREN : '(' ;
RPAREN : ')' ;
STRING : QUOTE ( ESC_SEQ | ~('\\' | QUOTE) )* QUOTE;
INT : DIGIT+ ;
FLOAT : DIGIT+ '.' DIGIT* EXPONENT?
| '.' DIGIT+ EXPONENT?
| DIGIT+ EXPONENT
;

line : object* ;

object : expr
| qexpr
;

qexpr : APOSTROPHE expr APOSTROPHE ;

expr : mexpr ( ('+' | '-') mexpr )* ;

mexpr : atom ( ('*' | '/') atom )* ;

atom : INT
| FLOAT
| ID
| STRING
| LPAREN expr RPAREN
;


Then i want to use the interpreter. I select 'line' as the starting rule and the next line as input:


			
"var" + 10


In the output i expect to see the values

			"var"
			
+
10
Instead, i see the values
			"var
			
" +
10
Surely this must be an error, given the above specified grammar? Or am i doing something wrong?



-Harry

   <<Less
About | Sitemap | Contact