Loading ...
Sorry, an error occurred while loading the content.
 

Newbie ANTLR question

Expand Messages
  • inyoursadmachine
    Hi, I m using ANTLR to write an interpreter for a C-like language. I finally got Parser.startRule() to run and Parser.getAST() returns the data below for the
    Message 1 of 2 , Dec 14, 2004
      Hi,
      I'm using ANTLR to write an interpreter for a C-like language. I
      finally got Parser.startRule() to run and Parser.getAST() returns
      the data below for the following source code:

      source:

      $name1 = "batman"
      $name2 = "robin"
      if($name1 == "catwoman")
      {
      $name3 = "the joker"
      }


      ast:
      ( = $name1 "batman" ) ( = $name2 "robin" ) ( if ( ==
      $name1 "catwoman" ) ( COMPOUND_STATEMENT { ( = $name3 "the
      joker" ) } ) )

      My question is how do I process a statement at a time from the AST?
      Or is this even the correct approach? Can I do this from my tree
      parser or do I need custom code for this?

      Thanks in advance,
      Matt
    • Terence Parr
      ... Hi Matt, You should do it with actions in your tree parser :) Ter -- CS Professor & Grad Director, University of San Francisco Creator, ANTLR Parser
      Message 2 of 2 , Dec 14, 2004
        On Dec 14, 2004, at 12:05 PM, inyoursadmachine wrote:
        > ast:
        > ( = $name1 "batman" ) ( = $name2 "robin" ) ( if ( ==
        > $name1 "catwoman" ) ( COMPOUND_STATEMENT { ( = $name3 "the
        > joker" ) } ) )
        >
        > My question is how do I process a statement at a time from the AST?
        > Or is this even the correct approach? Can I do this from my tree
        > parser or do I need custom code for this?

        Hi Matt,

        You should do it with actions in your tree parser :)

        Ter

        --
        CS Professor & Grad Director, University of San Francisco
        Creator, ANTLR Parser Generator, http://www.antlr.org
        Cofounder, http://www.jguru.com
        Cofounder, http://www.knowspam.net enjoy email again!
      Your message has been successfully submitted and would be delivered to recipients shortly.