// [muster_file.cpp] pattern: parsing from a file /* This is only a pattern how to parse from a file. For a concrete example you have to substitute the text within <>. */ // necessary includes #include "stdosx.h" // base header STYX library #include "scn_base.h" // scanner #include "ptm_gen.h" // parse & term construction #include "symbols.h" // symbol table #include "hmap.h" // hash maps #include "_lim.h" // scanner table #include "_pim.h" // parser table #include "_int.h" // language interface static void parse_and_eval(c_string szPath) // parse & eval file { Scn_T pScn; // scan table Scn_Stream pCstream; // scan stream PLR_Tab pPlr; // parse table PT_Cfg pPCfg; // parse configuration PT_Term pTree; // parse result: derivation tree or NULL Scn_get_(&pScn); // create scan table pPlr = PLR_get_(); // create parse table pCstream = Stream_file(pScn,"",szPath,""); // create scanner from 'szPath' /* you can split the path into the following components pCstream = Stream_file(pScn,,,); */ pPCfg = PT_init(pPlr,pCstream); // create parse configuration pTree = PT_PARSE(pPCfg,""); // parse from first start nonterminal // initializes error count with syntax error count PT_setErrorCnt(PT_synErrorCnt(pPCfg)); // no errors --> eval derivation tree if( PT_errorCnt() == 0 ) { pStart; // start nonterminal tree node pChild1; // first child node // ... pChildN; // last child node // extract start nonterminal tree node assert0( _Start_(pTree,&pStart), ""); // end command --> stop process if( _ (pStart,&pChild1, ..., &pChildN) ) { // further evaluation ... } } if( pTree != NULL ) PT_delT(pTree); // release derivation tree PT_quit(pPCfg); // release parse configuration Stream_close(pCstream); // close scan stream Stream_free(pCstream); // release scan stream Scn_free(pScn); // release scan table PLR_delTab(pPlr); // release parse table } int main(int argc, char* argv[]) { // modul initialisation for hash maps and symbols MAP_init(); initSymbols(); // init language symbols _initSymbols(); // parse and evaluate file parse_and_eval(argv[0]); // release language symbols _quitSymbols(); // modul termination for hash maps and symbols freeSymbols(); MAP_quit(); BUG_CORE; return 0; }