// 1102 DEVICE ID=(18,0) DI=0x03740038 NAME="sw1102" UMASK=0666 CAPS={MN} { PORT = 7 PW=X1 LS=G25 ID={ 0 }, // PORT = 9 PW=X4 LS=G3125 ID={ 8 }, // PORT = 10 PW=X4 LS=G25 ID={ 16 } // }; DEVICE ID=(0,1) DI=0x04000003 NAME="host" UMASK=0444 CAPS={ MN,MB0, DB,DIO }; DEVICE ID=(8,1) NAME="meter" UMASK=0444 CAPS={ MN,MB0,MB1,MB2,MB3,DB,DIO }; DEVICE ID=(16,1) DI=0x03780038 NAME="sw1101" UMASK=0444 CAPS={ MN } { PORT = 12 PW=X1 LS=G25 ID={ 0, 8, 18 } // , , };
// #include <_> COMPILER SRIO_CONFIG // CHARACTERS letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz". digit = "0123456789". cr = '\r'. lf = '\n'. tab = '\t'. stringch = ANY - '"' - '\\' - cr - lf - tab. hexDigit = "0123456789abcdefABCDEF". printable = '\u0020' .. '\u007e'. TOKENS ident = letter {"_"} { letter | "_" | digit }. number = digit { digit } | "0x" hexDigit {hexDigit}. string = '"' { stringch | "\"\"" } '"' . COMMENTS FROM "/*" TO "*/" NESTED COMMENTS FROM "//" TO lf IGNORE cr + lf + tab PRODUCTIONS // DEVICE<int &iStepDefNo> (. ConfDevice dev; dev.iStepNo=iStepDefNo; .) = "DEVICE" (. dev.iId = 0xFF; dev.iHopCnt=0xFF; .) [ { DEVNAME<dev> | "ID" "=" "(" NUMBER<dev.iId> "," NUMBER<dev.iHopCnt> ")" | "DI" "=" NUMBER<(int &)dev.uDidCar> | DEVCAPS<dev> | "UMASK" "=" NUMBER<(int &)dev.uMask> } ] [ "{" { (. ConfPort cport; .) ASSIGPort<cport> (. dev.lstPorts.Add(cport); .) [","] } "}" ] [ ";" ] (. m_pDevices->Add(dev); .) . // ASSIGPort<ConfPort &pPort> (. int num=-1; .) = "PORT" "=" NUMBER<pPort.nPort> { "PW" "=" PW<pPort.Pw> | "LS" "=" LS<pPort.Ls> | "ID" "=" "{" NUMBER<num> (. pPort.lstIds.Push(num); .) { ',' NUMBER<num> (. pPort.lstIds.Push(num); .) } "}" } . // PW<ePW &pw> (. int iTmp=0; .) = ( "X1" (. pw = PWX1; .) | "X2" (. pw = PWX2; .) | "X4" (. pw = PWX4; .) | "X1L0" (. pw = PWX1L0; .) | "X1L1" (. pw = PWX1L1; .) | "X1L2" (. pw = PWX1L2; .) |NUMBER<iTmp> (. pw=(ePW)iTmp; .) ) . // LS<eLS &ls> (. int iTmp=0; .) = ( "G125" (. ls = LSG125; .) | "G25" (. ls = LSG25; .) | "G3125" (. ls = LSG3125; .) | "G5" (. ls = LSG5; .) | "G625" (. ls = LSG625; .) |NUMBER<iTmp> (. ls=(eLS)iTmp; .) ) . // , STRING<CStr &str> = string (. str=CStr::FromPosLen(t->val, 1, strlen(t->val)-2); .) . // 10- 16- NUMBER<int &value> = number (. value=Utils::ToInt32(t->val); .) . // (, devfs ) DEVNAME<ConfDevice &dev> (. CStr str; .) = "NAME" "=" STRING<str> (. strcpy(dev.szName, (LPCSTR)str); .) . // API DEVCAPS<ConfDevice &dev> (. dev.uCaps = 0; .) = "CAPS" "=" "{" { [','] ( "MN" (. dev.uCaps |= MN; .) |"MB0" (. dev.uCaps |= MB0; .) |"MB1" (. dev.uCaps |= MB1; .) |"MB2" (. dev.uCaps |= MB2; .) |"MB3" (. dev.uCaps |= MB3; .) |"DB" (. dev.uCaps |= DB; .) |"DIO" (. dev.uCaps |= DIO; .) |"ST" (. dev.uCaps |= ST; .) ) } "}" . ////////////////////////////////////////////////////////////// // SRIO_CONFIG = DEVICE<iStepDefNo> { DEVICE<iStepDefNo> } . END SRIO_CONFIG
D:\WRL>cocor cocor –namespace cfg sdrv_conf.atg Coco/R (Nov 17, 2010), changed by APRCPV checking sdrv_conf.atg(1): warning LL1: in DEVICE: contents of [...] or {...} must not be deletable sdrv_conf.atg(1): warning LL1: in BLK_STEPDEF: "DEVICE" is start & successor of deletable structure parser + scanner generated 0 errors detected D:\WRL >
bool ReadConfigFile() { bool bSuc=false; // if (access(m_szConfFileName, 0)!=0) { TRACE(eLL_CRIT, "Error: Configuration file '%s' not found or unaccessable!\n", m_szConfFileName); abort(); } cfg::Scanner &s = *new cfg::Scanner(m_szConfFileName); // cfg::Parser &p = *new cfg::Parser(&s); // p.m_pConfigData = this; // p.Parse(); // // // , : error(row:col) bSuc=(p.errors->count < 1); delete &p; delete &s; // return bSuc; }
Source: https://habr.com/ru/post/328296/
All Articles