tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,19 @@
|
|||
grammar rpnC ;
|
||||
//
|
||||
// rpn Calculator
|
||||
//
|
||||
// Nigel Galloway - April 7th., 2012
|
||||
//
|
||||
@members {
|
||||
Stack<Double> s = new Stack<Double>();
|
||||
}
|
||||
rpn : (WS* (num|op) (WS | WS* NEWLINE {System.out.println(s.pop());}))*;
|
||||
num : '-'? Digit+ ('.' Digit+)? {s.push(Double.parseDouble($num.text));};
|
||||
Digit : '0'..'9';
|
||||
op : '-' {double x = s.pop(); s.push(s.pop() - x);}
|
||||
| '/' {double x = s.pop(); s.push(s.pop() / x);}
|
||||
| '*' {s.push(s.pop() * s.pop());}
|
||||
| '^' {double x = s.pop(); s.push(Math.pow(s.pop(), x));}
|
||||
| '+' {s.push(s.pop() + s.pop());};
|
||||
WS : (' ' | '\t'){skip()};
|
||||
NEWLINE : '\r'? '\n';
|
||||
Loading…
Add table
Add a link
Reference in a new issue