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