Scanner.SUB_ASSIGN, Scanner.MUL_ASSIGN, Scanner.QUO_ASSIGN,
Scanner.REM_ASSIGN, Scanner.AND_ASSIGN, Scanner.OR_ASSIGN,
Scanner.XOR_ASSIGN, Scanner.SHL_ASSIGN, Scanner.SHR_ASSIGN:
- s = Node.NewStat(P.pos, P.tok);
+ // assignment
+ pos, tok := P.pos, P.tok;
P.Next();
- s.lhs = x;
- s.expr = P.ParseExpressionList();
- if l, r := x.len(), s.expr.len(); l > 1 && r > 1 && l != r {
+ y := P.ParseExpressionList();
+ if xl, yl := x.len(), y.len(); xl > 1 && yl > 1 && xl != yl {
P.Error(x.pos, "arity of lhs doesn't match rhs");
}
+ s = Node.NewStat(x.pos, Scanner.EXPRSTAT);
+ s.expr = Node.NewExpr(pos, tok, x, y);
default:
var pos, tok int;
case Scanner.PERIOD:
// selector or type guard
- P.Expr1(x.x, 8); // 8 == highest precedence
+ P.Expr1(x.x, Scanner.HighestPrec);
P.String(x.pos, ".");
if x.y != nil {
- P.Expr1(x.y, 8);
+ P.Expr1(x.y, Scanner.HighestPrec);
} else {
P.String(0, "(");
P.Type(x.t);
case Scanner.LBRACK:
// index
- P.Expr1(x.x, 8);
+ P.Expr1(x.x, Scanner.HighestPrec);
P.String(x.pos, "[");
P.Expr1(x.y, 0);
P.String(0, "]");
case Scanner.LPAREN:
// call
- P.Expr1(x.x, 8);
+ P.Expr1(x.x, Scanner.HighestPrec);
P.String(x.pos, "(");
P.Expr1(x.y, 0);
P.String(0, ")");
if x.x == nil {
// unary expression
P.Token(x.pos, x.tok);
- P.Expr1(x.y, 7); // 7 == unary operator precedence
+ P.Expr1(x.y, Scanner.UnaryPrec);
} else {
// binary expression: print ()'s if necessary
prec := Scanner.Precedence(x.tok);
func (P *Printer) Expr(x *Node.Expr) {
- P.Expr1(x, 0);
+ P.Expr1(x, Scanner.LowestPrec);
}
// declaration
P.Declaration(s.decl, false);
- case Scanner.DEFINE, Scanner.ASSIGN, Scanner.ADD_ASSIGN,
- Scanner.SUB_ASSIGN, Scanner.MUL_ASSIGN, Scanner.QUO_ASSIGN,
- Scanner.REM_ASSIGN, Scanner.AND_ASSIGN, Scanner.OR_ASSIGN,
- Scanner.XOR_ASSIGN, Scanner.SHL_ASSIGN, Scanner.SHR_ASSIGN:
- // assignment
- P.Expr(s.lhs);
- P.Blank();
- P.Token(s.pos, s.tok);
- P.Blank();
- P.Expr(s.expr);
- P.semi = true;
-
case Scanner.INC, Scanner.DEC:
P.Expr(s.expr);
P.Token(s.pos, s.tok);