[antlr-interest] How to build an AST with 'ANSI C grammar for ANTLR v3'?

Hwan Jo nimbusob at gmail.com
Mon Nov 3 18:08:05 PST 2008


    I am afraid that this question seems stupid; however anyone
concerned, please give me a solution for this. Spent 3 weeks for this
problem by myself and found no exit yet.

    I have downloaded a grammar file from grammars section in ANTLRv3
official homepage. Unfortunately, there are some problems. At first,
the parser reports 'no viable alternative at input <EOF>' error in
many decent C source files(tested 30 sources) and seems not parse
source files any further.

    I have found some solutions in mailing list; however it is a
problem too. Should I modify all grammar definition with EOF! ending
condition? Author of this grammar file commented out that he had
tested a source file with 3500 lines, but the grammar file does not
works for my source files which are compiled normally(without any
WARNINGS in Microsoft VC and GCC).

    The another problem is 'how can I build an AST tree for any ANSI C
source files with this grammar file?'. Googled about it already, still
have no clues. There are nice examples in ANTLR wiki site and tried
some, (like Heterogeneous tree construction example in
http://www.antlr.org/wiki/display/ANTLR3/Tree+construction#Treeconstruction-heterogeneous)
but it did not helped me much. What should I do for my goal? Are there
any useful examples -even failure attempts- for this? What thread or
article should I read for? (I already put output=AST; option in
options section in the grammar file)

    My testing environment is

    Microsoft windows XP
    ANTLR Version 3.1.1(Latest)
    'ANSI C grammar for ANTLR v3'
    Java SE SDK 1.6.1
    Eclipse europa
    and target language is Java.



    Thank you for reading my thread.
    Regards,

    Francesco Jo


More information about the antlr-interest mailing list