KFormula* KFormula::parseIMP(const char*& str) { KFormula* left = parseOR(str); while(isspace(*str)) ++str; if(strncmp(str,"=>",2) == 0) { // This is an implication str += 2; KFormula* right = parseIMP(str); return new KFormula(KFormula::IMP,left,right); } else { return left; // This is not an implication } }
KFormula* KFormula::parseEQU(const char*& str) { KFormula* left = parseIMP(str); while(isspace(*str)) ++str; if(strncmp(str,"<=>",3) == 0) { // This is an equivalence str += 3; KFormula* right = parseEQU(str); return new KFormula(KFormula::EQU,left,right); } else { return left; // This is not an equivalence } }
void Parser::parseIMP(void) { if (tkp >= (tok.size())) return; if (!accept(tok[tkp])){ error("IMP: Unexpected char at: ", tkp); tkp++; return; } if (tok[tkp] == 'A'){ tkp++; stackIMP(); } else if (tok[tkp] == 'B'){ if (tok[tkp + 1] == 'A'){ tkp += 2; arithIMP(); } else if (tok[tkp + 1] == 'B'){ tkp += 2; heapIMP(); } else if (tok[tkp + 1] == 'C'){ tkp += 2; ioIMP(); } } else if (tok[tkp] == 'C'){ tkp++; flowIMP(); } else { error("IMP parse error at: ", tkp); tkp++; return; } push("\n"); parseIMP(); }
void Parser::parse(void) { parseIMP(); end(); }