Пример #1
0
 public function __construct($identifier, $type)
 {
     parent::__construct();
     $this->identifier = $identifier;
     $this->type = $type;
     $this->CMP_TABLE = [self::$INTEGER => [self::$INTEGER => true, self::$BOOLEAN => false, self::$REAL => true, self::$STRING => false], self::$REAL => [self::$INTEGER => false, self::$REAL => true, self::$BOOLEAN => false, self::$STRING => false], self::$BOOLEAN => [self::$INTEGER => false, self::$REAL => false, self::$BOOLEAN => true, self::$STRING => false], self::$STRING => [self::$INTEGER => false, self::$REAL => false, self::$BOOLEAN => false, self::$STRING => true]];
 }
Пример #2
0
 public function __construct($scanner, $_symTable, $identifier)
 {
     $this->symTable = new SymTable($_symTable);
     $this->identifier = $identifier;
     while ($scanner->get()->isIdentifier()) {
         //variable declaration parse
         $identifier = $scanner->get();
         if (!$scanner->nget()->isOperator(':')) {
             Node::simpleException($scanner, ['<OPERATOR \':\'>']);
         }
         $scanner->next();
         $type = SymType::parse($scanner, $_symTable, null);
         if ($type->isAnonim()) {
             $this->symTable->append($type);
         }
         $this->symTable->append(new SymVar($identifier->getValue(), $type));
         // $scanner->next();
         Node::semicolonPass($scanner);
     }
     if (!$scanner->get()->isKeyword('end')) {
         Node::simpleException($scanner, ['<KEYWORD \'end\'']);
     }
     $scanner->next();
     if ($this->symTable->count() == 0) {
         SemanticException::expected($scanner, ['<VAR DECLARATIONS>']);
     }
 }
Пример #3
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;
     }
 }
Пример #4
0
 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
 protected static function parseSignature($scanner, $_symTable)
 {
     list($identifier, $symTable) = parent::parseSignature($scanner, $_symTable);
     parent::requireOperator($scanner, ':');
     $scanner->next();
     $type = SymType::parseFixed($scanner, $symTable);
     if ($type->isAnonim()) {
         $symTable->append($type);
     }
     $_symTable->append(new SymVar('result', $type));
     return [$identifier, $symTable, $type];
 }
Пример #6
0
 public function __construct($scanner, $_symTable, $identifier)
 {
     $this->identifier = $identifier;
     $scanner->next();
     $token = $scanner->get();
     if ($token->isOperator('[')) {
         $scanner->next();
         while (!$scanner->get()->isOperator(']')) {
             //
             if ($scanner->get()->isIdentifier()) {
                 $symbol = $_symTable->findRecursive($scanner->get()->getValue());
                 if (is_a($symbol, 'vendor\\SemanticParser\\Nodes\\SymSubrangeType')) {
                     $this->dimensions[] = $symbol;
                     $scanner->next();
                 } else {
                     $this->dimensions[] = new SymSubrangeAnonimType($scanner, $_symTable);
                 }
             } else {
                 $this->dimensions[] = new SymSubrangeAnonimType($scanner, $_symTable);
             }
             if ($scanner->get()->isOperator(',')) {
                 $scanner->next();
                 continue;
             } else {
                 if (!$scanner->get()->isOperator(']')) {
                     SemanticException::expected($scanner, ['<OPERATOR \',\'>', '<OPERATOR \']\'>']);
                 }
             }
         }
         if (count($this->dimensions) < 1) {
             SemanticException::raw($scanner, 'Found array with no dimensions!');
         }
         $token = $scanner->nget();
     }
     if (!$token->isKeyword('of')) {
         SemanticException::expected($scanner, ['<KEYWORD \'of\'>']);
     }
     $scanner->next();
     $this->type = SymType::parse($scanner, $_symTable, null);
     // $scanner->next();
 }
Пример #7
0
 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];
 }