Beispiel #1
0
 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--;
 }
Beispiel #2
0
 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;
     }
 }