[TCS] Storing operators as enumeration values [message #581864] |
Sat, 05 May 2007 09:43 |
Eclipse User |
|
|
|
Hello.
My project with TCS is going along very well, using SPL.tcs as reference.
I stumbled upon a minor problem with operation templates: as far as I know,
the storeOpTo option of an operatorTemplate specifies the attribute to save
the parsed operator to. I found that such attribute must be of KM3 type
String for the parser to work, however I originally planned to represent
operations in the KM3 models by means of an enumeration type, to keep the
model high-level.
KM3
---
enumeration Operation {
literal Addition
literal Subtraction
}
class OperationExpr extends Expr {
reference lExpr : Expr;
reference rExpr : Expr;
attribute operation : Operation;
}
TCS
---
operatorTemplate OperatorExpr(operators=opPlus opMinus, source=lExpr,
storeOpTo=operation);
With the above code, the ANTLR parser compiles correctly, but when parsing
an expression, the two Expr objects and an empty OperationExpr are flattened
out at the same level of the tree.
|- Expr
|- Expr
\- Operation {with operation attribute to default value, the first of the
enum}
Instead of:
\- Operation
|- Expr
\- Expr
The problem desappears if I set the type of the operation attribute back to
String.
Is there a way to do this with today's TCS?
Thanks.
--
Lorenzo
|
|
|
Powered by
FUDForum. Page generated in 0.03551 seconds