/* const char STATUS_START[] PROGMEM = "start"; const char STATUS_STOP[] PROGMEM = "stop"; const char STATUS_CFG[] PROGMEM = "cfg"; const char PAREHTHESES[] PROGMEM = "()"; */ void CommandParser::AddComponent(SCommand* pCommand, char key, char* szValue) { switch(key) { case 'n': strncpy(pCommand->name, szValue, sizeof(pCommand->name) - 1); pCommand->name[sizeof(pCommand->name) - 1] = '\0'; break; case 'c': if (strcmp(szValue, "start") == 0) pCommand->command = SCommand::EStart; else if (strcmp(szValue, "stop") == 0) pCommand->command = SCommand::EStop; else if (strcmp(szValue, "cfg") == 0) pCommand->command = SCommand::EConfig; break; case 'l': pCommand->lidTemp = atoi(szValue); break; case 'o': pCommand->contrast = atoi(szValue); case 'd': pCommand->commandId = atoi(szValue); break; case 'p': pCommand->pProgram = ParseProgram(szValue); break; } }
virtual CompileUnit Parse(CompileResult & result, String source, String fileName, IncludeHandler* includeHandler, Dictionary<String,String> const& preprocesorDefinitions) override { auto tokens = PreprocessSource(source, fileName, result.GetErrorWriter(), includeHandler, preprocesorDefinitions); CompileUnit rs; rs.SyntaxNode = ParseProgram(tokens, result.GetErrorWriter(), fileName); return rs; }
Sentencia* Sintactico::ParseS() { Sentencia* stmt = ParseProgram(); if( proximo_token.GetTipo() !=eof ) throw SyntaxException("se esperaba fin de archivo",analizador_lexico->GetLineaActual() ); return stmt; }
PUBLIC int main ( int argc, char *argv[] ) { if ( OpenFiles( argc, argv ) ) { InitCharProcessor( InputFile, ListFile ); CurrentToken = GetToken(); ParseProgram(); fclose( InputFile ); fclose( ListFile ); printf("ok\n"); return EXIT_SUCCESS; } else printf("failed\n"); return EXIT_FAILURE; }
AST* ParseFile(char* filename, IDTable* id_table) { ParserState parser; parser.filename = filename; parser.lex = (LexerState*)malloc(sizeof(LexerState)); StartLexer(parser.lex, filename, id_table); AST* program = ParseProgram(&parser); printf("ID table : \n"); int i; for(i = 0; i < id_table->count; ++i) { printf("%d = %s\n", i, id_table->names[i]); } free(parser.lex); return program; }
/************************************************************************* * Function Name : GetProgramList * Description : get all the programs in a byte array and link them to a list * Parameters : * Returns : **************************************************************************/ static PROGRAM *GetProgramList(unsigned char *pucBuffer, int iProgramSize) { int iReadCounter = 0; PROGRAM *pstPrograms = NULL; PROGRAM *pstTemp = NULL; PROGRAM *pstNew = NULL; while (iReadCounter < iProgramSize) { pstNew = (PROGRAM *)malloc(sizeof(PROGRAM)); ParseProgram(pstNew, pucBuffer); if (pstPrograms == NULL ) { pstPrograms = pstNew; } else { pstTemp->pstNext = pstNew; } pstTemp = pstNew; iReadCounter += 4; pucBuffer += 4; } return pstPrograms; }
void MHEngine::TransitionToScene(const MHObjectRef &target) { int i; if (m_fInTransition) { // TransitionTo is not allowed in OnStartUp or OnCloseDown actions. MHLOG(MHLogWarning, "WARN TransitionTo during transition - ignoring"); return; } if (target.m_GroupId.Size() == 0) { return; // No file name. } QString csPath = GetPathName(target.m_GroupId); // Check that the file exists before we commit to the transition. // This may block if we cannot be sure whether the object is present. QByteArray text; if (! m_Context->GetCarouselData(csPath, text)) { EngineEvent(2); // GroupIDRefError return; } // Parse and run the file. MHGroup *pProgram = ParseProgram(text); if (!pProgram ) MHERROR("Empty scene"); if (pProgram->m_fIsApp) { delete pProgram; MHERROR("Expected a scene"); } // Clear the action queue of anything pending. m_ActionStack.clear(); // At this point we have managed to load the scene. // Deactivate any non-shared ingredients in the application. MHApplication *pApp = CurrentApp(); for (i = pApp->m_Items.Size(); i > 0; i--) { MHIngredient *pItem = pApp->m_Items.GetAt(i - 1); if (! pItem->IsShared()) { pItem->Deactivation(this); // This does not remove them from the display stack. } } m_fInTransition = true; // TransitionTo etc are not allowed. if (pApp->m_pCurrentScene) { pApp->m_pCurrentScene->Deactivation(this); // This may involve a call to RunActions pApp->m_pCurrentScene->Destruction(this); } // Everything that belongs to the previous scene should have been removed from the display stack. // At this point we may have added actions to the queue as a result of synchronous // events during the deactivation. // Remove any events from the asynch event queue unless they derive from // the application itself or a shared ingredient. MHAsynchEvent *pEvent; QQueue<MHAsynchEvent *>::iterator it = m_EventQueue.begin(); while (it != m_EventQueue.end()) { pEvent = *it; if (!pEvent->pEventSource->IsShared()) { delete pEvent; it = m_EventQueue.erase(it); } else { ++it; } } // Can now actually delete the old scene. if (pApp->m_pCurrentScene) { delete(pApp->m_pCurrentScene); pApp->m_pCurrentScene = NULL; } m_Interacting = 0; // Switch to the new scene. CurrentApp()->m_pCurrentScene = static_cast< MHScene* >(pProgram); SetInputRegister(CurrentScene()->m_nEventReg); m_redrawRegion = QRegion(0, 0, CurrentScene()->m_nSceneCoordX, CurrentScene()->m_nSceneCoordY); // Redraw the whole screen if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on. { pProgram->PrintMe(__mhlogStream, 0); } pProgram->Preparation(this); pProgram->Activation(this); m_fInTransition = false; // The transition is complete }
// Launch and Spawn bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn) { if (m_fInTransition) { MHLOG(MHLogWarning, "WARN Launch during transition - ignoring"); return false; } if (target.m_GroupId.Size() == 0) return false; // No file name. QString csPath = GetPathName(target.m_GroupId); // Get path relative to root. // Check that the file exists before we commit to the transition. // This may block if we cannot be sure whether the object is present. QByteArray text; if (! m_Context->GetCarouselData(csPath, text)) { if (!m_fBooting) EngineEvent(2); // GroupIDRefError return false; } MHApplication *pProgram = (MHApplication*)ParseProgram(text); if (! pProgram) { MHLOG(MHLogWarning, "Empty application"); return false; } if (! pProgram->m_fIsApp) { MHLOG(MHLogWarning, "Expected an application"); delete pProgram; return false; } if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on. { pProgram->PrintMe(__mhlogStream, 0); } // Clear the action queue of anything pending. m_ActionStack.clear(); m_fInTransition = true; // Starting a transition try { if (CurrentApp()) { if (fIsSpawn) // Run the CloseDown actions. { AddActions(CurrentApp()->m_CloseDown); RunActions(); } if (CurrentScene()) { CurrentScene()->Destruction(this); } CurrentApp()->Destruction(this); if (!fIsSpawn) { delete m_ApplicationStack.pop(); // Pop and delete the current app. } } // Save the path we use for this app. pProgram->m_Path = csPath; // Record the path int nPos = pProgram->m_Path.lastIndexOf('/'); if (nPos < 0) { pProgram->m_Path = ""; } else { pProgram->m_Path = pProgram->m_Path.left(nPos); } // Have now got the application. m_ApplicationStack.push(pProgram); // This isn't in the standard as far as I can tell but we have to do this because // we may have events referring to the old application. while (!m_EventQueue.isEmpty()) { delete m_EventQueue.dequeue(); } // Activate the application. .... CurrentApp()->Activation(this); m_fInTransition = false; // The transition is complete return true; } catch (...) { m_fInTransition = false; // The transition is complete return false; } }