/* * $Id$ */ //******************************************************************* // hparser2.prg: Hessmark parser(2): a '#'-al kezd“d“ sorok elemz‚se. // 1999, Csisz r Levente //******************************************************************* #include "objgen.ch" //******************************************************************* #define _STRICT_PARENT_ #include "token.och" //#include "mmarker.och" //#include "rmarker.och" //#include "maltrset.och" //#include "rsmmarkr.och" //#include "ralter.och" #include "edefdict.och" #include "defdict.och" //#include "extrdict.och" //#include "xtrdict.och" // #include "freader.och" //#include "incl.och" //#include "prserr.och" //******************************************************************* // #include "cr_lf.ch" #include "ctoken.ch" // #include "prserr.ch" //******************************************************************* #include "hparser.ch" //******************************************************************* #include "reader.och" #include "treader.och" #include "hparser.och" //******************************************************************* #xtranslate this: => HPARSER.(this): //******************************************************************* function hpr_prsDefine(this,mNameToken) // A # define elemz“je. local state,tkId,tkStr local name,params local ujsor #ifdef ID_STRING #define ST_D_START "start" #define ST_D_TORZS "torzs" #define ST_D_PARAM_VAGY_TORZS "param_vagy_torzs" #define ST_D_TORZS_START "torzs_start" #define ST_D_PARAM_START "param_start" #define ST_D_PARAM_NEVUTAN "param_nevutan" #define ST_D_PARAM_VESSZOUTAN "param_vesszoutan" #else #define ST_D_START 1 #define ST_D_TORZS 2 #define ST_D_PARAM_VAGY_TORZS 3 #define ST_D_TORZS_START 4 #define ST_D_PARAM_START 5 #define ST_D_PARAM_NEVUTAN 6 #define ST_D_PARAM_VESSZOUTAN 7 #endif state:=ST_D_START this:rds() while(this:item!=nil) tkId:=TOKEN.(this:item):id tkStr:=TOKEN.(this:item):str ujsor:=tkId==TKID_UJSOR .or.; tkId==TKID_BOS .or. tkId==TKID_EOS if (state==ST_D_START) if (ujsor) // Hib s ‚s v‚ge is van. this:errorgen(mNameToken,HPRERR_SDEFINE) exit elseif (tkId==TKID_URES) // Eldobjuk. state:=ST_D_START elseif (tkId==TKID_NEV) // Ez a neve name:=tkStr state:=ST_D_PARAM_VAGY_TORZS else // Hib s. this:errorgen(this:item,HPRERR_SDEFINE) exit endif elseif (state==ST_D_PARAM_VAGY_TORZS) if (ujsor) // A definĄci˘ res. this:unrds() this:clearParserbuffer() this:addDefine(mNameToken,name,params) // this:putParserBuffer(this:item) exit elseif (tkId==TKID_URES) // tmegynk a t”rzsh”z. this:clearParserbuffer() state:=ST_D_TORZS_START elseif (tkId==TKID_CHAR .and. tkStr=="(") // A param‚terek. state:=ST_D_PARAM_START else // A t”rzs. this:clearParserBuffer() this:putParserBuffer(this:item) state:=ST_D_TORZS endif elseif (state==ST_D_PARAM_START) // '(' ut n. N‚v vagy ')' j”het. params:={} if (tkId==TKID_URES) // Eldobjuk. elseif (tkId==TKID_CHAR .and. tkStr==")") // Kezd“dik a t”rzs. this:clearParserbuffer() state:=ST_D_TORZS_START elseif (tkId==TKID_NEV) // Param‚ter. aadd(params,tkStr) state:=ST_D_PARAM_NEVUTAN else // B rmi m s, az nem j˘! Ebben benne van az Łj sor is! // Hib s ‚s v‚ge is van. this:errorgen(mNameToken,HPRERR_LDEFINE) exit endif elseif (state==ST_D_PARAM_NEVUTAN) // Param‚terlist ban egy n‚v ut n. // ',' vagy ')' j”het. if (tkId==TKID_URES) // Eldobjuk. elseif (tkId==TKID_CHAR .and. tkStr==")") // Kezd“dik a t”rzs. // šres param‚ter lista. this:clearParserBuffer() state:=ST_D_TORZS_START elseif (tkId==TKID_CHAR .and. tkStr==",") // Kezd“dik a k”vetkez“ param‚ter. state:=ST_D_PARAM_VESSZOUTAN else // B rmi m s, az nem j˘! Ebben benne van az Łj sor is! // Hib s ‚s v‚ge is van. this:errorgen(mNameToken,HPRERR_PDEFINE) exit endif elseif (state==ST_D_PARAM_VESSZOUTAN) // ',' ut n. Csak n‚v j”het. if (tkId==TKID_URES) // Eldobjuk. elseif (tkId==TKID_NEV) // Param‚ter. aadd(params,tkStr) state:=ST_D_PARAM_NEVUTAN else // B rmi m s, az nem j˘! Ebben benne van az Łj sor is! // Hib s ‚s v‚ge is van. this:errorgen(mNameToken,HPRERR_PDEFINE) exit endif elseif (state==ST_D_TORZS_START) // Az reseket lenyeljk. if (tkId==TKID_URES) // Eldobjuk. this:unputParserBuffer() elseif (tkId==TKID_UJSOR .or.; tkId==TKID_BOS .or. tkId==TKID_EOS) // V‚ge a definici˘nak. this:unrds() this:addDefine(mNameToken,name,params) exit else // B rmi m s, indul a t”rzs. state:=ST_D_TORZS endif elseif (state==ST_D_TORZS) if (tkId==TKID_UJSOR .or.; tkId==TKID_BOS .or. tkId==TKID_EOS) // V‚ge a definici˘nak. this:unrds() this:addDefine(mNameToken,name,params) exit else // B rmi m s a t”rzs folytat˘dik. endif else ? "HPARSER:parseDefine(): Ismeretlen  llapot: ",state errorlevel(1) quit endif this:rds() end while this:sorNyel() return nil //******************************************************************* function hpr_prsUndef(this,mnameToken) // A # undef elemz“je. local state #ifdef ID_STRING #define ST_UD_START "start" #define ST_UD_VEGE "vege" #else #define ST_UD_START 1 #define ST_UD_VEGE 2 #endif local tkId,tkStr local name local ujsor state:=ST_UD_START this:rds() while(this:item!=nil) tkId:=TOKEN.(this:item):id tkStr:=TOKEN.(this:item):str ujsor:=tkId==TKID_UJSOR .or.; tkId==TKID_BOS .or. tkId==TKID_EOS if (state==ST_UD_START) if (ujsor) // Hib s ‚s v‚ge is van. this:errorgen(mnameToken,HPRERR_SUNDEF) exit elseif (tkId==TKID_URES) // Maradunk. elseif (tkId==TKID_NEV) // Ez a neve name:=tkStr state:=ST_UD_VEGE else // Hib s. this:errorgen(mnameToken,HPRERR_SUNDEF) exit endif elseif (state==ST_UD_VEGE) if (ujsor) // K‚sz vagyunk. this:unrds() this:clearParserbuffer() // Nem kell hib t jelezni, ha nincs. DEFDICT.(this:defdict):delKey(name) exit elseif (tkId==TKID_URES) // Maradunk. else // Hib s this:errorgen(this:item,HPRERR_SUNDEF) exit endif else ? "HPARSER:parseUndef(): Ismeretlen  llapot: ",state errorlevel(1) quit endif this:rds() end while this:sorNyel() return nil //******************************************************************* function hpr_addDefine(this,mnameToken,name,params) // A t”rzs a parserBuffer-ben van. // Az mNameToken jelzi, hogy hol volt a definĄci˘. local w,prev,errStr w:=C.EDEFDICT:onew(name,params,; this:arrayParserBuffer(),; TOKEN.mnameToken:file,; TOKEN.mnameToken:line,; TOKEN.mnameToken:pos) this:clearParserBuffer() if (nil!=(prev:=DEFDICT.(this:defdict):add(w))) // M r van ilyen makr˘ errStr:="Previous: "+; EDEFDICT.prev:deffilelinepos[1]+"("+; toStr(EDEFDICT.prev:deffilelinepos[2])+")" this:errorGen(mnameToken,HPRERR_MDUPLICATE,{name,errStr}) endif return nil //******************************************************************* function hpr_prsIfdef(this,mnameToken,ifdefType) // A #ifdef/#ifndef elemz“je. local state #ifdef ID_STRING #define ST_FD_START "start" #define ST_FD_VEGE "vege" #else #define ST_FD_START 1 #define ST_FD_VEGE 2 #endif local tkId,tkStr local name local ujsor local megvan state:=ST_FD_START this:rds() while(this:item!=nil) tkId:=TOKEN.(this:item):id tkStr:=TOKEN.(this:item):str ujsor:=tkId==TKID_UJSOR .or.; tkId==TKID_BOS .or. tkId==TKID_EOS if (state==ST_FD_START) if (ujsor) // Hib s ‚s v‚ge is van. this:errorgen(mnameToken,HPRERR_IFDEFNL) exit elseif (tkId==TKID_URES) // Maradunk. elseif (tkId==TKID_NEV) // Ez a neve name:=tkStr state:=ST_FD_VEGE else // Hib s. this:errorgen(this:item,HPRERR_SIFDEF) exit endif elseif (state==ST_FD_VEGE) if (ujsor) // K‚sz vagyunk. this:unrds() this:clearParserbuffer() if (ifdefType==IFDEFTYPE_NONE) // Hamis  gban lev“ if. this:branch:=nil aadd(this:ifStack,{IFB_NONEBRANCH,this:branch}) this:sorNyel() else megvan:=DEFDICT.(this:defdict):atKey(name) this:branch:=if(ifdefType==IFDEFTYPE_IFDEF,megvan!=nil,megvan==nil) aadd(this:ifStack,{IFB_IFBRANCH,this:branch}) endif exit elseif (tkId==TKID_URES) // Maradunk. else // Hib s this:errorgen(this:item,HPRERR_SIFDEF) exit endif else ? "HPARSER:parseIfdef(): Ismeretlen  llapot: ",state errorlevel(1) quit endif this:rds() end while this:sorNyel() return nil //******************************************************************* function hpr_prsElse(this,mnameToken) // A #else elemz“je. local w if (len(this:ifStack)<=0) // Hiba, nincs hozz  if. this:errorgen(this:item,HPRERR_ELSE) // Nincs hozz  if elseif (this:branch!=nil) w:=atail(this:ifStack) // A spec-ben t”bb else is lehet, ilyenkor csak megfordĄtja a // felt‚telt. if (w[1]==IFB_IFBRANCH) w[1]:=IFB_ELSEBRANCH else // Duplik lt else, A spec-ben ez nem hiba! this:incompErrorgen(this:item,HPRERR_ELSE2) // Duplik lt else endif this:branch:=w[2]:=!w[2] endif this:sorNyel() return nil //******************************************************************* function hpr_prsEndif(this,mnameToken) // A #endif elemz“je. local w if (len(this:ifStack)<=0) // Hiba, nincs hozz  if. this:errorgen(this:item,HPRERR_ENDIF) // Nincs hozz  if else adrop(this:ifStack) if (len(this:ifStack)<=0) this:branch:=.t. else w:=atail(this:ifStack) this:branch:=w[2] endif endif this:sorNyel() return nil //*******************************************************************