Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar Calc
- addSub
- addSub return [v : int]
- : mulDiv addSub2(<mulDiv.v>)
- <$v = addSub2.v;>
- ;
- addSub2 (left : int) return [v : int]
- : ADD mulDiv <int next = left + mulDiv.v;>
- addSub2(next) <$v = addSub2.v;>
- | SUB mulDiv <int next = left - mulDiv.v;>
- addSub2(next) <$v = addSub2.v;>
- | <$v = left;>
- ;
- mulDiv return [v : int]
- : scope mulDiv2(<scope.v>) <$v = mulDiv2.v;>
- ;
- mulDiv2 (left : int) return [v : int]
- : MUL scope mulDiv2(<left * scope.v>) <$v = mulDiv2.v;>
- | DIV scope mulDiv2(<left / scope.v>) <$v = mulDiv2.v;>
- | <$v = left;>
- ;
- factorial return [v : int]
- : OP addSub CP <$v = addSub.v;>
- | NUM <$v = Integer.valueOf(NUM);>
- ;
- maybe return [v : char]
- : FAC <$v = '!';>
- | "" <$v = 'N';>
- ;
- scope return [v : int]
- : OP addSub CP maybe <if(maybe.v == 'N')$v = addSub.v; else $v = addSub.v * 40;>
- | SUB scope <$v = -scope.v;>
- | NUM maybe <if(maybe.v == 'N')$v = Integer.valueOf(NUM); else $v = Integer.valueOf(NUM) * 40;>
- ;
- ADD : "+";
- SUB : "-";
- MUL : "*";
- FAC : "!";
- DIV : "/";
- OP : "(";
- CP : ")";
- NUM $ "([1-9][0-9]*)|(0)";
- skip -> "[ \n\r\t]+";
- EMP : "";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement