[antlr-interest] Problem with semanic action

Wraight, Oliver oliver.wraight at brooks.com
Thu Sep 29 12:07:26 PDT 2005


I'm not sure if I fully understand your problem, but at first glance I'd
guess the solution would be not to use "(PAIR basicMessage)*" in
structuredMessage, but "(PAIR structuredMessage)?" instead.

ie:
structuredMessage returns[Message *rmsg]
{
    Message *bm1 = NULL;
    Message *sm2 = NULL;
}
    : bm1=basicMessage (PAIR sm2=structuredMessage)?
        {
            rmsg = new Message;
            rmsg->op1 = bm1;
            rmsg->op2 = sm2;
        }
    ;

Hope this helps,

Oliver

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Nicola Cuomo
Sent: 27 September 2005 04:30
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problem with semanic action

Hi again i've another problem :)

I've the following grammar piece (semantic action removed)

---
structuredMessage returns[Message *rmsg]
        : bm1=basicMessage (PAIR bm2=basicMessage )*
        ;

basicMessage returns[Message *rmsg]
        : VAR_IDENT (PRIME)?
        | CONST_IDENT
        | VAR_IDENT LPAREN structuredMessage RPAREN
        ;
---

Message is a tree like structure

struct Message
{
        int type;
        
        string value;
        
        Message *op1;
        Message *op2;
};

Using  semantic  action I can make and fill a Message structure in the
basicMessage role the problem is with the structuredMessage role.

In  my idea the subrole identified by bm1 should go into the op1 field
of  the  returned  Message structure and the subrole identified by bm2
should  go into the op2 field.

For  a message like (the "." is PAIR) A1.A2.A3 the structure should be
like (ASCII art incoming :)
   |
  / \
A1  / \
  A2  A3

The problem is that the role iterate the star part making difficult to
build a tree like structure.

So i was wondering how i can fill the Message structure?

The action i've written was something like

structuredMessage returns[Message *rmsg]
{
        Message *tbasicMessage = NULL;
        Message *tbasicMessages = NULL;
        Message *tmsg = NULL;
}
        : tbasicMessage=basicMessage 
                {  
                        tmsg = new Message;
                        tmsg->op1 = tbasicMessage;
                        tmsg->op2 = NULL;
                        rmsg = tmsg;
                }
                (PAIRING tbasicMessages=basicMessage
                {  
                        tmsg = new Message;
                        tmsg->op1 = tbasicMessage;
                        tmsg->op2 = tbasicMessages;
                        rmsg = tmsg;
                } )*
        ;
        
I really don't know what to do :(
        
Regards
-- 
 Nicola                          mailto:ncuomo at gmail.com


_____________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.

_____________________________________________________________________
This email message, including any attachments, may contain confidential and proprietary information for the sole use of the intended recipient.  If you are not the intended recipient, you are hereby notified that any use, copying or dissemination of this message is strictly prohibited.  If you received this message in error, please notify Brooks Automation, Inc. immediately by reply email or by calling Brooks US Headquarters at +1 978-262-2400. Then delete this message from your system, without making any copy or distribution.  Thank you.


More information about the antlr-interest mailing list