コード例 #1
0
ファイル: SwitchStatement.php プロジェクト: kaduev13/Compiler
 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();
 }
コード例 #2
0
ファイル: ForStatement.php プロジェクト: kaduev13/Compiler
 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--;
 }
コード例 #3
0
ファイル: Factor.php プロジェクト: kaduev13/Compiler
 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;
     }
 }
コード例 #4
0
ファイル: TypeDef.php プロジェクト: kaduev13/Compiler
 public function __construct($scanner, $_symTable)
 {
     if (!$scanner->get()->isIdentifier()) {
         parent::simpleException($scanner, ['<IDENTIFIER>']);
     }
     $identifier = $scanner->get();
     $scanner->next();
     parent::requireOperator($scanner, '=');
     $scanner->next();
     $this->symbol = SymType::parse($scanner, $_symTable, $identifier->getValue());
     $_symTable->append($this->symbol);
 }
コード例 #5
0
ファイル: Program.php プロジェクト: kaduev13/Compiler
 public function __construct($scanner)
 {
     $scanner->next();
     $this->symTable = new SymTable(null);
     Globals::init($this->symTable);
     $this->heading = new ProgramHeading($scanner);
     parent::semicolonPass($scanner);
     $this->block = new Block($scanner, $this->symTable);
     parent::requireOperator($scanner, '.');
     $scanner->next();
     if (!$scanner->get()->isEOF()) {
         parent::simpleException($scanner, ['<EOF>']);
     }
 }
コード例 #6
0
ファイル: ConstDef.php プロジェクト: kaduev13/Compiler
 public function __construct($scanner, $_symTable)
 {
     $identifier = $scanner->get();
     if (!$identifier->isIdentifier()) {
         parent::simpleException($scanner, ['<IDENTIFIER>']);
     }
     $scanner->next();
     parent::requireOperator($scanner, '=');
     $constant = $scanner->nget();
     if (!$constant->isConst()) {
         parent::simpleException($scanner, ['<CONSTANT']);
     }
     $this->symbol = new SymConst($identifier->getValue(), $constant->getValue(), $constant->type, $_symTable);
     $_symTable->append($this->symbol);
     $scanner->next();
 }
コード例 #7
0
ファイル: ActualParamList.php プロジェクト: kaduev13/Compiler
 public function __construct($scanner, $_symTable)
 {
     $this->params = [];
     parent::requireOperator($scanner, '(');
     $scanner->next();
     if ($scanner->get()->isRBracket()) {
         $scanner->next();
         $this->params = [];
         return;
     }
     $this->params[] = new SimpleExpression($scanner, $_symTable);
     while (!$scanner->get()->isRBracket()) {
         parent::requireOperator($scanner, ',');
         $scanner->next();
         $this->params[] = new SimpleExpression($scanner, $_symTable);
     }
     $scanner->next();
 }
コード例 #8
0
ファイル: Proc.php プロジェクト: kaduev13/Compiler
 protected static function parseSignature($scanner, $_symTable)
 {
     if (!$scanner->get()->isIdentifier()) {
         parent::simpleException($scanner, ['<IDENTIFIER>']);
     }
     $symTable = new SymTable($_symTable);
     $identifier = $scanner->get()->getValue();
     $scanner->next();
     if ($scanner->get()->isOperator('(')) {
         $scanner->next();
         $idx = 0;
         while (true) {
             $identifiers = [];
             while ($scanner->get()->isIdentifier()) {
                 $identifiers[] = $scanner->get()->getValue();
                 $scanner->next();
                 if (!$scanner->get()->isOperator(',')) {
                     break;
                 }
                 $scanner->next();
             }
             if (count($identifiers) > 0) {
                 parent::requireOperator($scanner, ':');
                 $scanner->next();
                 $type = SymType::parseFixed($scanner, $symTable);
                 foreach ($identifiers as $arg) {
                     $symTable->append(new SymArg($arg, $type, $idx));
                     $idx++;
                 }
             }
             if ($scanner->get()->isOperator(')')) {
                 $scanner->next();
                 break;
             }
             parent::semicolonPass($scanner);
         }
     }
     return [$identifier, $symTable];
 }