[antlr-interest] Composed grammars: small bug with generated files and pbs with errors reporting

Jim Idle jimi at temporal-wave.com
Mon Sep 1 10:15:46 PDT 2008


On Mon, 2008-09-01 at 17:55 +0200, Jean-Claude Durand wrote:

> I use antlr v3.1 with the C language target to compose grammars. I
> send you an archive to show
> 
> you the problem:
> - first, in the different generated .h files, the variable 'tree' has
> no type in the typedef definition of the 
> "return" when building ASTs (you should have the type
> 'pANTLR3_BASE_TREE'):

As has been postedquite a number of times now ;-), you need to have:

options
{
ASTLabelType=pANTLR3_BASE_TREE;
}

In your grammar.


> 
> - second, error reporting does not work very well even with very
> simple grammars as in my example
> below. Sometimes it is ok, sometimes not (the same message for 2
> different errors or no message at all):
> 
> 
> I compose the 2 grammars:
> 
> 
> parser grammar Int;
> options
> {
> language=C;
> output=AST;
> }
> ent: 
> INT Id SEMICOL
> -> ^(INT Id) 
> ;
> 
> 
> and:
> 
> 
> parser grammar Float;
> options
> {
> language=C; 
> output=AST;
> }
> reel : 
> FLOAT Id SEMICOL
> -> ^(FLOAT Id) 
> ;
> 
> 
> in the composed grammar:
> 
> 
> parser grammar Composed;
> options
> {
> language=C;
> tokenVocab=Lex;
> output=AST;
> }
> import Int, Float;
> decls
> :
> e=ent
> r=reel
> -> ^(DECL $e $r)
> ;
> 


> 
> 
> - example 4: NOT ok, I get the same message twice for the first error
> but nothing on the second.
> 
> 
> int a b;
> float x y;
> 
> 
> the result is:
> 
> 
>  main:
> err.notOk(1)  : error 9 : Extraneous token, at offset 5
>     near [Index: 2 (Start: 5243798-Stop: 5243798) ='b', type<8> Line:
> 1 LinePos:5]
>      : Extraneous input - expected SEMICOL ...
> err.notOk(1)  : error 9 : Extraneous token, at offset 5
>     near [Index: 2 (Start: 5243798-Stop: 5243798) ='b', type<8> Line:
> 1 LinePos:5]
>      : Extraneous input - expected SEMICOL ...
>  main: ast: 249856
>  main: (DECL (int a) (float x))
>  main.


I'll look into it, maybe it is something to do with not resetting the
error flag perhaps.


JIm
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080901/c4c4ef92/attachment.html 


More information about the antlr-interest mailing list