[antlr-interest] NPE from org.antlr.runtime.Parser.getMissingSymbol(..) when trying to parse

Terence Parr parrt at cs.usfca.edu
Wed Jul 9 15:59:00 PDT 2008


i think i fixed that just recently...it's when it finds eof or  
something upon mismatch.
Ter
On Jul 9, 2008, at 3:54 PM, Sumanto Biswas wrote:

> Hi,
>
> I used the SimpleCalc.g grammar from
> http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3
> and used antlr3.1b1 with Java and was trying it with various inputs. I
> gave input "asd", and got a NPE. The stack trace along with other
> output is pasted below.
>
> Just for reference, I have also pasted grammar below.
>
> Should the parser ever give NPE?
>
> Regards,
> Sumanto
>
> ------------------------------------------------------------
> line 1:0 no viable alternative at character 'a'
> line 1:1 no viable alternative at character 's'
> line 1:2 no viable alternative at character 'd'
> Exception in thread "main" java.lang.NullPointerException
> 	at org.antlr.runtime.Parser.getMissingSymbol(Parser.java:69)
> 	at  
> org 
> .antlr 
> .runtime 
> .BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:624)
> 	at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:117)
> 	at SimpleCalcParser.factor(SimpleCalcParser.java:189)
> 	at SimpleCalcParser.term(SimpleCalcParser.java:125)
> 	at SimpleCalcParser.expr(SimpleCalcParser.java:60)
> 	at Tester.main(Tester.java:24)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at  
> sun 
> .reflect 
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at  
> sun 
> .reflect 
> .DelegatingMethodAccessorImpl 
> .invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java: 
> 90)
> ------------------------------------------------------------
>
>
> Grammar pasted below:
> ------------------------------------------------------------
> grammar SimpleCalc;
>
> tokens {
> 	PLUS 	= '+' ;
> 	MINUS	= '-' ;
> 	MULT	= '*' ;
> 	DIV	= '/' ;
> }
>
>
>
> /*------------------------------------------------------------------
> * PARSER RULES
> *------------------------------------------------------------------*/
>
> expr	: term ( ( PLUS | MINUS )  term )* ;
>
> term	: factor ( ( MULT | DIV ) factor )* ;
>
> factor	: NUMBER ;
>
>
> /*------------------------------------------------------------------
> * LEXER RULES
> *------------------------------------------------------------------*/
>
> NUMBER	: (DIGIT)+ ;
>
> WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ 	{ $channel =  
> HIDDEN; } ;
>
> fragment DIGIT	: '0'..'9' ;
> ------------------------------------------------------------



More information about the antlr-interest mailing list