[antlr-interest] Specifying optional elements in a tree grammar.

Paul McKee paul.mckee at mckeetech.com
Wed Mar 25 10:08:04 PDT 2009


Hi:

How do I go about specifying optional elements in a tree grammar?
For example, in my AST generator, I have:

querySpecification :
 selectClause 
 ( intoClause ) ?
 ( fromClause  )?
 ( (whereClause) =>whereClause )?
 ( (groupByClause) => groupByClause 
  ( havingClause  )?
 )? ->^(SELECTCLAUSE selectClause ^(INTOCLAUSE intoClause)? ^(FROMCLAUSE fromClause)? ^(WHERECLAUSE whereClause)?);

Which generates fine, but in my tree walker, I have:

querySpecification :
 ^(SELECTCLAUSE selectClause ^(INTOCLAUSE intoClause)? ^(FROMCLAUSE fromClause)? ^(WHERECLAUSE whereClause)?)
 ;

Which causes the following:
[16:57:30] error(100): TsqlWalker.g:284:54: syntax error: antlr: TsqlWalker.g:284:54: expecting RPAREN, found '?'
[16:57:30] error(100): TsqlWalker.g:284:80: syntax error: antlr: TsqlWalker.g:284:80: unexpected token: ?
[16:57:30] error(100): TsqlWalker.g:284:107: syntax error: antlr: TsqlWalker.g:284:107: expecting SEMI, found ')'

I'm still pretty new to this, so any help is most welcome.

Best Regards

Paul McKee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090325/0a5ac5ce/attachment.html 


More information about the antlr-interest mailing list