[antlr-interest] Questions about ANTLR tree parsers
Suman Karumuri
mansuk at gmail.com
Sat Oct 29 02:16:11 PDT 2005
Hi ,
1) Can anyone explain me what this action does. I have taken this
example from the calc.g file in antlr examples.
expr : expr1 { ## = #(#[EXPR,"expr"],##); } ;
I have gone through the docs but i am unable to understand what ## in
an action is translated to .As i understand it is a shortcut for #expr
but it doesn't seem to be correct and i get many errors.
2) There are no docs on how to write the grammar for a tree parser.
>From what i have read and understood, this is the conclusion i have
reached:
" A parser grammar is shows associativity and precedence where as the
tree parser grammar is the grammar
- Without associativity
- Without precedence
- Without delimiting characters.
"
Is that correct?
3) I have a problem grouping multiple trees as a single node from a
rule.For example in the below grammar:
program : stmt;
stmt : expr EOL
|! v:VAR EQUALS s:expr EOL
{ #v.setType(VAR_NAME); #stmt = #(#EQUALS, #s, #v); }
| PRINT^ expr EOL!
| WHILE^ cond sl:stmt_lst { #sl.setType(STMT_LIST);}
stmt_lst: BEGIN! (EOL!)* (stmt)* END! (EOL!)*
expr : // This is an expression
I want the statement list to be a subtree of while root. But the above
set type does not seem to work. Am i missing something important?
4) How is this rule in parser translated to tree parser?
program = (stmt)*
But in the tree parser this doesn't seem to work:
program = #(stmt)*
What is the right way to do it?
Thanks for your time.
-Suman
More information about the antlr-interest
mailing list