[TCS] Storing operators as enumeration values [message #377464] |
Sat, 05 May 2007 13:43 |
Lorenzo Dalla Vecchia Messages: 58 Registered: July 2009 |
Member |
|
|
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
|
|
|
Re: [TCS] Storing operators as enumeration values [message #377466 is a reply to message #377464] |
Sat, 05 May 2007 19:33 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hello,
> My project with TCS is going along very well, using SPL.tcs as reference.
I am glad to read this :-).
> 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.
The current version of TCS does not allow the use of enumerations to
represent operators. "enumeration literals for operators" is still in
the TODO list.
This will require an additional definition of operator-to-literal
mappings. Consequently, it will be necessary to slightly extend TCS
syntax, not just the translation from TCS+KM3 to ANTLR.
> 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?
The problem is probably that TCS tries to assign a String to the
operation attribute, which fails and leads to failure of subsequent
settings (i.e., lExpr and rExpr).
Regards,
Frédéric Jouault
|
|
|
|
Re: [TCS] Storing operators as enumeration values [message #581898 is a reply to message #377464] |
Sat, 05 May 2007 19:33 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hello,
> My project with TCS is going along very well, using SPL.tcs as reference.
I am glad to read this :-).
> 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.
The current version of TCS does not allow the use of enumerations to
represent operators. "enumeration literals for operators" is still in
the TODO list.
This will require an additional definition of operator-to-literal
mappings. Consequently, it will be necessary to slightly extend TCS
syntax, not just the translation from TCS+KM3 to ANTLR.
> 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?
The problem is probably that TCS tries to assign a String to the
operation attribute, which fails and leads to failure of subsequent
settings (i.e., lExpr and rExpr).
Regards,
Frédéric Jouault
|
|
|
|
Powered by
FUDForum. Page generated in 0.03189 seconds