A calculator
{my %variables}
start: statement /^\Z/ {$variables {'.'} = $item [1]}
statement: variable '=' statement {$variables {$item [1]} = $item [3]}
| expression
expression: term '+' expression {$item [1] + $item [3]}
| term '-' expression {$item [1] - $item [3]}
| term
term: factor '*' term {$item [1] * $item [3]}
| factor '/' term {$item [1] / $item [3]}
| factor
factor: number
| variable {$variables {$item [1]} ||=
Math::BigInt -> new (0)}
| '+' factor {$item [2]}
| '-' factor {$item [2] * -1}
| '(' statement ')' {$item [2]}
number: /\d+/ {Math::BigInt -> new ($item [1])}
variable: /[a-z]+/i
| '.'
[Prev]
[Next]
[Index]