[antlr-interest] Problem with C target output on example C grammar - temporary (?) solution found

Kamil Burzynski nopik at data.pl
Tue Apr 1 03:48:23 PDT 2008


Hello again,

 For the time being, I've simplified external_declaration just to:
external_declaration : declaration ;

(which effectively allows to remove it completely, of course) and moved
( declaration_specifiers? declarator declaration* '{' )=> 
function_definition
from external_declaration to declaration. I have moved options { k = 1 } to 
declaration as well,
though I am not yet experienced enough with antlr to be sure if this is 
correct action.

Now, it works on sample file, at least ;) On other trivial files it works 
as well. However, if I run it on main.c file (i.e. on itself), it crashes 
around #include statement ;p

"Kamil Burzynski" <nopik at data.pl> napisał(a):
> Hello,
>
> I am new to this list as well as to antlr, so please be gentle ;) My goal
>
> is to have flexible C/C++ parser, after trying yacc/lex for a short while 

> I
> decided to go to antlr. Since I want my project in C++, it seems, that
> antlr 3.1b is better than official 3.0.1. Anyway, I have installed
> antlr-2008-03-13.12.tar.gz with libantlr3c-3.1b2.tar.gz and tried to
> compile some examples from examples-v3.1b1.tar.gz. The simple ones do
> work,
> indeed. However, when I try to run C grammar, it fails with segfault.
> Here
> is some info (I have cut off a bunch of 'Created a symbolpp class'
> messages):
>
> 988 05:34:46 andLinux ~/Warsztat/antlr/examples-v3/C/C$ java
> org.antlr.Tool
> C.g3pl
> ANTLR Parser Generator Version 3.1b1 (??) 1989-2007
> Generating CParser.c
> Generating CParser.h
> Generating CLexer.c
> Generating CLexer.h
> 989 05:35:24 andLinux ~/Warsztat/antlr/examples-v3/C/C$ g++ *.c -o main
> -I.
> -L /usr/local/lib/ -lantlr3c -ggdb
> 990 05:35:32 andLinux ~/Warsztat/antlr/examples-v3/C/C$ gdb main
> GNU gdb 6.6-debian
> Copyright (C) 2006 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you
> are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for
> details.
> This GDB was configured as "i486-linux-gnu"...
> Using host libthread_db library "/lib/libthread_db.so.1".
> (gdb) run
> Starting program: /home/nopik/Warsztat/antlr/examples-v3/C/C/main
> Including file 'jimtest.h'
> Created a symbolpp class
> define type size_t
> [cut many similar messages]
> Created a symbolpp class
> define type fd_mask
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x08054f75 in direct_declarator (ctx=0x80b0868) at CParser.c:16284
> 16284 if (
> (SCOPE_TOP(declaration))->isTypedef)
> Current language: auto; currently c++
> (gdb) where
> #0 0x08054f75 in direct_declarator (ctx=0x80b0868) at CParser.c:16284
> #1 0x08055897 in declarator (ctx=0x80b0868) at CParser.c:16156
> #2 0x0806efa4 in function_definition (ctx=0x80b0868) at CParser.c:13775
> #3 0x0806f5c3 in external_declaration (ctx=0x80b0868) at CParser.c:13652
> #4 0x0806f89e in translation_unit (ctx=0x80b0868) at CParser.c:13543
> #5 0x0806fbef in main (argc=1, argv=0xbf9b45a4) at main.c:188
> (gdb) print ctx
> $2 = (pCParser) 0x80b0868
> (gdb) print ctx->pCParser_declarationTop
> $3 = (pCParser_declaration_SCOPE) 0x0
> (gdb) quit
>
> Indeed, when in direct_declarator I change if( $declaration::isTypedef )
> to
> e.g. if( false ), program do not crash, though report a bunch of errors.
>
> Any ideas? Maybe I am using mismatched versions (e.g. old examples) or
> what? Original author must have ran it at least once, so probably I have
> messed something ;)
>
> PS. It seems, that antlr banner says wrong year - it should be 2008
> instead
> of 2007, right? :)
>
> --
> Best regards from
> Kamil Burzynski




-- 
Best regards from
Kamil Burzynski



More information about the antlr-interest mailing list