diff options
author | Bruce Wells <brucekwells@gmail.com> | 2020-06-04 18:43:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 18:43:16 +0300 |
commit | aa8ffe19f2eb6f194b3e6ee1aac4c2706659e6b9 (patch) | |
tree | 55ef6ebce4cdcb53bfe7cc142ef40f90756d9b6c /src/NXP/Classes/Tokenizer.php | |
parent | ea898d7a7b85aeb677f81f13784232c99b61808a (diff) |
Variable fixes (#67)V2.0.3
* Reproduce if throws UnknownOperatorException
* Fix variable detection
* Adding IncorrectNumberOfFunctionParametersException
* Removing tabs
* Better exception message text
Diffstat (limited to 'src/NXP/Classes/Tokenizer.php')
-rw-r--r-- | src/NXP/Classes/Tokenizer.php | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php index 6b14677..203724a 100644 --- a/src/NXP/Classes/Tokenizer.php +++ b/src/NXP/Classes/Tokenizer.php @@ -157,14 +157,16 @@ class Tokenizer } $this->emptyNumberBufferAsLiteral(); $this->emptyStrBufferAsVariable(); - if (count($this->tokens) > 0) { - if ($this->tokens[count($this->tokens) - 1]->type === Token::Operator) { - $this->tokens[count($this->tokens) - 1]->value .= $ch; + if ($ch != '$') { + if (count($this->tokens) > 0) { + if ($this->tokens[count($this->tokens) - 1]->type === Token::Operator) { + $this->tokens[count($this->tokens) - 1]->value .= $ch; + } else { + $this->tokens[] = new Token(Token::Operator, $ch); + } } else { $this->tokens[] = new Token(Token::Operator, $ch); } - } else { - $this->tokens[] = new Token(Token::Operator, $ch); } $this->allowNegative = true; } @@ -251,12 +253,12 @@ class Tokenizer break; case Token::Operator: if (!array_key_exists($token->value, $this->operators)) { - throw new UnknownOperatorException(); + throw new UnknownOperatorException($token->value); } $op1 = $this->operators[$token->value]; while ($stack->count() > 0 && $stack->top()->type === Token::Operator) { if (!array_key_exists($stack->top()->value, $this->operators)) { - throw new UnknownOperatorException(); + throw new UnknownOperatorException($stack->top()->value); } $op2 = $this->operators[$stack->top()->value]; if ($op2->priority >= $op1->priority) { |