[antlr-interest] Antlr missing getTree() method? C#

Setia, Namit namit.setia at lehman.com
Wed Jul 23 13:28:50 PDT 2008


I'm sure there is something I'm doing wrong, but I can't figure it out.
I created a grammar (see below) and exported it to C#, then tried the
following code as a test:

Antlr.Runtime.ICharStream str = new
Antlr.Runtime.ANTLRStringStream("a=5;");
qss_grammarLexer qlex = new qss_grammarLexer(str);
Antlr.Runtime.CommonTokenStream tokens = new
Antlr.Runtime.CommonTokenStream(qlex);
qss_grammarParser qpar = new qss_grammarParser(tokens);

For some reason, I don't see any methods to extract the AST tree from
the parser (i.e., from the "qpar" variable).  I've seen in other posts
people calling qpar.getTree() or qpar.program().  Am I missing something
critical from my grammar?  Is it missing badly?  Or, am I supposed to
get the tree some other way?  I am using the daily build of antlr from
6/26/08 and antlworks 1.2b5.  I tried reverting to the older version,
and I get the same result.

Thanks,

namit

------------------------------------------------------------------------
--------------------------------------
grammar qss_grammar;

options
{
	language=CSharp2;
	output=AST;
}

qexprlist
  : ( qassignment_statement )* EOF!
  ;

qassignment_statement
  : qassignment SEMI { Console.Write("hello"); }
  ;

qassignment
  : (qname ASSIGN )? qexpr
  ;

qprimary_expr
  : qint
  | qvname
  | (LPAREN qexpr RPAREN ) 
  | qfunction
  | qarray
  | qstring
  ;

qsign_expr
  : qprimary_expr
  ;

qmul_expr
  : qsign_expr (( MUL | DIV | MOD ) qsign_expr)*
  ;
  
qexpr
  	:	 qmul_expr (( PLUS | MINUS ) qmul_expr)*
  ;



PLUS	:	'+';
MINUS	:	'-';
DIV	:	'/';
MUL	:	'*';
MOD	:	'%';
POW	:	'^';
LETTER	:	'a'..'z'|'A'..'Z';
DIGIT	:	'0'..'9';
PER	:	'.';
SEMI	:	';';
ASSIGN	:	'=';
EQ	:	'=''=';
NQ	:	'!''=';
LEQ	:	'<''=';
GEQ	:	'>''=';
LPAREN	:	'(';
RPAREN	:	')';

qint	:	(DIGIT)*;
qname	:	LETTER(LETTER|DIGIT)*;
qstr	:	(LETTER|DIGIT)*;
qstring	:	'"' (LETTER|DIGIT)* '"';
qinputval:	(LETTER|DIGIT)*;
qvname	:	(LETTER(LETTER|DIGIT)*)(':'qinputval('.'qinputval)*)?;
qarray	:	'{' (qstring|qvname)(','(qstring|qvname))* '}';
qfunction:	(LETTER(LETTER|DIGIT)*)'('
qprimary_expr(','qprimary_expr)* ')';


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.


More information about the antlr-interest mailing list