Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Arithmetic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
%token minus \-|−
%token times \*|×
%token div /|÷
%token indices \^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the token name pow?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using either indices or exponent would be more correct but it's a trivial thing, I don't mind either way.

%token constant [A-Z_]+[A-Z0-9_]*
%token id \w+

Expand All @@ -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 )
Expand Down
11 changes: 11 additions & 0 deletions Visitor/Arithmetic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down