/* records */ static void parseKeywords (tokenInfo * const token, boolean local) { switch (token->keyword) { case KEYWORD_END: fileSkipToCharacter (';'); break; case KEYWORD_CONSTANT: parseConstant (local); break; case KEYWORD_TYPE: parseTypes (token); break; case KEYWORD_SUBTYPE: parseTypes (token); break; case KEYWORD_ENTITY: parseModule (token); break; case KEYWORD_COMPONENT: parseModule (token); break; case KEYWORD_FUNCTION: parseSubProgram (token); break; case KEYWORD_PROCEDURE: parseSubProgram (token); break; case KEYWORD_PACKAGE: parsePackage (token); break; default: break; } }
void GPUProgram::BindingTable::parse(const std::string& code) { bindingArray.resize(0); TextInput ti(TextInput::FROM_STRING, code); while (ti.hasMore()) { Token t = ti.read(); // Scan for "#" while (! symbolMatch(t, "#") && ti.hasMore()) { t = ti.read(); } if (ti.hasMore()) { // Read the comment line Token t = ti.peek(); if (t.type() == Token::SYMBOL) { ti.readSymbol(); if (t.string() == "var") { parseVariable(ti); } else if (t.string() == "const") { parseConstant(ti); } } } } }
//----------------------------------------------------------------------------- // Function: IPXactValueParser::parseExpression() //----------------------------------------------------------------------------- QString IPXactValueParser::parseExpression(QString const& expression) const { QString format = getFormatForExpression(expression); if ((format == "bool" || format == "string" || format.isEmpty()) && isValidExpression(expression, format)) { return expression; } return QString::number(parseConstant(expression, format)); }
//lead into the program void Parser::parseBlock() { ++it; switch (it->tag) { case CONSTANT: parseConstant(); parseBlock(); break; case VAR: parseVariables(); parseBlock(); break; case TYPE: parseType(); parseBlock(); break; case FUNCTION: parseFunction(); parseBlock(); break; case PROCEDURE: parseProcedure(); parseBlock(); break; case BEGIN: { shared_ptr<Statement> block = parseStmtList(currNode == root ? FINISH : END); //root的block与函数的block if (currNode != root) { (static_pointer_cast<FunctionStmt>(currNode))->body=block; } else { block->value.value = "__Main__"; currNode->addNode(block); } bool tmp=it->tag == FINISH || it->tag == END; if (it->tag == END) { it++; match(SEMI); } } break; } }
static void enterScope (tokenInfo *const parentToken, const vString *const extraScope, const int parentKind) { tokenInfo *token = newToken (); int origParentKind = parentToken->parentKind; copyToken (token, parentToken, TRUE); if (extraScope) { token->parentKind = parentKind; addToScope (token, extraScope, origParentKind); } readToken (token); while (token->type != TOKEN_EOF && token->type != TOKEN_CLOSE_CURLY) { boolean readNext = TRUE; switch (token->type) { case TOKEN_OPEN_CURLY: enterScope (token, NULL, -1); break; case TOKEN_KEYWORD: switch (token->keyword) { /* handle anonymous classes */ case KEYWORD_new: readToken (token); if (token->keyword != KEYWORD_class) readNext = FALSE; else { char buf[32]; tokenInfo *name = newToken (); copyToken (name, token, TRUE); snprintf (buf, sizeof buf, "AnonymousClass%u", ++AnonymousID); vStringCopyS (name->string, buf); readNext = parseClassOrIface (token, K_CLASS, name); deleteToken (name); } break; case KEYWORD_class: readNext = parseClassOrIface (token, K_CLASS, NULL); break; case KEYWORD_interface: readNext = parseClassOrIface (token, K_INTERFACE, NULL); break; case KEYWORD_trait: readNext = parseTrait (token); break; case KEYWORD_function: readNext = parseFunction (token, NULL); break; case KEYWORD_const: readNext = parseConstant (token); break; case KEYWORD_define: readNext = parseDefine (token); break; case KEYWORD_namespace: readNext = parseNamespace (token); break; case KEYWORD_private: CurrentStatement.access = ACCESS_PRIVATE; break; case KEYWORD_protected: CurrentStatement.access = ACCESS_PROTECTED; break; case KEYWORD_public: CurrentStatement.access = ACCESS_PUBLIC; break; case KEYWORD_var: CurrentStatement.access = ACCESS_PUBLIC; break; case KEYWORD_abstract: CurrentStatement.impl = IMPL_ABSTRACT; break; default: break; } break; case TOKEN_VARIABLE: readNext = parseVariable (token); break; default: break; } if (readNext) readToken (token); } copyToken (parentToken, token, FALSE); parentToken->parentKind = origParentKind; deleteToken (token); }