[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "alternative1 | alternative2" to " alternative1* alternative2*" ast transformation



Hi Soeren,

First, your AST should be changed to:

/***********************************************************
§ MI 1.00.00 Abstract Syntax Tree root
***********************************************************/
object = slots;

/***********************************************************
§ MI 2.00.00 Global slots
***********************************************************/
slots =
  parent_slot* promote_slot* container_slot* import_slot*
    variable_slot* public_slot* private_slot*;


Now, here's alittle trick.



object =


  slot*
    {-> New slots([slot.parent_slot], [slot.promote_slot],
        [slot.container_slot], ...) };

slot
    {-> parent_slot promote_slot container_slot ... } =

  {parent_slot} parent_slot
    [-> parent_slot Null Null ... } |

  {promote_slot} promote_slot
    [-> Null promote_slot Null ... } |

  {container_slot} container_slot
    [-> Null Null container_slot ... } |
...


Have fun!


Etienne

Søren Andreasen wrote:
Hi,

I have a really big problem. My syntax does not require a bunch of
alternatives to appear in a specific order.
But I would like to sort them in my AST.

Somethin like:
-----------------------------------
Productions

/***********************************************************
§ MI 1.00.00 Abstract Syntax Tree root
***********************************************************/
object = slot*;

/***********************************************************
§ MI 2.00.00 Global slots
***********************************************************/
slot =
  {import_slot} import_slot |
  {variable_slot} variable_slot |
  {public_slot} public_slot |
  {private_slot} private_slot;

<...>

Abstract Syntax Tree

/***********************************************************
§ MI 1.00.00 Abstract Syntax Tree root
***********************************************************/
object = slot*;

/***********************************************************
§ MI 2.00.00 Global slots
***********************************************************/
slot = parent_slot* promote_slot* container_slot* import_slot*
variable_slot* public_slot* private_slot*;
-----------------------------------

No matter how I try I can't get it to work.. Please help!

Regards, Soeren




-- Etienne M. Gagnon, Ph.D. http://www.info.uqam.ca/~egagnon/ SableVM: http://www.sablevm.org/ SableCC: http://www.sablecc.org/