|
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'): typedef struct Composed_Float_reel_return_struct { /** Generic return elements for ANTLR3 rules that are not in tree parsers or returning trees */ pANTLR3_COMMON_TOKEN start; pANTLR3_COMMON_TOKEN stop; tree; } Composed_Float_reel_return; - 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 1: ok int a ; float x ; the result is: main: main: (DECL (int a) (float x)) main. - example 2: ok int a b; float x; the result is: main: err1.ok(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: (DECL (int a) (float x)) main. - example 3: ok int a ; float x y; ... - 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 use the lexer: lexer grammar Lex; options { language=C; } tokens { DECL; } INT: 'int'; FLOAT: 'float'; SEMICOL: ';'; Id: 'a'..'z'+ ; Blancs: ( ' ' | '\t' | '\n' )+ { $channel=HIDDEN; } ; With more complicated grammars, I got no error reporting at all. |
ComposedGrammars_1.tar.gz
Description: GNU Zip compressed data
Have a nice day, Jean-Claude Durand LIG, équipe GETALP 385, rue de la Bibliothèque BP 53 38041 Grenoble cedex 9 France tél: +33 (0)4 76 51 43 81 fax: +33 (0)4 76 51 44 05 |
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
