//**// void statementlists(){ if (lookahead == IF){ //分支语句 switchStatement(); } else if (lookahead == id){ //赋值语句 assignment(); } else if (lookahead == WHILE){ //while语句 loopStatement(); } else if (lookahead == input){ //输入语句 inputStatement(); } else if (lookahead == output){ //输出 outputStatement(); } else if (lookahead == call){ //函数调用 functioncall(); } else if (lookahead == var){ //变量定义 varDefinition(); } else if (lookahead == begin){ //复合语句 complexStatementlists(); } }
AST* Parser::statement(Scope* ps) { AST* ret = NULL; if (expect(";")) { ret = emptyStatement(); } else if (expect("var")) { ret = varStatement(ps); opteol(); } else if (expect("{")) { ret = block(ps); opteol(); } else if (expect("if")) { ret = ifStatement(ps); } else if (expect("switch")) { ret = switchStatement(ps); } else if (expect("do")) { ret = doStatement(ps); opteol(); } else if (expect("while")) { ret = whileStatement(ps); } else if (expect("for")) { ret = forStatement(ps); } else if (expect("with")) { ret = withStatement(ps); } else if (expect("continue")) { ret = continueStatement(); opteol(); } else if (expect("break")) { ret = breakStatement(); opteol(); } else if (expect("return")) { ret = returnStatement(ps); opteol(); } else if (expect("try")) { ret = tryStatement(ps); } else if (expect("throw")) { ret = throwStatement(ps); opteol(); } else { ret = expression(0, ps); opteol(); } return ret; }
void statement (void) { //------------------------------------------------------------------- // NOTE: Since we currently don't support generic BEGIN/END (compound // statement) blocks... if ((curToken != TKN_CODE) /*&& (curToken != TKN_BEGIN)*/) crunchStatementMarker(); switch (curToken) { case TKN_IDENTIFIER: { SymTableNodePtr IdPtr = NULL; //-------------------------------------------------------------- // First, do we have an assignment statement or a function call? searchAndFindAllSymTables(IdPtr); if ((IdPtr->defn.key == DFN_FUNCTION)/* || (IdPtr->defn.key == DFN_MODULE)*/) { RoutineKey key = IdPtr->defn.info.routine.key; if ((key == RTN_ASSERT) || (key == RTN_PRINT) || (key == RTN_CONCAT)) { bool uncrunch = ((key == RTN_ASSERT) && !AssertEnabled) || ((key == RTN_PRINT) && !PrintEnabled) || ((key == RTN_CONCAT) && !StringFunctionsEnabled); if (uncrunch) { uncrunchStatementMarker(); Crunch = false; } } crunchSymTableNodePtr(IdPtr); if (IdPtr->defn.info.routine.flags & ROUTINE_FLAG_ORDER) { if (NumOrderCalls == MAX_ORDERS) syntaxError(ABL_ERR_SYNTAX_TOO_MANY_ORDERS); crunchByte((unsigned char)(NumOrderCalls / 32)); crunchByte((unsigned char)(NumOrderCalls % 32)); NumOrderCalls++; } getToken(); SymTableNodePtr thisRoutineIdPtr = CurRoutineIdPtr; routineCall(IdPtr, 1); CurRoutineIdPtr = thisRoutineIdPtr; Crunch = true; } else assignmentStatement(IdPtr); } break; case TKN_REPEAT: repeatStatement(); break; case TKN_WHILE: whileStatement(); break; case TKN_IF: ifStatement(); break; case TKN_FOR: forStatement(); break; case TKN_SWITCH: switchStatement(); break; case TKN_TRANS: transStatement(); break; case TKN_TRANS_BACK: transBackStatement(); break; } //--------------------------------------------------------------------- // Now, make sure the statement is closed off with the proper block end // statement, if necessary (which is usually the case :). synchronize(statementEndList, NULL, NULL); if (tokenIn(statementStartList)) syntaxError(ABL_ERR_SYNTAX_MISSING_SEMICOLON); }
void GAME() { system("clear"); srand(time(NULL)); int randomDigit = rand() % 11; const char *country[10]; country[0] = "canada"; country[1] = "america"; country[2] = "russia"; country[3] = "china"; country[4] = "germany"; country[5] = "italy"; country[6] = "greece"; country[7] = "jamaica"; country[8] = "egypt"; country[9] = "iran"; country[10] = "turkey"; MISS.MISS = 0; MISS.i = 0; MISS.countInput = 1; INPUT: printf("\n\tGAMES BASED ON COUNTRY NAMES, You'll be figuring out the country NAME!\n"); printf("\n\tCLUE:\n"); switch(randomDigit) { case 0: printf("\n\tI am a country located NORTH of America!!!\n"); break; case 1: printf("\n\tI am a country with 50 STATES!!!\n"); break; case 2: printf("\n\tI am the WORLDS largest nation on the MAP!!!\n"); break; case 3: printf("\n\tI am the highest counterfeit production in the WORLD!!!\n"); break; case 4: printf("\n\tI own BMW and Mercedes BENZ!!!\n"); break; case 5: printf("\n\tI am known for PIZZA and PASTA!!!\n"); break; case 6: printf("\n\tI was the place to hold the FIRST Olympic Games!!!\n"); break; case 7: printf("\n\tI am the NATION from where Usain Bolt hails from!!!\n"); break; case 8: printf("\n\tI am the Arabian country with Pyramids!!!\n"); break; case 9: printf("\n\tI am the Nation at odds with Israel and U.S over"); printf("\n\tNuclear Power!!!\n"); break; case 10: printf("\n\tI am a country with a city which lies on Two"); printf("\n\tContinents, European and Asian Continents!!!\n"); break; default: break; } int num1 = strlen(country[randomDigit]); printf("\n\t**s a %d character word\n", num1); int x; printf("\n\tTYPE ONE LETTER HERE (lower-case ONLY) >> "); const char *character = country[randomDigit]; while (scanf("%1[\n]", &MISS.word[MISS.i]) == 0) { scanf("%c", &MISS.word[MISS.i]); strncpy(&MISS.words[MISS.i], &MISS.word[MISS.i], MISS.countInput); for(x=0;x<num1;x++) { if(MISS.word[MISS.i] == character[x]) { MISS.MISS--; } } for(x=0;x<MISS.countInput;x++) { MISS.match = strspn(&character[x], &MISS.words[x]); if(MISS.match == num1) { system("clear"); printf("\n\n\t###########################################"); printf("\n\t###########################################"); printf("\n\t## ##"); printf("\n\t## ## ## ########## ## ## ##"); printf("\n\t## ## ## ########## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ##"); printf("\n\t## #### ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ##"); printf("\n\t## ## ########## ######### ##"); printf("\n\t## ## ########## ######### ##"); printf("\n\t## ##"); printf("\n\t## ## ## ########## #### ## ##"); printf("\n\t## ## ## ########## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ## ##"); printf("\n\t## ########## ########## ## ## ## ##"); printf("\n\t## ########## ########## ## #### ##"); printf("\n\t## ##"); printf("\n\t###########################################"); printf("\n\t###########################################\n"); exit(0); } } } MISS.MISS++; switchStatement(); MISS.i++; goto INPUT; }