1

Is it possible to generate .m and .h's for any grammar/ rules so that during parsing it creates an object that represents that rule.

So some grammar

coolObjName = Word;

could generate a class that is named coolObjName (or some variation) and has a field for the word, and generates the action:

coolObjName = Word{
    CoolObjName* newName = [[CoolObjName alloc] initWithWord:POP_STR()];
    PUSH(newName);
};

Then a higher level rule such as:

myhigherlevel = coolObjName Number;

would create a myHigherLevel class that has a coolObjName member and a number, which then adds the action:

myhigherlevel = coolObjName Number{
   double num = POP_DOUBLE();
   coolObjName* name = POP(); 
   MyHigherLevel* higherLevel = [[MyHigherLevel alloc] init];
   higherLevel.number = num;
   higherLevel.name = name;
   PUSH(higherLevel);
};

Empty tags turn to empty objects and * and + result in arrays.

Is there a tool that can do this or where would I go to create such. (seems super useful and awesome)

4

1 回答 1

0
于 2014-04-10T03:02:29.153 回答