diff --git a/Arithmetic.pp b/Arithmetic.pp index a2007d7..df8c886 100644 --- a/Arithmetic.pp +++ b/Arithmetic.pp @@ -49,6 +49,7 @@ %token minus \-|− %token times \*|× %token div /|÷ +%token indices \^ %token constant [A-Z_]+[A-Z0-9_]* %token id \w+ @@ -62,7 +63,10 @@ ternary() ( ::times:: #multiplication expression() )? ternary: - term() ( ::div:: #division expression() )? + quaternary() ( ::div:: #division expression() )? + +quaternary: + term() ( ::indices:: #indices expression() )? term: ( ::bracket_:: expression() ::_bracket:: #group ) diff --git a/Visitor/Arithmetic.php b/Visitor/Arithmetic.php index 3308820..b42cb49 100644 --- a/Visitor/Arithmetic.php +++ b/Visitor/Arithmetic.php @@ -177,6 +177,17 @@ public function visit( break; + case '#indices': + $children[0]->accept($this, $a, $eldnah); + + $acc = function ($b) use ($a, $acc) { + return $acc(pow($a(), $b)); + }; + + $children[1]->accept($this, $acc, $eldnah); + + break; + case '#division': $children[0]->accept($this, $a, $eldnah); $parent = $element->getParent();