Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit 0df9b34

Browse files
rubicon9carl
authored and
carl
committed
Adding Support for Indices
- Adding token ^ - Updating order of operation to include indices - Adding action for new #indices (using php pow function) - NB, tests delayed since it appears the suite is already failing?
1 parent 311a733 commit 0df9b34

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Arithmetic.pp

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
%token minus \-|−
5050
%token times \*|×
5151
%token div /|÷
52+
%token indices \^
5253
%token constant [A-Z_]+[A-Z0-9_]*
5354
%token id \w+
5455

@@ -62,7 +63,10 @@
6263
ternary() ( ::times:: #multiplication expression() )?
6364

6465
ternary:
65-
term() ( ::div:: #division expression() )?
66+
quaternary() ( ::div:: #division expression() )?
67+
68+
quaternary:
69+
term() ( ::indices:: #indices expression() )?
6670

6771
term:
6872
( ::bracket_:: expression() ::_bracket:: #group )

Visitor/Arithmetic.php

+11
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ public function visit(
177177

178178
break;
179179

180+
case '#indices':
181+
$children[0]->accept($this, $a, $eldnah);
182+
183+
$acc = function ($b) use ($a, $acc) {
184+
return $acc(pow($a(), $b));
185+
};
186+
187+
$children[1]->accept($this, $acc, $eldnah);
188+
189+
break;
190+
180191
case '#division':
181192
$children[0]->accept($this, $a, $eldnah);
182193
$parent = $element->getParent();

0 commit comments

Comments
 (0)