sptr<ExpListNode> Parser::ParseExpList() { sptr<ExpListNode> root(new ExpListNode(ParseExp(), "Arguments")); while(Match(COMMA, -1)) { NextToken(); sptr<ExprNode> expr; if (expr = ParseExp()) root->PushChild(expr); } return root; }
sptr<Node> Parser::ParseForLoop() { sptr<StmntNode> root(new StmntNode(currToken)); NextToken(); root->PushChild(ParseIdent()); Expect(ASSIGN, -1); root->PushChild(ParseExp()); root->PushChild(sptr<KeywordNode>(new KeywordNode(currToken))); Expect(TO, DOWNTO, -1); root->PushChild(ParseExp()); Expect(DO, -1); root->PushChild(ParseStatement()); return root; }
Local WORD FindWP(char *expression) { WORD i, undef; ULONG value, value2; value = ParseExp(expression, &undef, strlen(expression)); if (undef) return FALSE; for (i=0; i<MAXWP; i++) { if (wpTable[i].type != WP_UNSET) { if (!strcmp(expression, wpTable[i].expression)) return i; value2 = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression)); if (value == value2) return i; } } return -1; }
BOOL RXGetLine(char *args) { ULONG addr, line = 0; long info[2]; // info[0] == lineBeg, info[1] == lineNo WORD type, i; short undef = TRUE; if(*args) { addr = ParseExp(args, &undef, strlen(args)); } if(undef)addr = programPC; type = CurrentMixedLine(&addr, &line, info); if(type == MIXTYPE_SOURCE) { char *lineStr = (char *)info[0]; for (i = 0; lineStr[i] && lineStr[i] != '\n'; ++i) ; sprintf(RexxReplyString,"%6d. ", info[1]); strncat(RexxReplyString, lineStr, i); } else { sprintf(RexxReplyString,"%08X",addr); strcat(RexxReplyString," "); i=strlen(RexxReplyString); Disassemble(addr, addr, &RexxReplyString[i]); } return TRUE; }
void Material::ParseExp(MaterialExpression* inputexp,JsonObject& obj) { JsonObject::MemberIterator first_mem = obj.MemberBegin(); s32 input_index = 0; while(first_mem!=obj.MemberEnd()) { if (first_mem->value.IsObject()) { MaterialExpMap::iterator it = exp_map_.find(first_mem->name.GetString()); if (it!=exp_map_.end()) { MaterialExpression* exp =(*it).second; MaterialInput* input = inputexp->GetInput(input_index); if (input) { input->input_mask_ = ParseMask(first_mem->value); input->link_= exp; } input_index++; ParseExp(exp,first_mem->value); } } first_mem++; } }
sptr<Node> Parser::ParseAssign(sptr<VarNode> ident) { sptr<AssignNode> root(new AssignNode(ParseVar(ident), currToken)); Expect(ASSIGN, -1); root->PushChild(ParseExp()); return root; }
bool cVarParser::ParseEquality(const string& input) { int condEqPos = input.find("=="); int condNeqPos = input.find("!="); int condOpPos = -1; if (condEqPos >= 0) condOpPos = condEqPos; if (condNeqPos >= 0) condOpPos = condNeqPos; if (condOpPos == -1) return false; string left(input.begin(), input.begin() + condOpPos); string right(input.begin() + condOpPos + 2, input.end()); if (ParseExp(left) && ParseExp(right)) { condEqLeft = Strip(left); condEqRight = Strip(right); return true; } return false; }
sptr<Node> Parser::ParseRepeatUntil() { sptr<StmntNode> root(new StmntNode(currToken)); NextToken(); root->PushChild(ParseBlock(0)); Expect(UNTIL, -1); root->PushChild(ParseExp()); return root; }
sptr<Node> Parser::ParseWhileLoop() { sptr<StmntNode> root(new StmntNode(currToken)); NextToken(); root->PushChild(ParseExp()); Expect(DO, -1); root->PushChild(ParseStatement()); return root; }
TPlVal TPlBs::ParseTup(TILx& Lx, const TFSet& Expect, const PPlBs& PlBs){ IAssert(TupExpect.In(Lx.Sym)); int FuncId=PlBs->AtomH.AddKey(Lx.Str); TPlValV ValV; Lx.GetSym(syLParen); Lx.GetSym(ExpExpect); TPlVal Val=ParseExp(Lx, TFSet()|syComma|syRParen, PlBs); ValV.Add(Val); while (Lx.Sym==syComma){ Lx.GetSym(ExpExpect); Val=ParseExp(Lx, TFSet()|syComma|syRParen, PlBs); ValV.Add(Val); } Lx.GetSym(Expect); // create and store tuple PPlTup Tup=TPlTup::New(FuncId, ValV); int TupId=PlBs->AddTup(Tup); TPlVal TupVal; TupVal.PutTupId(TupId); return TupVal; }
sptr<Node> Parser::ParseConditional() { sptr<StmntNode> root(new StmntNode(currToken)); NextToken(); root->PushChild(ParseExp()); Expect(THEN, -1); root->PushChild(ParseStatement()); if (MatchSkip(ELSE, -1)) root->PushChild(ParseStatement()); return root; }
/* RxGetInfo function * returns a string in the following format * breakpoint status program state * source file name (or NOSOURCE) address range for source * line number range for source * */ BOOL RXGetInfo(char *args) { ULONG addr, line = 0, startaddr, endaddr; long info[2]; // info[0] == lineBeg, info[1] == lineNo int first = 0, last = 0, type; short undef = TRUE, i; DEBUG *debug; if(*args) { addr = ParseExp(args, &undef, strlen(args)); } if(undef)addr = programPC; debug = FindNearestDebug(addr); // give breakpoint info and program status first if(IsBreakpoint(addr))sprintf(RexxReplyString,"BP "); sprintf(RexxReplyString,"NOBP "); strcat(RexxReplyString,StateText(programState)); if(debug) { // we have source // find end of this source range type = CurrentMixedLine(&addr,&line,info); if (type == 0)type = NextMixedLine(&addr, &line, info); if(type == MIXTYPE_SOURCE) { first = info[1]; // find end of range for the target range while(NextMixedLine(&addr,&line,info) == MIXTYPE_SOURCE); last = info[1]; } // now find the address range for this line startaddr = endaddr = addr; while(NextMixedLine(&addr,&line,info) == MIXTYPE_DISM)endaddr=addr; // give source range, then address range i = strlen(RexxReplyString); sprintf(&RexxReplyString[i]," %d. %d. %08X %08X",first,last,startaddr,endaddr); // finally, give the file name strcat(RexxReplyString," "); strcat(RexxReplyString,DirBuf); strcat(RexxReplyString,debug->sourceName); } else { strcat(RexxReplyString," NOSOURCE 0. 0. 0 0 NOSOURCE"); } return TRUE; }
void Parser::ParseConstDecl() { if (MatchSkip(CONST, -1)) { do { string name = currToken->lexeme; Expect(IDENT, -1); Expect(EQUAL, -1); sptr<ExprNode> exprValue(ParseExp()); // TODO get value currSymTable->Push(sptr<SymVar>(new SymVar(name, exprValue->GetType(), true))); } while (MatchSkip(SEMICOLON, -1)); } }
BOOL RXGetDismLine(char *args) { ULONG addr; short undef = TRUE, i; if(*args) { addr = ParseExp(args, &undef, strlen(args)); } if(undef)addr = programPC; sprintf(RexxReplyString,"%08X",addr); strcat(RexxReplyString," "); i=strlen(RexxReplyString); Disassemble(addr, addr, &RexxReplyString[i]); return TRUE; }
bool cVarParser::ParseAssign(const string& input) { int assignPos = input.find("="); if (assignPos >= 0) { string var(input.begin(), input.begin() + assignPos); if (ParseVar(var)) { varName = Strip(var); string assign(input.begin() + assignPos + 1, input.end()); return ParseExp(assign); } } LogFile.eSysLog("error parsing '%s'", input.c_str()); return false; }
BOOL SetWatchpoint(char *expression, ULONG type) { WORD i, undef; ULONG value; value = ParseExp(expression, &undef, strlen(expression)); if (undef) return FALSE; for (i=0; i<MAXWP; i++) { if (wpTable[i].type == WP_UNSET) { wpTable[i].type = type; strcpy(wpTable[i].expression, expression); return TRUE; } } ScrStatus("*** Watchpoint table full!!"); return FALSE; }
BOOL RXGetEval(char *args) { long val; short undef = TRUE; if(*args) { val = ParseExp(args, &undef, strlen(args)); } if(!undef) { char buf[128]; OffsetAddressBuf(val, buf); sprintf(RexxReplyString,"%d %08lx %s",val, val, buf); return TRUE; } sprintf(RexxReplyString,"UNDEFINED"); return 0; }
BOOL RXGetWords(char *args) { ULONG addr; UBYTE *address; short undef = TRUE, i = 0, j; if(*args) { addr = ParseExp(args, &undef, strlen(args)); } if(undef)addr = programPC; address = (UBYTE *)addr; for (i = 0; i < 7*2; i += 2) { j =strlen(RexxReplyString); sprintf(&RexxReplyString[j]," %04X", (address[i] << 8) | address[i+1]); } return TRUE; }
TWixExp::TWixExp(const TStr& _ExpStr): ExpStr(_ExpStr), Ok(true), ErrMsg(), ExpItem(), FactExpect(), TermExpect(), ExpExpect(){ // prepare expect sets FactExpect=TFSet()|wesyNot|wesyIncl|wesyExcl|wesyLParen|wesyDQuote|wesyWord; TermExpect=FactExpect; ExpExpect=TermExpect; // parse the expression string TWixExpLx Lx(ExpStr); try { Lx.GetSym(ExpExpect); ExpItem=ParseExp(Lx, TFSet()|wesyEof); } catch (EWixExp E){ Ok=false; ErrMsg=E.GetErrMsg(); } }
///////////////////////////////////////////////// // Wix-Expression PWixExpItem TWixExp::ParseFact(TWixExpLx& Lx, const TFSet& Expect){ if (Lx.Sym==wesyNot){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitNot, ExpItem)); } else if (Lx.Sym==wesyIncl){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitIncl, ExpItem)); } else if (Lx.Sym==wesyExcl){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitExcl, ExpItem)); } else if (Lx.Sym==wesyLParen){ Lx.GetSym(ExpExpect); PWixExpItem ExpItem=ParseExp(Lx, TFSet()|wesyRParen); Lx.GetSym(Expect); return ExpItem; } else if (Lx.Sym==wesyDQuote){ TStrV WordStrV; Lx.GetSym(TFSet()|wesyWord|wesyDQuote); while (Lx.Sym==wesyWord){ WordStrV.Add(Lx.Str); Lx.GetSym(TFSet()|wesyWord|wesyDQuote); } Lx.GetSym(Expect); return PWixExpItem(new TWixExpItem(WordStrV)); } else if (Lx.Sym==wesyWord){ PWixExpItem ExpItem=PWixExpItem(new TWixExpItem(Lx.Str)); Lx.GetSym(TFSet(Expect)|wesyWCard); if (Lx.Sym==wesyWCard){ PWixExpItem WCardExpItem= PWixExpItem(new TWixExpItem(weitWCard, ExpItem)); ExpItem=WCardExpItem; Lx.GetSym(Expect); } return ExpItem; } else { Fail; return NULL; } }
BOOL RXGetBytes(char *args) { ULONG addr; UBYTE *address; short undef = TRUE, i = 0, j; if(*args) { addr = ParseExp(args, &undef, strlen(args)); } if(undef)addr = programPC; address = (UBYTE *)addr; for (i = 0; i < 7; ++i) { j=strlen(RexxReplyString); sprintf(&RexxReplyString[j]," %02X", address[i]); } return TRUE; }
sptr<Node> Parser::ParseSwitchCase() { sptr<StmntNode> root(new StmntNode(currToken)); NextToken(); root->PushChild(ParseExp()); Expect(OF, -1); sptr<Node> caseList(new ListNode(ParseConstList(), "Case list")); Expect(COLON, -1); caseList->PushChild(ParseStatement()); while (MatchSkip(SEMICOLON, -1)) { caseList->PushChild(ParseConstList()); Expect(COLON, -1); caseList->PushChild(ParseStatement()); } root->PushChild(caseList); Expect(END, -1); return root; }
TTqlExp::TTqlExp(const TStr& _ExpStr): ExpStr(_ExpStr), Ok(true), ErrMsg(), Item(), RelOpSet(), FactExpect(), TermExpect(), ExpExpect(){ // symbol sets RelOpSet=TFSet(tsyLss, tsyLEq, tsyEq, tsyNEq, tsyGEq, tsyGtr); FactExpect=TFSet(tsyNot, tsyIncl, tsyExcl, tsyTitle, tsyLParen, tsyLBracket, tsyDQuote, tsyWord); TermExpect=FactExpect; ExpExpect=TermExpect; TTqlLx Lx(ExpStr); try { Lx.GetSym(ExpExpect); Item=ParseExp(Lx, TFSet()|tsyEof); } catch (ETql E){ Ok=false; ErrMsg=E.GetErrMsg(); } }
void Material::ParseExp(MaterialInput& input,JsonObject& obj,const string& key) { if (obj.HasMember(key.c_str())) { JsonObject::MemberIterator first_mem = obj[key.c_str()].MemberBegin(); if(first_mem!=obj.MemberEnd()) { MaterialExpMap::iterator it = exp_map_.find(first_mem->name.GetString()); if (it!=exp_map_.end()) { MaterialExpression* exp =(*it).second; input.input_mask_ = ParseMask(first_mem->value); ParseExp(exp,first_mem->value); input.link_ = exp; } first_mem++; } } }
void Material::Load(std::istream& stream) { JsonDocument json; string line; stream.seekg(0, std::ios::end); int length = (int)stream.tellg(); stream.seekg(0, std::ios::beg); char* str = BufferAllocator<char>::allocate(length+1); BinaryReader br(stream); br.readRaw(str, length); str[length] = '\0'; json.Parse<0>(str); if (json.HasParseError()) { Log::GetLog()->Printf(Log::ERROR_CHN, "jsonerror:%s,code:%s,len %d", str, json.GetParseError(), length); return; } BufferAllocator<char>::deallocate(str, length + 1); GetValue(emmisive_only_,json,"emissive_only"); GetValue(depth_write_,json,"depth_write"); ////load all expressions if (json.HasMember("expression")) { JsonObject& exp_json = json["expression"]; LoadAllEXP(exp_json); } ParseExp(emissive_,json,"emissive"); ParseExp(diffuse_,json,"diffuse"); ParseExp(normal_,json,"normal"); ParseExp(specular_color_,json,"specular_color"); ParseExp(specular_power_,json,"specular_power"); ParseExp(opacity_,json,"opacity"); ParseExp(mask_,json,"mask"); ParseExp(distortion_,json,"distortion"); }
sptr<ExprNode> Parser::ParsePrimary() { sptr<ExprNode> primary = nullptr; if (Match(INTEGER, REAL, HEX, CHARACTER, STRING, -1)) { primary = sptr<ConstNode>(new ConstNode(currToken)); NextToken(); } else if (Match(IDENT, -1)) { sptr<VarNode> ident = ParseIdent(); primary = Match(OPENBRAC, -1) ? ParseVar(ParseFuncCall(ident)) : ParseVar(ident); } else if (Match(OPENBRAC, -1)) { NextToken(); primary = ParseExp(); if (Match(CLOSEBRAC)) NextToken(); else throw ParserException("Enclosed bracket error"); } return primary; }
WORD RefreshWatchpoints(WORD maxLines, BOOL fullRefresh) { WORD count = 0; WORD i, undef; ULONG val; BOOL flag = FALSE; for (i=0; i<MAXWP && maxLines > 0; i++) { switch (wpTable[i].type) { case WP_UNSET: break; case WP_BYTES: val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression)); if (undef) ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression); else { WORD j = (CurDisplay->ds_ScrCols-35)/3; UBYTE *ps = (UBYTE *)val; if (!flag) { flag = ShowWatchTitle(fullRefresh,&count,&maxLines); } ScrPrintf("%-24.24s %08X ", wpTable[i].expression, val); while (j > 0) { ScrPrintf("%02X ", *ps++); --j; } } count++; Newline(); maxLines--; break; case WP_WORDS: val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression)); if (undef) ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression); else { WORD j = (CurDisplay->ds_ScrCols-35)/5; UWORD *ps = (UWORD *)val; if (!flag) { flag = ShowWatchTitle(fullRefresh,&count,&maxLines); } ScrPrintf("%-24.24s %08X ", wpTable[i].expression, val); while (j > 0) { ScrPrintf("%04X ", *ps++); --j; } } count++; Newline(); maxLines--; break; case WP_LONGS: val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression)); if (undef) ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression); else { WORD j = (CurDisplay->ds_ScrCols-35)/9; ULONG *ps = (ULONG *)val; if (!flag) { flag = ShowWatchTitle(fullRefresh,&count,&maxLines); } ScrPrintf("%-24.24s %08X ", wpTable[i].expression, val); while (j > 0) { ScrPrintf("%08X ", *ps++); --j; } } count++; Newline(); maxLines--; break; } } // add a newline to end if at top of screen if(flag && !CurDisplay->ds_RegFlag) { Newline(); count++; maxLines++; } return count; }
///////////////////////////////////////////////// // Tql-Expression PTqlItem TTqlExp::ParseFact(TTqlLx& Lx, const TFSet& Expect){ if (Lx.Sym==tsyNot){ Lx.GetSym(FactExpect); PTqlItem Item=ParseFact(Lx, Expect); return PTqlItem(new TTqlItem(titNot, Item)); } else if (Lx.Sym==tsyIncl){ Lx.GetSym(FactExpect); PTqlItem Item=ParseFact(Lx, Expect); return PTqlItem(new TTqlItem(titIncl, Item)); } else if (Lx.Sym==tsyExcl){ Lx.GetSym(FactExpect); PTqlItem Item=ParseFact(Lx, Expect); return PTqlItem(new TTqlItem(titExcl, Item)); } else if (Lx.Sym==tsyTitle){ Lx.GetSym(FactExpect); PTqlItem Item=ParseFact(Lx, Expect); return PTqlItem(new TTqlItem(titTitle, Item)); } else if (Lx.Sym==tsyLParen){ Lx.GetSym(ExpExpect); PTqlItem Item=ParseExp(Lx, TFSet()|tsyRParen); Lx.GetSym(Expect); return Item; } else if (Lx.Sym==tsyLBracket){ Lx.GetSym(tsyWord); TStr TagNm=Lx.Str; Lx.GetSym(tsyRBracket); Lx.GetSym(TFSet(FactExpect)|RelOpSet); if (RelOpSet.In(Lx.Sym)){ TStr RelOpStr=Lx.Str; Lx.GetSym(tsyWord, tsyExcl); TStr ArgStr; if (Lx.Sym==tsyExcl){ Lx.GetSym(tsyWord); ArgStr=TStr("-")+Lx.Str; } else { ArgStr=Lx.Str; } Lx.GetSym(Expect); return PTqlItem(new TTqlItem(TagNm, RelOpStr, ArgStr)); } else { PTqlItem Item=ParseFact(Lx, Expect); return PTqlItem(new TTqlItem(TagNm, Item)); } } else if (Lx.Sym==tsyDQuote){ TStrV WordStrV; do { Lx.GetSym(); if (Lx.Sym==tsyWord){ WordStrV.Add(Lx.Str);} } while (Lx.Sym!=tsyDQuote); Lx.GetSym(Expect); return PTqlItem(new TTqlItem(WordStrV)); } else if (Lx.Sym==tsyWord){ PTqlItem Item=PTqlItem(new TTqlItem(Lx.Str)); Lx.GetSym(TFSet(Expect)|tsyWCard); if (Lx.Sym==tsyWCard){ PTqlItem WCardItem= PTqlItem(new TTqlItem(titWCard, Item)); Item=WCardItem; Lx.GetSym(Expect); } return Item; } else { Fail; return NULL; } }