1 using System;
2 using System.Numerics.Multiprecision;
3 using BigNumTokens;
4 using BigNumCalc;
5
6 parser BigNumExpressionParser
7 {
8 uselexer BigNumLexer;
9 main;
10
11 Expr(EvaluationStack* s, var uchar op)
12 ::= Term(s):left
13 (
14 (PLUS | MINUS){ op = lexer.GetUChar(pos); }
15 Term(s):right
16 {
17 BigValue* r = s->Pop();
18 BigValue* l = s->Pop();
19 s->Push(Evaluate(l, r, op));
20 }
21 )*
22 ;
23
24 Term(EvaluationStack* s, var uchar op)
25 ::= Factor(s):left
26 (
27 (MUL | DIV){ op = lexer.GetUChar(pos); }
28 Factor(s):right
29 {
30 BigValue* r = s->Pop();
31 BigValue* l = s->Pop();
32 s->Push(Evaluate(l, r, op));
33 }
34 )*
35 ;
36
37 Factor(EvaluationStack* s)
38 ::= MINUS Factor(s):f1{ s->Push(Evaluate(s->Pop(), '-')); }
39 | PLUS Factor(s):f2{ s->Push(Evaluate(s->Pop(), '+')); }
40 | Number(s):num
41 | LPAREN Expr(s):e RPAREN
42 ;
43
44 Number(EvaluationStack* s)
45 ::= FLOAT{ s->Push(ParseBigFloat(lexer.GetToken(pos))); }
46 | RATIONAL{ s->Push(ParseBigRational(lexer.GetToken(pos))); }
47 | INTEGER{ s->Push(ParseBigInteger(lexer.GetToken(pos))); }
48 ;
49 }