Skip to content

Commit

Permalink
Add support for increment and decrement expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Jul 8, 2024
1 parent e9a7d8b commit 89a0fda
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ttcn3/syntax/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ type (
X Expr
}

// A postfix expresseion (i++, i--)
PostExpr struct {
X Expr
Op Token
}

// A BinaryExpr represents a binary expression.
// Possible operands are all tokens with a precedence value, TO and FROM.
BinaryExpr struct {
Expand Down Expand Up @@ -338,6 +344,7 @@ func (x *ParametrizedIdent) exprNode() {}
func (x *ValueLiteral) exprNode() {}
func (x *CompositeLiteral) exprNode() {}
func (x *UnaryExpr) exprNode() {}
func (x *PostExpr) exprNode() {}
func (x *BinaryExpr) exprNode() {}
func (x *ParenExpr) exprNode() {}
func (x *SelectorExpr) exprNode() {}
Expand Down
67 changes: 67 additions & 0 deletions ttcn3/syntax/nodes_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion ttcn3/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ func (p *parser) parseBinaryExpr(prec1 int) Expr {
func (p *parser) parsePostfixExpr() Expr {
x := p.parseUnaryExpr()

if p.tok == INC || p.tok == DEC {
x = &PostExpr{X: x, Op: p.consume()}
}

if p.tok == LENGTH {
x = p.parseLength(x)
}
Expand Down Expand Up @@ -658,7 +662,7 @@ func (p *parser) parsePostfixExpr() Expr {
// | PrimaryExpr
func (p *parser) parseUnaryExpr() Expr {
switch p.tok {
case ADD, EXCL, NOT, NOT4B, SUB:
case ADD, EXCL, NOT, NOT4B, SUB, INC, DEC:
tok := p.consume()
// handle unused expr '-'
if tok.Kind() == SUB {
Expand Down

0 comments on commit 89a0fda

Please sign in to comment.