[antlr-interest] Recursive rule invocation

Jeroen van Schagen jeroen.v.schagen at gmail.com
Sat Aug 29 06:37:36 PDT 2009


Just noticed I forgot to include the grammar file, here it is.

On Sat, Aug 29, 2009 at 2:56 PM, <jeroen.v.schagen at gmail.com> wrote:

> Thanks for the response. I'm aware of the left factoring approach, however
> then the alternative:
>
> markup+ ';'
>
> will have a higher priority then:
>
> markup+ expression ';'
>
> which is invalid for my language. Is there any way to specify priorities
> other then the ordering of alternatives?
>
> On Aug 29, 2009 2:20pm, Martijn Reuvers <martijn.reuvers at gmail.com> wrote:
> > Hi Jeroen,
> >
> >
> >
> > I would rewrite the markupStatement like this:
> >
> >
> >
> > markupStatement :
> >
> >  markup+ (expression | regularStatement | embedding)? ';'
> >
> >
> >
> > That way its valid again. The markup+ in each of your choices is the
> >
> > problem now I guess.
> >
> >
> >
> > Martijn
> >
> >
> >
> > On Sat, Aug 29, 2009 at 12:57 PM, Jeroen van
> >
> > Schagenjeroen.v.schagen at gmail.com> wrote:
> >
> > > Can somebody please tell me what is recursive about the markupStatement
> >
> > > production in the following grammar? The problem disappears when I
> remove
> >
> > > the expression NT symbol from argument, but this is required for my
> >
> > > language. Is it solvable without having to enable backtracking?
> >
> > > markupStatement: markup+ expression ';'
> >
> > > | markup+ regularStatement ';'
> >
> > > | markup+ embedding ';'
> >
> > > | markup+ ';'
> >
> > > ;
> >
> > > where..
> >
> > > markup: IDCON attributes arguments?
> >
> > > -> ^( MARKUP IDCON attributes arguments? ) ;
> >
> > > attributes: attribute*
> >
> > > -> ^( ATTRIBUTES attribute* );
> >
> > > attribute: '#' IDCON // ID attribute
> >
> > > | '.' IDCON // Class attribute
> >
> > > | '$' IDCON // Name attribute
> >
> > > | ':' IDCON // Type attribute
> >
> > > | '@' NATCON // Width attribute
> >
> > > | '@' NATCON '%' NATCON // Width-height attribute
> >
> > > ;
> >
> > > arguments: '(' argument? ( ',' argument )* ')' ;
> >
> > > argument: expression
> >
> > > | IDCON '=' expression ;
> >
> > > expression: ( IDCON | NATCON | TEXT | SYMBOLCON
> >
> > > | '[' expression? ( ',' expression )* ']' // List
> >
> > > | '{' keyValuePair? ( ',' keyValuePair )* '}' // Record
> >
> > > ) ( '+' expression | '.' IDCON )* ;
> >
> > > keyValuePair: IDCON ':' expression ;
> >
> > > regularStatement:    'echo' expression ';' ;
> >
> > > embedding: PRETEXT embed textTail ;
> >
> > > embed: markup* expression ;
> >
> > > textTail: POSTTEXT | MIDTEXT embed textTail ;
> >
> > >
> >
> > > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >
> > > Unsubscribe:
> >
> > > http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
> > >
> >
> > >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090829/6542d1f6/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WaebricTest.g
Type: application/octet-stream
Size: 5805 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090829/6542d1f6/attachment.obj 


More information about the antlr-interest mailing list