Example #1
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>']);
     }
 }
Example #2
0
 public static function parseFixed($scanner, $_symTable)
 {
     if ($scanner->get()->isIdentifier()) {
         $aliased = $_symTable->findRecursive($scanner->get()->getValue());
         if (is_a($aliased, 'vendor\\SemanticParser\\Nodes\\SymType')) {
             $scanner->next();
             return $aliased;
         }
         SemanticException::expected($scanner, ['<TYPE IDENTIFIER>']);
     } else {
         if ($scanner->get()->isOperator('^')) {
             return new SymPointerAnonimType($scanner, $_symTable);
         } else {
             if ($scanner->get()->isKeyword('array')) {
                 $type = new SymArrayAnonimType($scanner, $_symTable);
                 if (!$type->isDynamic()) {
                     SemanticException::expected($scanner, ['<FIXED TYPE>']);
                 }
                 return $type;
             } else {
                 SemanticException::expected($scanner, ['<TYPE>']);
             }
         }
     }
 }
Example #3
0
 public function __construct($scanner, $_symTable, $identifier)
 {
     $this->identifier = $identifier;
     $type = $scanner->nget();
     if (!$type->isIdentifier()) {
         Node::simpleException($scanner, ['<TYPE IDENTIFIER>']);
     }
     $type = $_symTable->findRecursive($type->getValue());
     if ($type == null || !is_a($type, 'vendor\\SemanticParser\\Nodes\\SymType')) {
         SemanticException::expected($scanner, ['<TYPE IDENTIFIER>']);
     }
     $this->type = $type;
     $scanner->next();
 }
Example #4
0
 private static function getRangeValue($scanner, $_symTable)
 {
     $token = $scanner->get();
     if (!$token->isInteger() && !$token->isIdentifier()) {
         Node::simpleException($scanner, ['<UNSIGNED NUMBER CONST>']);
     }
     if ($token->isIdentifier()) {
         $symbol = $_symTable->findRecursive($token->getValue());
         if (!is_a($symbol, 'vendor\\SemanticParser\\Nodes\\SymConst')) {
             SemanticException::expected($scanner, ['<CONST IDENTIFIER>']);
         }
         $value = $symbol->value;
         if (!is_int($value)) {
             SemanticException::expected($scanner, ['<INT CONST IDENTIFIER>']);
         }
         return $value;
     } else {
         return $token->getValue();
     }
 }
Example #5
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();
 }