diff --git a/Arithmetic.pp b/Arithmetic.pp index 2e25e1f..fd4abf7 100644 --- a/Arithmetic.pp +++ b/Arithmetic.pp @@ -52,6 +52,7 @@ %token minus \-|− %token times \*|× %token div /|÷ +%token pow \^ %token constant [A-Z_]+[A-Z0-9_]+ %token id \w+ @@ -65,7 +66,10 @@ ternary() ( ::times:: #multiplication expression() )? ternary: - term() ( ::div:: #division expression() )? + quaternary() ( ::div:: #division expression() )? + +quaternary: + term() ( ::pow:: #power expression() )? term: ( ::bracket_:: expression() ::_bracket:: #group ) diff --git a/Test/Unit/Arithmetic.pp b/Test/Unit/Arithmetic.pp index a615516..fd2743b 100644 --- a/Test/Unit/Arithmetic.pp +++ b/Test/Unit/Arithmetic.pp @@ -51,6 +51,7 @@ %token minus \- %token times \* %token div / +%token pow \^ %token constant [A-Z_]+[A-Z0-9_]+ %token id \w+ @@ -64,7 +65,10 @@ ternary() ( ::times:: #multiplication expression() )? ternary: - term() ( ::div:: #division expression() )? + quaternary() ( ::div:: #division expression() )? + +quaternary: + term() ( ::pow:: #power expression() )? term: ( ::bracket_:: expression() ::_bracket:: #group ) diff --git a/Visitor/Arithmetic.php b/Visitor/Arithmetic.php index 1534192..e9253bc 100644 --- a/Visitor/Arithmetic.php +++ b/Visitor/Arithmetic.php @@ -209,6 +209,17 @@ public function visit( break; + case '#power': + $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 '#fakegroup': case '#group': $children[0]->accept($this, $a, $eldnah);