[antlr-interest] Error: TokenStreamException while reading Grammer

Johannes Luber jaluber at gmx.de
Tue Feb 3 22:50:27 PST 2009


Chal Chale apne Ghar schrieb:
> 
> 
> Hi Gavin,
> Thanks for quick Response.
> It was really helpful to me.
> After trying with the antlr v3 , I am getting different error in console.

You are using the syntax for ANTLR 2.7.7 which is mostly incompatible
with the one used by ANTLR 3. The general form of a grammar is:

/** This is a grammar doc comment */
grammar-type grammar name;
options { name1 = value; name2 = value2; ... }
import delegateName1=grammar1, ..., delegateNameN=grammarN; // can omit
delegateName
tokens { token-name1; token-name2 = value; ... }
scope global-scope-name-1 { «attribute-definitions» }
scope global-scope-name-2 { «attribute-definitions» }
...
@header {...}
@lexer::header {...}
@members {...}

«rules»

To set the superclass of the generated class, use the superClass option.

See
<http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+printable+documentation>
for further information. Although I'm really wondering how ANTLRworks
didn't complain about the fact, that you are actually using a ANTLR 2
grammar. I suggest that you either convert the grammar to the new syntax
or just use ANTLR 2.7.7.

Johannes
>  
> D:\Actuate\Samplelexer-parser\ConversionTool>java org.antlr.Tool
> D:\Actuate\VB\v
> b_org.g
> ANTLR Parser Generator  Version 3.1.1
> error(100): D:\Actuate\VB\vb_org.g:1:1: syntax error: antlr:
> D:\Actuate\VB\vb_or
> g.g:1:1: unexpected token: class
> warning(149): D:\Actuate\VB\vb_org.g:0:0: rewrite syntax or operator
> with no out
> put option; setting output=AST
> error(150):  grammar file D:\Actuate\VB\vb_org.g has no rules
> error(100): D:\Actuate\VB\vb_org.g:0:0: syntax error: assign.types:
> <AST>:0:0: u
> nexpected end of subtree
> error(100): D:\Actuate\VB\vb_org.g:0:0: syntax error: define: <AST>:0:0:
> unexpec
> ted end of subtree
> i am attching my .g file fro reference.
> Any help would be appriciated.
> regards,
> Gunjan
> On Tue, Feb 3, 2009 at 1:23 AM, Gavin Lambert <antlr at mirality.co.nz
> <mailto:antlr at mirality.co.nz>> wrote:
> 
>     At 21:45 2/02/2009, Chal Chale apne Ghar wrote:
> 
>         D:\Actuate\Samplelexer-parser\ConversionTool>java antlr.Tool
>         vb_org.txt
>         ANTLR Parser Generator   Version 2.7.5 (20050128)   1989-2005
>         jGuru.com
>         error: Token stream error reading grammar(s):
>         vb_org.txt:45:7: expecting ''', found 'p'
>         TokenStreamException: expecting ''', found 'p'
> 
>         as seen, i am getting TokenStream Exception. But when i am using
>         AntlrWorks to check the Grammer syntax, it is showing correct to me.
> 
> 
>     You're running ANTLR v2 on the command line, but ANTLRWorks is for
>     ANTLR v3.  To run ANTLR v3, you need to use "org.antlr.Tool", not
>     "antlr.Tool".
> 
>     Also, by convention grammar files have a .g extension.  This doesn't
>     really matter (ANTLR will still happily compile the file regardless
>     of extension), but it's a good idea to follow the convention, since
>     that's what tools are expecting.
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list