Re: Generating AST using javacc and jjtree



Get ANTLR at
http://www.antlr.org/
It supports not only Java but C++ and C#. Written in Java v.1.1 and can be
compiled to EXE with MS Visual Studio as J#.
Generates Lexer, Parser (which can build AST) and AST Grammar Walker (with
actions). It is free, has very good documentation and support. At ANTLR site
you will find a number of grammars ready for use.



<nakuldurve@xxxxxxxxx> wrote in message
news:1161530170.771861.232460@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
I am using javacc and jjtree to generate an AST for a C++ input file. I
have got the file parsing fine, and the generated tree is printed
below. Is there any way to extract the information about the nodes from
the tree (e.g. instead of just "logical_and_expression", see the actual
information / text about the node) ?

The AST shown below is for the program shown here (hello world). That's
why I'm not sure what or how its managed to generate the AST below with
all inclusive_or_expressions etc etc.

Thanks a lot!

Code:
int main()
{
print("Hello world");
}

Parser output:
C++ Parser Version 0.1: Reading from file Test.cpp . . .
translation_unit
external_declaration
function_definition
declaration_specifiers
builtin_type_specifier
function_declarator
function_direct_declarator
qualified_id
func_decl_def
compound_statement
statement_list
statement
expression
assignment_expression
conditional_expression
logical_or_expression
logical_and_expression
inclusive_or_expression
exclusive_or_expression
and_expression
equality_expression
relational_expression
shift_expression
additive_expression
multiplicative_expression
pm_expression
cast_expression
unary_expression
postfix_expression
primary_expression
id_expression
expression_list
assignment_expression
conditional_expression
logical_or_expression
logical_and_expression
inclusive_or_expression
exclusive_or_expression
and_expression
equality_expression
relational_expression
shift_expression
additive_expression
multiplicative_expression
pm_expression
cast_expression
unary_expression
postfix_expression
primary_expression
C++ Parser Version 0.1: Program parsed successfully.



.



Relevant Pages

  • Re: Get line numbers with Antlr parser
    ... I need to extract the line numbers from the parser. ... You will have to build an AST class to be used by antlr for that, ... in one part of the parser it works, but in the tree parser ... That way, antlr will build the tree using MyAST nodes, which store the ...
    (comp.compilers)
  • Re: Highspeed parsen - aber wie?
    ... AST) erzeugen sollte. ... Vergleiche das am besten mit SAX und DOM. ... der Parser Elemente und Attribute findet, ...
    (de.comp.lang.java)
  • Re: [ANTLR] Zeile und Spalte bei Fehler in Treeparser ermitteln
    ... > Peter Rill schrieb: ... >> Leider ist ja die Javadoc zu ANTLR auch sehr lückenhaft und viele Methoden ... > public void initialize(AST ast) { ... Man muss void initialize(Token token) ...
    (de.comp.lang.java)
  • Re: Formelparser
    ... >> Abstract Syntax Tree (AST) und Expression Parsing. ... Der Begriff Token ist leider auch im Compilerbau relativ überladen. ... >> wird nahezu immer Parser gennant. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: [SUMMARY] Parsing JSON (#155)
    ... a parser generator to construct their parser. ... translates your grammar into parsing code that will match the described ... worth a look if you want to do some grammar based parsing. ... The approach I like to take is have the caller pass the AST to be modified. ...
    (comp.lang.ruby)

Quantcast