public function __construct($scanner, $_symTable) { parent::requireKeyword($scanner, 'case'); $scanner->next(); $this->condition = new Expression($scanner, $_symTable); parent::requireKeyword($scanner, 'of'); $scanner->next(); Globals::$switchDepth++; while (true) { if ($scanner->get()->isKeyword('else')) { $scanner->next(); $this->default = CompoundStatement::smartParse($scanner, $_symTable); parent::semicolonPass($scanner); break; } $caseCondition = new Expression($scanner, $_symTable); $caseCondition = TypeCast::tryTypeCast($caseCondition, $this->condition->symType, false); parent::requireOperator($scanner, ':'); $scanner->next(); $caseStatements = CompoundStatement::smartParse($scanner, $_symTable); $this->cases[] = ["condition" => $caseCondition, "statements" => $caseStatements]; parent::semicolonPass($scanner); if ($scanner->get()->isKeyword('end')) { break; } } Globals::$switchDepth--; parent::requireKeyword($scanner, 'end'); $scanner->next(); }
public function __construct($scanner, $_symTable) { parent::requireKeyword($scanner, 'for'); $scanner->next(); $this->counter = VariableAccess::parse($scanner, $_symTable); if (!SymSimpleType::equal($this->counter->symType, Globals::getSimpleType('integer'))) { SemanticException::raw($scanner, 'Counter must be integer'); } parent::requireOperator($scanner, ':='); $scanner->next(); $this->from = new Expression($scanner, $_symTable); $this->from = TypeCast::tryTypeCast($this->from, 'integer'); switch ($scanner->get()->getValue()) { case 'to': $this->direction = self::DIRECTION_ASC; break; case 'downto': $this->direction = self::DIRECTION_DESC; break; default: parent::simpleException($scanner, ['<KEYWORD \'to\'>', '<KEYWORD \'downto\'>']); } $scanner->next(); $this->to = new Expression($scanner, $_symTable); $this->to = TypeCast::tryTypeCast($this->to, 'integer'); parent::requireKeyword($scanner, 'do'); $scanner->next(); Globals::$loopDepth++; $this->statements = CompoundStatement::smartParse($scanner, $_symTable); Globals::$loopDepth--; }
public function __construct($scanner, $_symTable) { if ($scanner->get()->isUnSignedConst()) { $this->node = $scanner->get(); $this->symType = SymType::recognizeSimpleType($this->node, $_symTable); $scanner->next(); return; } if ($scanner->get()->isLBracket()) { $scanner->next(); $this->node = new Expression($scanner, $_symTable); parent::requireOperator($scanner, ')'); $this->symType = $this->node->symType; $scanner->next(); return; } if ($scanner->get()->isKeyword('not')) { $this->keyword = $scanner->get(); $scanner->next(); $this->node = new Factor($scanner, $_symTable); $this->node = TypeCast::tryTypeCast($this->node, 'boolean'); $this->symType = $this->node->symType; return; } if ($scanner->get()->isIdentifier()) { $identifier = $scanner->get(); $symbol = $_symTable->findRecursive($identifier->getValue()); if (is_a($symbol, 'vendor\\SemanticParser\\Nodes\\SymType')) { $scanner->next(); if (!$scanner->get()->isLBracket()) { parent::simpleException($scanner, ['<OPERATOR \'(\'>']); } $scanner->next(); $expression = new Expression($scanner, $_symTable); if (!$scanner->get()->isRBracket()) { parent::simpleException($scanner, ["<OPERATOR ')'>"]); } $scanner->next(); $class = get_class($expression->symType); if (!$class::equal($expression->symType, $symbol)) { $expression = new TypeCast($expression, $symbol); } $this->node = $expression; $this->symType = $this->node->symType; return; } $scanner->next(); if ($scanner->get()->isLBracket()) { $actualParamList = new ActualParamList($scanner, $_symTable); $this->node = new FunctionDesignator($identifier, $actualParamList, $_symTable); } else { $this->node = VariableAccess::parse($scanner, $_symTable, $identifier); } $this->symType = $this->node->symType; return; } }
public function __construct($scanner, $_symTable) { parent::requireKeyword($scanner, 'while'); $scanner->next(); $this->condition = new Expression($scanner, $_symTable); $this->condition = TypeCast::tryTypeCast($this->condition, 'boolean'); parent::requireKeyword($scanner, 'do'); $scanner->next(); Globals::$loopDepth++; $this->statements = CompoundStatement::smartParse($scanner, $_symTable); Globals::$loopDepth--; }
public function __construct($left, $right, $operator, $_symTable) { switch ($operator->getValue()) { case 'div': case 'mod': $right = TypeCast::tryTypeCast($right, 'integer'); $left = TypeCast::tryTypeCast($left, 'integer'); $this->symType = Globals::getSimpleType('integer'); break; case 'and': case 'or': case 'xor': $right = TypeCast::tryTypeCast($right, 'boolean'); $left = TypeCast::tryTypeCast($left, 'boolean'); $this->symType = Globals::getSimpleType('boolean'); break; case '*': case '+': case '-': if (SymSimpleType::equal($left->symType, Globals::getSimpleType('integer')) && SymSimpleType::equal($right->symType, Globals::getSimpleType('integer'))) { $this->symType = Globals::getSimpleType('integer'); break; } case '/': $left = TypeCast::tryTypeCast($left, 'real'); $right = TypeCast::tryTypeCast($right, 'real'); $this->symType = Globals::getSimpleType('real'); break; case '>': case '<': case '>=': case '<=': case '<>': case '=': if (SymSimpleType::equal($left->symType, Globals::getSimpleType('integer')) && SymSimpleType::equal($right->symType, Globals::getSimpleType('integer'))) { $this->symType = Globals::getSimpleType('boolean'); break; } $left = TypeCast::tryTypeCast($left, 'real'); $right = TypeCast::tryTypeCast($right, 'real'); $this->symType = Globals::getSimpleType('boolean'); break; default: throw new \Exception('OPERATOR NOT IMPLEMENTED YET'); } $this->left = $left; $this->right = $right; $this->operator = $operator; }