Recursive Production

37 views
Skip to first unread message

Tabiul Mahmood

unread,
Oct 11, 2013, 3:12:17 AM10/11/13
to sab...@googlegroups.com
Token
   tw
= 'w';
   comma
= ',';
Production
    operation
=  operation (comma operation)*
                     
| tw

This does not work for sablecc. How can I do something like this in sablecc. In this example, the production operation could be 'w' or 'w','w','w'.........

Thanks

Hong Phuc Bui

unread,
Oct 11, 2013, 3:32:25 AM10/11/13
to sab...@googlegroups.com
You can use something like that:


Tokens

   tw = 'w';
   comma = ',';
Productions
    operation = tw tw_tail*;
    tw_tail = comma tw;
--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
---
You received this message because you are subscribed to the Google Groups "SableCC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sablecc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tabiul Mahmood

unread,
Oct 11, 2013, 3:48:15 AM10/11/13
to sab...@googlegroups.com
Oh ok, thanks. I wish I could do the way I proposed as I feel that is more intuitive and does not break the production into multiple entries. I can do that in Antlr. I am using sablecc due to poor support for c++ in Antlr. Sablecc has been good to me so far :) but wish the production was more expressive like Antlr.

Hong Phuc Bui

unread,
Oct 11, 2013, 4:00:54 AM10/11/13
to sab...@googlegroups.com
The syntax from antlr is maybe more intuitive, but you can also transform your CST tree into AST tree with SableCC.
Something like this may be useful:


Tokens
   tw = 'w';
   comma = ',';
Productions
    operation = tw [tail]:tw_tail*
        {->New operation([tw,tail.tw])}
;

    tw_tail
        {-> tw}
        = comma tw{->tw};

Abstract Syntax Tree
    operation = tw*;

So you get a operation as a list of tw. Pls. see more about this in master thesis.
Reply all
Reply to author
Forward
0 new messages