[antlr-interest] antlr-interest Digest, Vol 44, Issue 93

Anders Karlsson anders at globe-trotter.us
Thu Jul 31 19:45:24 PDT 2008


Hi

I was trying to create a tree parser but when I write

tree grammar xxx;

at the top of the file (or lex grammar xxx for that matter)

I get a null pointer exception as follows:

Cannot generate the grammar because:
error(10): internal error: C:....path to my xxx.g file : java.lang.NullPointerException
org.antlr.tool.GrammarSanity.traceStatesLookingForLeftRecursion(GrammarSanity.java:105)
...
java.lang.Thread.run(Unknown Source)

Any ideas what I am doing wrong?

The grammar follows (from the ANTLR3 ref book,slightly modified):

tree grammar evaluate;       // this causes the error, if I remove tree there is no exception

options {
	tokenVocab=expeval; // read tokens from this file expeval.tokens
	ASTLabelType=CommonTree;
	language=C;
}

@header {
  #include <stdio.h> // here some using/includes could be specified.
}

@members {
  // here some instance variables could be defined.
}

prog 
	:	statement+;

statement 
	:	 expr { char m[32]; puts( itoa( $expr.value, m, 10 ) ); }
	;

expr returns [int value] 
	:	^('+' a=expr b=expr) { $value=a+b; }
	| ^('-' a=expr b=expr) { $value=a-b; }
	| ^('*' a=expr b=expr) { $value=a*b; }	
	| ^('/' a=expr b=expr) { $value=a/b; }
	| INT { $value=atoi((const char*)($INT.text->chars)); }
	;
	
INT
	:	 '0'..'9'+
	;	



More information about the antlr-interest mailing list