Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / October 2006

Tip: Looking for answers? Try searching our database.

Generating AST using javacc and jjtree

Thread view: 
nakuldurve@gmail.com - 22 Oct 2006 16:16 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.