[TCS] postfix operators [message #22561] |
Fri, 31 October 2008 11:57 |
T Kruse Messages: 73 Registered: July 2009 |
Member |
|
|
Hi,
TCS has a notation for postfix operators, but the result looks weird for
arity = 2. Is this maybe only intended for unary operators?
Like for any binary operator "+", in theory one could have it infix, as in
3+2, or prefix, as in +(3,4), or postfix as in (3,4)+
but I guess none of these are covered by TCS, right?
|
|
|
Re: [TCS] postfix operators [message #22691 is a reply to message #22561] |
Mon, 03 November 2008 15:01 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hi Thibault,
"Postfix" has indeed only been used for unary operators so far.
Because it is possible to represent "(3, 4)+" without using
operatorTemplates, you may directly encode the postfix notation using
standard templates.
For instance:
- Metamodel excerpt:
abstract class Expression {}
class BinaryOpExp extends Expression {
reference leftOperand container : Expression;
attribute operator : Operator;
reference rightOperand container : Expression;
}
enumeration Operator {
literal plus;
literal minus;
literal and;
literal or;
-- ...
}
- TCS excerpt:
template BinaryOpExp
: "(" leftOperand "," rightOperand ")" operator
;
enumerationTemplate Operator
: #plus = "+",
#minus = "-",
#and = "and",
#or = "or"
;
Of course, it would also be possible to implement support for postfix
operatorTemplates in TCS.
Best regards,
Frédéric Jouault
T Kruse a écrit :
> Hi,
>
> TCS has a notation for postfix operators, but the result looks weird for
> arity = 2. Is this maybe only intended for unary operators?
>
> Like for any binary operator "+", in theory one could have it infix, as
> in 3+2, or prefix, as in +(3,4), or postfix as in (3,4)+
> but I guess none of these are covered by TCS, right?
>
|
|
|
Powered by
FUDForum. Page generated in 0.03151 seconds