<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.18.3">
</HEAD>
<BODY>
On Mon, 2008-08-04 at 09:52 -0700, rkevinburton@charter.net wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
If I left factor the grammar I essentially have
</PRE>
</BLOCKQUOTE>
<BR>
Thsi is not left factored, you have just left factored the first bit of it.
<BLOCKQUOTE TYPE=CITE>
<PRE>
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)
       
</PRE>
</BLOCKQUOTE>
<BR>
both of htese have a common prefix classCommon VAR Identifier, left factor these.
<BLOCKQUOTE TYPE=CITE>
<PRE>
classMethod
        : c=classCommon name=Identifier formalParameterList functionBody
        -> ^( $c formalParameterList functionBody )
       
</PRE>
</BLOCKQUOTE>
<BR>
And so does this, <BR>
<BR>
You want to take all the classCommon stuff and start classSourceElement with it, then you have classField as:<BR>
<BR>
VAR name=Identifier <BR>
( COLON type=Identifier ->^(CFIELD $name TYPES $type)<BR>
| ->^(CFIELD $name)<BR>
)<BR>
<BR>
your classSourceElement the is:<BR>
<BR>
classSourceElement<BR>
: c=classCommon<BR>
( c1=classField<BR>
| c2=classProperty<BR>
etc.<BR>
<BR>
and you rewrite as ^(TYPEDECL $c $c1? $c2? etc).<BR>
<BR>
You AST walker can then semantically check whether static and so on are valid for this declaration.<BR>
Jim
</BODY>
</HTML>