[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Grammatica-users] Grammar for "Nesting"
From: |
Patrick M Gremo |
Subject: |
Re: [Grammatica-users] Grammar for "Nesting" |
Date: |
Tue, 26 Jul 2005 08:49:34 -0500 |
Thanks for all of your assistance. You have been very helpfull.
I think I'm supper close. Here is the grammar I have now.
===================
%header%
GRAMMARTYPE = "LL"
%tokens%
USER_UNARY = <<[a-zA-Z][a-zA-Z0-9_]*>>
STRING = <<("[^"]*")>>
WHITESPACE = <<[ \t\n\r]+>> %ignore%
%productions%
_expression_ = Message ;
Message = Factor Term? ;
Term = MethodCall Term? ;
Factor = MethodCall
| STRING ;
MethodCall = USER_UNARY ;
================================
When I try with this data:
object call1 call2
I get this (from TreePrinter):
_expression_(2001)
Message(2002)
Factor(2004)
MethodCall(2005)
USER_UNARY(1003): "object", line: 1, col: 1
Term(2003)
MethodCall(2005)
USER_UNARY(1003): "call1", line: 1, col: 8
Term(2003)
MethodCall(2005)
USER_UNARY(1003): "call2", line: 1, col: 14
This is very close, except I want the tree "flipped" so that "object" is at the bottom.
I did some tests and this grammar lets only the Factor be a String or
MethodCall. This is good as I don't want Strings to be missinterpretted
as a method call.
Thanks
address@hidden wrote: -----
To: address@hidden
From: Per Cederberg <address@hidden>
Sent by: address@hidden
Date: 07/25/2005 03:48PM
Subject: Re: [Grammatica-users] Grammar for "Nesting"
Well, Grammatica uses LL grammars so they are recursive on
the right-hand side. Your production is identical to this
one:
Message = MethodCall
| Object MethodCall
| Message MethodCall ;
This describes a sequence of MethodCall productions with a
possible end of an Object and then a MethodCall. To write
this in a right-recursive way, you'd simply write this
instead:
Message = MethodCall
| Object MethodCall
| MethodCall Message ;
Which in turn can be simplified to:
Message = MethodCall [Message]
| Object MethodCall ;
/Per
On mon, 2005-07-25 at 12:45 -0500, Patrick M Gremo wrote:
> This is close.
>
>
>
> But I think what I need is something like:
>
> Message = [Object | Message] MethodCall
>
> But this gives me an infinite loop.
>
> I think I can describe it as:
>
> A Message can have an Object OR another Message coupled with a MethodCall.
>
>
>
>
>
>
>
>
>
>
> I think a production for Message could look like this:
>
> Message = MethodCall Message?
> | Object Message? ;
>
> This will allow an infinite list of method calls and
> objects mixed together. If the Object production can
> only be placed at the end, you'd write the production
> like this:
>
> Message = MessageCall Message?
> | Object ;
>
> Cheers,
>
> /Per
>
> On sun, 2005-07-24 at 19:40 -0500, Patrick M Gremo wrote:
> >
> > I'm trying to create a kind of "reverse" call stack type of thing. It
> > sounds easy but for some reason I just can't figure it out.
> >
> > I have this:
> >
> > (object | methodCall) methodCall methodCall methodCall ...
> >
> >
> > I want a tree like:
> >
> > message
> > |-methodCall
> > |-message
> > |-methodCall
> > |-message
> > |-methodCall
> > |-message
> > |-object | methodCall
> >
> >
> >
> >
> > _______________________________________________
> > Grammatica-users mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/grammatica-users
> >
> _______________________________________________
> Grammatica-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
_______________________________________________
Grammatica-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/grammatica-users