|
@ -23,10 +23,24 @@ Stmt = @AssignStmt SEMI |
|
|
AssignStmt = name:Ident ASSIGN expr:Expr { return stmt("assign", { name, expr }) } |
|
|
AssignStmt = name:Ident ASSIGN expr:Expr { return stmt("assign", { name, expr }) } |
|
|
|
|
|
|
|
|
// Expressions |
|
|
// Expressions |
|
|
Expr = AddExpr |
|
|
|
|
|
|
|
|
Expr = BitOrExpr |
|
|
|
|
|
|
|
|
|
|
|
BitOrExpr = head:BitXorExpr tail:(op:BitOrOp e:BitXorExpr)* { return assocl(head, tail || []) } |
|
|
|
|
|
BitOrOp = PIPE { return "bit_or" } |
|
|
|
|
|
|
|
|
|
|
|
BitXorExpr = head:BitAndExpr tail:(op:BitXorOp e:BitAndExpr)* { return assocl(head, tail || []) } |
|
|
|
|
|
BitXorOp = CARET { return "bit_xor" } |
|
|
|
|
|
|
|
|
|
|
|
BitAndExpr = head:ShiftExpr tail:(op:BitAndOp e:ShiftExpr)* { return assocl(head, tail || []) } |
|
|
|
|
|
BitAndOp = AMPERSAND { return "bit_and" } |
|
|
|
|
|
|
|
|
|
|
|
ShiftExpr = head:AddExpr tail:(op:ShiftOp e:AddExpr)* { return assocl(head, tail || []) } |
|
|
|
|
|
ShiftOp = LTLT { return "shift_left" } |
|
|
|
|
|
/ GTGT { return "shift_right" } |
|
|
|
|
|
|
|
|
AddExpr = head:UnaryExpr tail:(op:AddOp e:UnaryExpr)* { return assocl(head, tail || []) } |
|
|
AddExpr = head:UnaryExpr tail:(op:AddOp e:UnaryExpr)* { return assocl(head, tail || []) } |
|
|
AddOp = PLUS { return "add" } |
|
|
AddOp = PLUS { return "add" } |
|
|
|
|
|
/ MINUS { return "subtract" } |
|
|
|
|
|
|
|
|
UnaryExpr = op:UnaryOp? e:BaseExpr { return op ? uexpr(op, e) : e } |
|
|
UnaryExpr = op:UnaryOp? e:BaseExpr { return op ? uexpr(op, e) : e } |
|
|
UnaryOp = TILDE { return "bit_negate" } |
|
|
UnaryOp = TILDE { return "bit_negate" } |
|
@ -59,6 +73,11 @@ U8 = @'u8' WS |
|
|
U16 = @'u16' WS |
|
|
U16 = @'u16' WS |
|
|
|
|
|
|
|
|
// Terminal symbols |
|
|
// Terminal symbols |
|
|
|
|
|
PIPE = '|' WS |
|
|
|
|
|
CARET = '^' WS |
|
|
|
|
|
AMPERSAND = '&' WS |
|
|
|
|
|
LTLT = '<<' WS |
|
|
|
|
|
GTGT = '>>' WS |
|
|
PLUS = '+' WS |
|
|
PLUS = '+' WS |
|
|
TILDE = '~' WS |
|
|
TILDE = '~' WS |
|
|
MINUS = '-' WS |
|
|
MINUS = '-' WS |
|
|