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>']); } }
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>']); } } } }
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(); }
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(); } }
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(); }