Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMT (Generative Modeling Technologies) » [TCS] Storing operators as enumeration values
[TCS] Storing operators as enumeration values [message #377464] Sat, 05 May 2007 13:43 Go to next message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
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 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
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 #377468 is a reply to message #377466] Sat, 05 May 2007 20:43 Go to previous message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
> 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.
>
> 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).

I see. Ok, that's not a big issue for me.
Thanks for the explanation.

--
Lorenzo
Re: [TCS] Storing operators as enumeration values [message #581898 is a reply to message #377464] Sat, 05 May 2007 19:33 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
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 #581913 is a reply to message #377466] Sat, 05 May 2007 20:43 Go to previous message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
> 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.
>
> 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).

I see. Ok, that's not a big issue for me.
Thanks for the explanation.

--
Lorenzo
Previous Topic:[TCS] Storing operators as enumeration values
Next Topic:[TCS] Multiple "operatored" templates conflict
Goto Forum:
  


Current Time: Fri Dec 19 08:55:09 GMT 2014

Powered by FUDForum. Page generated in 0.02162 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software