[antlr-interest] ANTLR Grammar error - Illegal token.
Jim Idle
jimi at temporal-wave.com
Mon Aug 4 10:03:00 PDT 2008
On Mon, 2008-08-04 at 09:52 -0700, rkevinburton at charter.net wrote:
> If I left factor the grammar I essentially have
Thsi is not left factored, you have just left factored the first bit of
it.
>
> classSourceElement
> : classField
> | classMethod
> | classProperty
> ;
>
> classCommon
> : (s=STATIC)? (modifier=(PUBLIC|PRIVATE))?
> ;
>
> classField
> : c=classCommon VAR name=Identifier
> -> ^( CFIELD $c $name )
> | c=classCommon VAR name=Identifier COLON type=Identifier
> -> ^( CFIELD $c $name TYPES $type)
> ;
both of htese have a common prefix classCommon VAR Identifier, left
factor these.
>
> classMethod
> : c=classCommon name=Identifier formalParameterList functionBody
> -> ^( $c formalParameterList functionBody )
> ;
And so does this,
You want to take all the classCommon stuff and start classSourceElement
with it, then you have classField as:
VAR name=Identifier
( COLON type=Identifier ->^(CFIELD $name TYPES $type)
| ->^(CFIELD $name)
)
your classSourceElement the is:
classSourceElement
: c=classCommon
( c1=classField
| c2=classProperty
etc.
and you rewrite as ^(TYPEDECL $c $c1? $c2? etc).
You AST walker can then semantically check whether static and so on are
valid for this declaration.
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080804/75e9f82b/attachment.html
More information about the antlr-interest
mailing list