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(); }
public function __construct($scanner, $_symTable) { $args = new SymTable($_symTable); if (!$scanner->get()->isIdentifier()) { parent::simpleException($scanner, ['<IDENTIFIER>']); } $this->identifier = $scanner->get()->getValue(); $scanner->next(); if (!$scanner->get()->isOperator('(')) { parent::simpleException($scanner, ['<OPERATOR \'(\'>']); } while (!$scanner->get()->isOperator(')')) { $identifiers = []; while ($scanner->get()->isIdentifier()) { $identifiers[] = $scanner->get()->getValue(); $scanner->next(); if (!$scanner->get()->isOperator(',')) { break; } $scanner->next(); } if (!$scanner->get()->isOperator(':')) { parent::simpleException($scanner, ['<OPERATOR \':\'>']); } $scanner->next(); $type = SymType::parseExisting($scanner, $args); foreach ($identifiers as $identifier) { $args->append(new SymVar($identifier, $type)); } parent::semicolonPass($scanner); } $this->symbol = new SymProc($this->identifier->getValue(), $args); $_symTable->append($this->symbol); $scanner->next(); }
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) { while ($scanner->get()->isKeyword('procedure') || $scanner->get()->isKeyword('function')) { array_push($this->fps, $scanner->get()->isKeyword('procedure') ? Proc::smartParse($scanner, $_symTable) : Func::smartParse($scanner, $_symTable)); parent::semicolonPass($scanner); } if (empty($this->fps)) { parent::simpleException($scanner, ['<IDENTIFIER>']); } }
public function __construct($scanner, $_symTable) { $this->statements = []; parent::requireKeyword($scanner, 'begin'); $scanner->next(); while (!$scanner->get()->isKeyword('end')) { $this->statements[] = new Statement($scanner, $_symTable); parent::semicolonPass($scanner); } $scanner->next(); }
public function __construct($scanner, $_symTable) { $decs = []; while ($scanner->get()->isIdentifier()) { array_push($this->varDecs, new VarDec($scanner, $_symTable)); parent::semicolonPass($scanner); } if (empty($this->varDecs)) { parent::simpleException($scanner, ['<IDENTIFIER>']); } }
public function __construct($scanner, $_symTable) { $finalKeyWords = ['var', 'function', 'procedure', 'begin']; $defs = []; while ($scanner->get()->isIdentifier()) { array_push($defs, new TypeDef($scanner, $_symTable)); parent::semicolonPass($scanner); } if (empty($defs)) { parent::simpleException($scanner, ['<IDENTIFIER>']); } }
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>']); } }
public static function smartParse($scanner, $_symTable) { $scanner->next(); list($identifier, $symTable) = self::parseSignature($scanner, $_symTable); parent::semicolonPass($scanner); $symbol = new SymProc($identifier, $symTable, null); $proc = new Proc(null, $symbol); $proc->symbol->node = $proc; if ($scanner->get()->isKeyword('forward')) { $_symTable->appendForwardable($proc->symbol); $scanner->next(); return $proc; } $proc->block = new Block($scanner, $symTable); $_symTable->appendForwardable($proc->symbol); return $proc; }