<!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
        -&gt; ^( CFIELD $c $name )
        | c=classCommon VAR name=Identifier COLON type=Identifier
        -&gt; ^( 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
        -&gt; ^( $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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp; COLON type=Identifier -&gt;^(CFIELD $name TYPES $type)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | -&gt;^(CFIELD $name)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<BR>
<BR>
your classSourceElement the is:<BR>
<BR>
classSourceElement<BR>
&nbsp;&nbsp; : c=classCommon<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( c1=classField<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | c2=classProperty<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>