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.
Vitaly - 26 Oct 2006 15:57 GMT
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.
> Hi all,
> I am using javacc and jjtree to generate an AST for a C++ input file. I
[quoted text clipped - 67 lines]
> primary_expression
> C++ Parser Version 0.1: Program parsed successfully.