protected function procAssignment(Token $token) { $this->debug(__METHOD__, __LINE__, "identifier: {$token->getValue()}"); // Validate the leftside if ($token->getType() != TokenType::IDENTIFIER) { throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment identifier: '{$token->getValue()}'", __FILE__, __LINE__); } $name = $token->getValue(); $token = $this->getToken(); // Validate the operator switch ($token->getType()) { case TokenType::SYMBOL: switch ($token->getValue()) { case ';': if (!$this->memory->hasVar($name)) { throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($name) + 1, "Unknown identifier: '{$name}'", __FILE__, __LINE__); } // Do nothing :\ return; break; case '=': // allow = break; case '++': case '--': // allow ++ and -- break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__); } break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__); } $operator = $token->getValue(); // Evaluate the rightside $type = $this->evalExp($value); // Perform action switch ($operator) { case '=': $this->memory->setVar($name, $value, $type); break; case '++': // number only // number only case '--': if (!$this->memory->hasVar($name)) { throw new SyntaxException($token->getLine(), $token->getColumn(), "Unknown identifier: '{$name}'", __FILE__, __LINE__); } $value = $this->memory->getVar($name); if ($operator == '++') { $newval = intval($value + 1); } else { $newval = intval($value - 1); } $this->memory->setVar($name, $newval, $type); break; default: throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($operator) + 1, "Unknown operator: '{$operator}'", __FILE__, __LINE__); break; } }