How to use TOKEN_STRING method in ng-mocks

Best JavaScript code snippet using ng-mocks

walley.js

Source:walley.js Github

copy

Full Screen

1none=null;function isalpha(input_char){return/^[a-z]+$/i.test(input_char)}function isdigit(e){return!isNaN(parseFloat(e))&&isFinite(e)}String.prototype.find=function(find_str,start){if(typeof start=="undefined"){start=0}return this.indexOf(find_str,start)};String.prototype.tolower=function(){return this.toLowerCase()};String.prototype.toupper=function(){return this.toUpperCase()};String.prototype.reverse=function(){return this.split("").reverse().join("")};Math["cot"]=function(num){return 1/Math.tan(num)};Math["sec"]=function(num){return 1/Math.cos(num)};Math["csc"]=function(num){return 1/Math.sin(num)};Object.prototype.slice=function(start,end){var return_obj={};var a=0;for(var i=start;i<end;i++){return_obj[a]=this[i];a++}return return_obj};Object.prototype.append=function(e){var t=this.maxn()+1;this[t]=e};Object.prototype.maxn=function(){var t=0;if(typeof this[0]=="undefined"){return-1}while(typeof this[t]!="undefined"){t=t+1}return t-1};Object.prototype.insert=function(insert_obj,pos){if(typeof pos=="undefined"){pos=table.maxn(this)+1;this[pos]=insert_obj}else{this[pos]=insert_obj}};Object.prototype.remove=function(pos){if(typeof pos=="undefined"){pos=table.maxn(obj)}delete this[pos]};Object.prototype.length=function(){return Object.keys(this).length};function len(obj){if(typeof obj=="string"){return obj.length}else if(typeof obj=="object"){return Object.keys(obj).length}else{console.log("Error..\nfunctin len() only support table or string\n")}}WALLEY={};WALLEY.stringToObject=function(input_str){if(typeof input_str=="string"){obj={};for(var i=0;i<input_str.length;i=i+1){obj[i]=input_str[i]}return obj}else{return input_str}};WALLEY.slice=function(obj,start,end){if(typeof obj=="object"){var return_obj={};var a=0;for(var i=start;i<end;i++){return_obj[a]=obj[i];a++}return return_obj}else if(typeof obj=="string"){return this.slice(start,end)}else{console.log("Error.. WALLEY.slice only support object and string type")}};function range(start,end,step){if(typeof end=="undefined"&&typeof step=="undefined"){end=start;start=0;step=1}else if(typeof step=="undefined"){step=1}var return_obj={};var count=0;for(var i=start;i<end;i=i+step){return_obj[count]=i;count++}return return_obj}2BEAUTIFUL_SPACES = 0;3if (typeof(exports)==="undefined"){4 exports = {};5}6INCOMPLETE_STATEMENT = false;7toString = function(input_str){8 if (input_str[0]==="\""){9 return input_str;10 }11 else{12 return "\""+input_str+"\"";13 }14}15Walley_Print_Error = function(input_str,error_message,error_start_index){16 console.log("Error.. %s\n",error_message);17 console.log("%s\n",input_str);18 var empty = "";19 var i = 0;20 for ( ; i<error_start_index ; i = i+1){21 empty = empty+" ";22 }23 empty = empty+"^";24 console.log("%s\n",empty);25}26Token_init = function(){27 var Token = {};28 Token["TOKEN_CLASS"] = "";29 Token["TOKEN_STRING"] = "";30 Token["TOKEN_START"] = -1;31 Token["TOKEN_END"] = -1;32 return Token;33}34TOKEN_print = function(token){35 console.log(token["TOKEN_CLASS"]+":"+"|"+token["TOKEN_STRING"]+"|"+token["TOKEN_START"]+"|"+token["TOKEN_END"]);36}37TL_toString = function(tl){38 var return_string = "";39 for(i in WALLEY.stringToObject(tl)){40 if((WALLEY.stringToObject(tl)).hasOwnProperty(i)){41 v=(WALLEY.stringToObject(tl))[i];42 return_string = return_string+v["TOKEN_STRING"];43 }44 };45}46TL_addToken = function(tl,add_token){47 var temp_token = Token_init();48 temp_token["TOKEN_CLASS"] = add_token["TOKEN_CLASS"];49 temp_token["TOKEN_STRING"] = add_token["TOKEN_STRING"];50 temp_token["TOKEN_START"] = add_token["TOKEN_START"];51 temp_token["TOKEN_END"] = add_token["TOKEN_END"];52 tl.append(temp_token);53}54TL_indexOfTokenThatHasTokenString = function(tl,token_string){55 var output = -1;56 var i = 0;57 for (i = 0 ; i<len(tl) ; i = i+1){58 if (tl[i]["TOKEN_STRING"]===token_string){59 return i;60 }61 }62 return -1;63}64TL_indexOfTokenThatHasTokenClass = function(tl,token_string){65 var output = -1;66 var i = 0;67 for (i = 0 ; i<len(tl) ; i = i+1){68 if (tl[i]["TOKEN_CLASS"]===token_string){69 return i;70 }71 }72 return -1;73}74match = function(input_str,index,match_string){75 var length_of_input_str = len(input_str);76 var length_of_match_str = len(match_string);77 if (length_of_input_str<index+length_of_match_str){78 return false;79 }80 var i = 0;81 var match = true;82 for ( ; i<length_of_match_str ; i = i+1){83 if (input_str[index+i]!==match_string[i]){84 match = false;85 break;86 }87 }88 if (match===true){89 return true;90 }91 else{92 return false;93 }94}95term = function(input_str1,input_str2){96 if (input_str1===input_str2){97 return true;98 }99 else{100 return false;101 }102}103LIST_indexOfFinalBracket = function(input_str,index_of_first_bracket){104 var count = 0;105 var in_string = false;106 var length_of_input_str = len(input_str);107 var i = index_of_first_bracket;108 for ( ; i<length_of_input_str ; i = i+1){109 if (((in_string===false && input_str[i]==="\"") && input_str[i-1]!=="\\")){110 in_string = true;111 continue;112 }113 if (((in_string===true && input_str[i]==="\"") && input_str[i-1]!=="\\")){114 in_string = false;115 continue;116 }117 if (in_string===false){118 if (input_str[i]==="["){119 count = count+1;120 continue;121 }122 if (input_str[i]==="]"){123 count = count-1;124 if (count===0){125 return i;126 }127 else{128 continue;129 }130 }131 }132 }133 return -1;134}135indexOfFinalDoubleQuote = function(input_str,first_index){136 var first_char = input_str[first_index];137 var i = first_index+1;138 var length = len(input_str);139 if (first_char==="\""){140 for ( ; i<length ; i = i+1){141 if ((input_str[i]==="\"" && input_str[i-1]!=="\\")){142 return i;143 }144 if ((input_str[i]==="\"" && input_str[i-1]==="\\")){145 if (input_str[i-2]==="\\"){146 return i;147 }148 }149 }150 }151 return -1;152}153Walley_Analyze_Token_Class = function(input_str,i){154 var return_obj = {};155 var length = len(input_str);156 if ((match(input_str,i,"&&") || match(input_str,i,"||"))){157 console.log("Error.. Does not support && and ||");158 console.log("Please use ' and ' and ' or ' instead");159 }160 if ((match(input_str,i,"++") || match(input_str,i,"--"))){161 end_index = i+2;162 return_obj[0] = end_index;163 return_obj[1] = "self_operator";164 return return_obj;165 }166 if (((((match(input_str,i,"+=") || match(input_str,i,"-=")) || match(input_str,i,"*=")) || match(input_str,i,"//=")) || match(input_str,i,"%="))){167 end_index = i+2;168 return_obj[0] = end_index;169 return_obj[1] = "self_assignment";170 return return_obj;171 }172 if (match(input_str,i,"**")){173 end_index = i+2;174 return_obj[0] = end_index;175 return_obj[1] = "m_operator";176 return return_obj;177 }178 if ((((((input_str[i]==="+" || input_str[i]==="-") || input_str[i]==="*") || input_str[i]==="/") || input_str[i]==="^") || input_str[i]==="%")){179 end_index = i+1;180 return_obj[0] = end_index;181 return_obj[1] = "m_operator";182 return return_obj;183 }184 if ((input_str[i]==="," || input_str[i]===":")){185 end_index = i+1;186 return_obj[0] = end_index;187 return_obj[1] = "punctuation";188 return return_obj;189 }190 if ((((match(input_str,i,"==") || match(input_str,i,">=")) || match(input_str,i,"<=")) || match(input_str,i,"!="))){191 end_index = i+2;192 return_obj[0] = end_index;193 return_obj[1] = "judge_sign";194 return return_obj;195 }196 if ((input_str[i]===">" || input_str[i]==="<")){197 end_index = i+1;198 return_obj[0] = end_index;199 return_obj[1] = "judge_sign";200 return return_obj;201 }202 if (((i<=length-2 && input_str[i]==="#") && input_str[i+1]==="~")){203 end_index = i+2;204 return_obj[0] = end_index;205 return_obj[1] = "l_annotation";206 return return_obj;207 }208 if ((i<=length-2 && (input_str[i]==="~" && input_str[i+1]==="#"))){209 end_index = i+2;210 return_obj[0] = end_index;211 return_obj[1] = "r_annotation";212 }213 if (input_str[i]==="="){214 end_index = i+1;215 return_obj[0] = end_index;216 return_obj[1] = "assignment_operator";217 return return_obj;218 }219 if (input_str[i]==="#"){220 end_index = i+1;221 return_obj[0] = end_index;222 return_obj[1] = "annotation";223 return return_obj;224 }225 if ((((input_str[i]==="(" || input_str[i]===")") || input_str[i]==="{") || input_str[i]==="}")){226 end_index = i+1;227 var output = input_str[i];228 return_obj[0] = end_index;229 return_obj[1] = output;230 return return_obj;231 }232 if (input_str[i]==="["){233 var index_of_final = LIST_indexOfFinalBracket(input_str,i);234 if (index_of_final===-1){235 INCOMPLETE_STATEMENT = true;236 }237 end_index = index_of_final+1;238 return_obj[0] = end_index;239 return_obj[1] = "list_table";240 return return_obj;241 }242 if (input_str[i]==="\""){243 var index_of_right_dq = indexOfFinalDoubleQuote(input_str,i);244 if (index_of_right_dq===-1){245 console.log("incomplete str\n");246 process.exit(0);247 }248 else{249 end_index = index_of_right_dq+1;250 return_obj[0] = end_index;251 return_obj[1] = "string";252 return return_obj;253 }254 }255 if (isdigit(input_str[i])===true){256 var a = i;257 var temp_str = input_str[i];258 while (isdigit(temp_str)){259 a = a+1;260 temp_str = temp_str+input_str[a];261 }262 end_index = a;263 return_obj[0] = end_index;264 return_obj[1] = "num";265 return return_obj;266 }267 if (((input_str[i]===" " || input_str[i]==="\n") || input_str[i]==="\t")){268 var a = i+1;269 for ( ; a<length ; a = a+1){270 if (((input_str[a]!==" " && input_str[a]!=="\n") && input_str[a]!=="\t")){271 break;272 }273 }274 end_index = a;275 return_obj[0] = end_index;276 return_obj[1] = "white_space";277 return return_obj;278 }279 if (((isalpha(input_str[i]) || input_str[i]==="_") || input_str[i]==="$")){280 var a = i+1;281 for ( ; a<length ; a = a+1){282 if ((((isalpha(input_str[a]) || input_str[a]==="_") || input_str[a]==="$") || isdigit(input_str[a]))){283 continue;284 }285 else{286 break;287 }288 }289 var id_string = input_str.slice(i,a);290 if (id_string==="import"){291 end_index = i+6;292 return_obj[0] = end_index;293 return_obj[1] = "import";294 return return_obj;295 }296 else if ((id_string==="and" || id_string==="not")){297 end_index = i+3;298 return_obj[0] = end_index;299 return_obj[1] = "relation";300 return return_obj;301 }302 else if (id_string==="or"){303 end_index = i+2;304 return_obj[0] = end_index;305 return_obj[1] = "relation";306 return return_obj;307 }308 else if (id_string==="if"){309 end_index = i+2;310 return_obj[0] = end_index;311 return_obj[1] = "keyword";312 return return_obj;313 }314 else if ((id_string==="def" || id_string==="for")){315 end_index = i+3;316 return_obj[0] = end_index;317 return_obj[1] = "keyword";318 return return_obj;319 }320 else if (((id_string==="elif" || id_string==="else") || id_string==="case")){321 end_index = i+4;322 return_obj[0] = end_index;323 return_obj[1] = "keyword";324 return return_obj;325 }326 else if (id_string==="while"){327 end_index = i+5;328 return_obj[0] = end_index;329 return_obj[1] = "keyword";330 return return_obj;331 }332 else if (id_string==="then"){333 end_index = i+4;334 return_obj[0] = end_index;335 return_obj[1] = "then";336 return return_obj;337 }338 else if (id_string==="end"){339 end_index = i+3;340 return_obj[0] = end_index;341 return_obj[1] = "end";342 return return_obj;343 }344 else if (id_string==="return"){345 end_index = i+6;346 return_obj[0] = end_index;347 return_obj[1] = "return";348 return return_obj;349 }350 else if (id_string==="local"){351 end_index = i+5;352 return_obj[0] = end_index;353 return_obj[1] = "local";354 return return_obj;355 }356 else if (id_string==="switch"){357 end_index = i+6;358 return_obj[0] = end_index;359 return_obj[1] = "keyword";360 return return_obj;361 }362 else if (id_string==="new"){363 end_index = i+3;364 return_obj[0] = end_index;365 return_obj[1] = "new";366 return return_obj;367 }368 else{369 end_index = a;370 return_obj[0] = end_index;371 return_obj[1] = "id";372 return return_obj;373 }374 }375 if (input_str[i]==="."){376 var a = i+1;377 end_index = a;378 return_obj[0] = end_index;379 return_obj[1] = "dot";380 return return_obj;381 }382 Walley_Print_Error(input_str,"Can not analyze this input",i);383 process.exit(0);384}385Walley_Lexical_Analyzie = function(input_str){386 var i = 0;387 var length = len(input_str);388 var tl = {};389 var end_index = 0;390 for ( ; i<length ; i = i+1){391 var output_data = Walley_Analyze_Token_Class(input_str,i);392 end_index = output_data[0];393 var token_class = output_data[1];394 if (INCOMPLETE_STATEMENT===true){395 break;396 }397 if (token_class==="white_space"){398 i = end_index-1;399 continue;400 }401 if (token_class==="annotation"){402 for (i = end_index ; i<length ; i = i+1){403 if (input_str[i]==="\n"){404 break;405 }406 }407 continue;408 }409 if (token_class==="l_annotation"){410 i = end_index;411 var count = 0;412 var find_right_annotation = false;413 for ( ; i<length-1 ; i = i+1){414 if (input_str[i]==="\""){415 count = count+1;416 continue;417 }418 if (((count%2===0 && input_str[i]==="~") && input_str[i+1]==="#")){419 i = i+1;420 find_right_annotation = true;421 break;422 }423 }424 if (find_right_annotation===false){425 INCOMPLETE_STATEMENT = true;426 return tl;427 }428 continue;429 }430 temp_token = Token_init();431 temp_token["TOKEN_START"] = i;432 temp_token["TOKEN_END"] = end_index;433 temp_token["TOKEN_CLASS"] = token_class;434 var token_string = "";435 token_string = input_str.slice(i,end_index).trim();436 temp_token["TOKEN_STRING"] = token_string;437 tl.append(temp_token);438 i = end_index-1;439 }440 return tl;441}442TREE_INDEX = 0;443TREE_init = function(name){444 var TREE = {};445 TREE["name"] = name||"";446 TREE["token_class"] = "";447 TREE["index"] = 0;448 TREE["layer"] = 0;449 TREE["node_list"] = {};450 TREE_INDEX = TREE_INDEX+1;451 return TREE;452}453TREE_addNode = function(tree,name,token_class){454 var length_of_nl = len(tree["node_list"]);455 tree["node_list"][length_of_nl] = TREE_init();456 tree["node_list"][length_of_nl]["name"] = name;457 tree["node_list"][length_of_nl]["token_class"] = token_class;458 tree["node_list"][length_of_nl]["index"] = TREE_INDEX-1;459 tree["node_list"][length_of_nl]["layer"] = tree["layer"]+1;460 tree["node_list"][length_of_nl]["node_list"] = {};461}462TREE_addTree = function(tree,add_tree){463 var index = TREE_INDEX;464 var length_of_nl = len(tree["node_list"]);465 tree["node_list"][length_of_nl] = add_tree;466 tree["node_list"][length_of_nl]["index"] = index;467 tree["node_list"][length_of_nl]["layer"] = tree["layer"]+1;468 TREE_INDEX = TREE_INDEX+1;469}470TREE_getTreeAccordingToIndex = function(tree,index){471 if (index===tree["index"]){472 return tree;473 }474 else{475 var nl = tree["node_list"];476 if (len(nl)===0){477 return null;478 }479 var i = 0;480 var length = len(nl);481 for ( ; i<length ; i = i+1){482 var node = nl[i];483 if (index===node["index"]){484 return node;485 }486 }487 nl = tree["node_list"];488 i = 0;489 for ( ; i<length ; i = i+1){490 found_tree = TREE_getTreeAccordingToIndex(nl[i],index);491 if (found_tree!==null){492 return found_tree;493 }494 }495 }496 return null;497}498TREE_print = function(tree){499 process["stdout"].write("("+tree["token_class"]+" "+tree["name"]);500 var length_of_node_list = len(tree["node_list"]);501 if (length_of_node_list!==0){502 var i = 0;503 var nl = tree["node_list"];504 for (i = 0 ; i<length_of_node_list ; i = i+1){505 TREE_print(nl[i]);506 }507 }508 process["stdout"].write(")");509}510TREE_changeNameAccordingToIndex = function(tree,index,change_to_name){511 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);512 temp_tree["name"] = change_to_name;513}514TREE_layer = function(tree){515 var temp_tree = TREE_getTreeAccordingToIndex(tree,TREE_INDEX);516 return temp_tree["layer"];517}518TREE_addNodeAtIndex = function(tree,index,add_name,add_token_class){519 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);520 TREE_addNode(temp_tree,add_name,add_token_class);521}522elements = function(tree,tl){523 if (INCOMPLETE_STATEMENT===true){524 return false;525 }526 var length_of_tl = len(tl);527 var index_of_comma = TL_indexOfTokenThatHasTokenString(tl,",");528 if (index_of_comma===-1){529 var index_of_tl = TREE_INDEX;530 TREE_addNode(tree,"value","");531 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl),tl);532 }533 else{534 var tl1 = tl.slice(0,index_of_comma);535 var tl2 = tl.slice(index_of_comma+1,length_of_tl);536 var index_of_tl1 = TREE_INDEX;537 TREE_addNode(tree,"value","");538 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&elements(tree,tl2);539 }540}541value = function(tree,tl){542 if (INCOMPLETE_STATEMENT){543 return false;544 }545 var length_of_tl = len(tl);546 if (length_of_tl===0){547 tree["name"] = "none";548 tree["token_class"] = "id";549 return true;550 }551 else if (length_of_tl===1){552 if ((("num"===tl[0]["TOKEN_CLASS"] || "string"===tl[0]["TOKEN_CLASS"]) || "id"===tl[0]["TOKEN_CLASS"])){553 tree["name"] = tl[0]["TOKEN_STRING"];554 tree["token_class"] = tl[0]["TOKEN_CLASS"];555 return true;556 }557 else if ("list_table"===tl[0]["TOKEN_CLASS"]){558 tree["name"] = tl[0]["TOKEN_STRING"];559 tree["token_class"] = "table";560 var key_index = {val:0};561 return table(tree,tl,key_index);562 }563 else{564 return false;565 }566 }567 else{568 return (((func_value(tree,tl) || table_value(tree,tl)) || func(tree,tl)) || relation(tree,tl))||expr(tree,tl);569 }570}571new_value = function(tree,tl){572 if (tl[0]["TOKEN_STRING"]==="new"){573 tree["name"] = "new_value";574 tree["token_class"] = "";575 tl[0]["TOKEN_STRING"] = ".";576 tl[0]["TOKEN_CLASS"] = "dot";577 return table_value_key(tree,tl);578 }579 return false;580}581table_elements = function(tree,tl,key_index){582 if (INCOMPLETE_STATEMENT){583 return false;584 }585 var length_of_tl = len(tl);586 var i = 0;587 var index_of_comma = -1;588 var count = 0;589 for (i = 0 ; i<length_of_tl ; i = i+1){590 if (tl[i]["TOKEN_STRING"]==="("){591 count++;592 continue;593 }594 if (tl[i]["TOKEN_STRING"]===")"){595 count--;596 continue;597 }598 if ((count===0 && tl[i]["TOKEN_STRING"]===",")){599 index_of_comma = i;600 break;601 }602 }603 if (index_of_comma!==-1){604 table_expr_tl = tl.slice(0,index_of_comma);605 table_elements_tl = tl.slice(index_of_comma+1,length_of_tl);606 var index1 = TREE_INDEX;607 TREE_addNode(tree,"table_expr","");608 return table_expr(TREE_getTreeAccordingToIndex(tree,index1),table_expr_tl,key_index)&&table_elements(tree,table_elements_tl,key_index);609 }610 else{611 var index = TREE_INDEX;612 TREE_addNode(tree,"table_expr","");613 return table_expr(TREE_getTreeAccordingToIndex(tree,index),tl,key_index);614 }615}616table_expr = function(tree,tl,key_index){617 if (INCOMPLETE_STATEMENT===true){618 return false;619 }620 var length_of_tl = len(tl);621 if ((((3<length_of_tl && term(tl[0]["TOKEN_CLASS"],"@")) && term(tl[1]["TOKEN_CLASS"],"id")) && term(tl[2]["TOKEN_STRING"],"="))){622 var append_key = tl[1]["TOKEN_STRING"];623 var length_of_append_key = len(append_key);624 var new_key = "@"+append_key;625 TREE_addNode(tree,new_key,"key");626 var index = TREE_INDEX;627 TREE_addNode(tree,"value","");628 return value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(3,length_of_tl));629 }630 else if ((term(tl[0]["TOKEN_CLASS"],"id") && term(tl[1]["TOKEN_STRING"],"="))){631 var index1 = TREE_INDEX;632 TREE_addNode(tree,"key","");633 var key_tl = Walley_Lexical_Analyzie(toString(tl[0]["TOKEN_STRING"]));634 var key_tree = TREE_init("key");635 value(key_tree,key_tl);636 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);637 var index2 = TREE_INDEX;638 TREE_addNode(tree,"value","");639 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(2,length_of_tl));640 }641 else if (((term(tl[0]["TOKEN_CLASS"],"list_table") && typeof(tl[1])!=="undefined") && term(tl[1]["TOKEN_STRING"],"="))){642 var length = len(tl[0]["TOKEN_STRING"]);643 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);644 var index1 = TREE_INDEX;645 TREE_addNode(tree,"key","");646 var key_tl = Walley_Lexical_Analyzie(string_inside);647 TREE;648 key_tree = TREE_init("key");649 value(key_tree,key_tl);650 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);651 var index2 = TREE_INDEX;652 TREE_addNode(tree,"value","");653 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(2,length_of_tl));654 }655 else{656 var index1 = TREE_INDEX;657 TREE_addNode(tree,"key","");658 var key_tl = Walley_Lexical_Analyzie(key_index["val"]+"");659 var key_tree = TREE_init("key");660 value(key_tree,key_tl);661 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);662 var index = TREE_INDEX;663 TREE_addNode(tree,"value","");664 key_index["val"] = key_index["val"]+1;665 return value(TREE_getTreeAccordingToIndex(tree,index),tl);666 }667 return false;668}669table = function(tree,tl,key_index){670 if (INCOMPLETE_STATEMENT===true){671 return false;672 }673 var length_of_tl = len(tl);674 if (length_of_tl===1){675 var list_string = tl[0]["TOKEN_STRING"];676 var length_of_list_string = len(list_string);677 if ((list_string[0]==="[" && list_string[length_of_list_string-1]==="]")){678 var list_string2 = list_string.slice(1,len(list_string)-1).trim();679 if (list_string2===""){680 return true;681 }682 var table_tl = Walley_Lexical_Analyzie(list_string2);683 return table_elements(tree,table_tl,key_index);684 }685 else{686 return false;687 }688 }689 else{690 return false;691 }692}693table_value = function(tree,tl){694 if (INCOMPLETE_STATEMENT===true){695 return false;696 }697 var length_of_tl = len(tl);698 var i = 0;699 var count = 0;700 for (i = 0 ; i<length_of_tl ; i = i+1){701 if (term(tl[i]["TOKEN_STRING"],"(")){702 count = count+1;703 }704 else if (term(tl[i]["TOKEN_STRING"],")")){705 count = count-1;706 }707 if ((count===0 && term(tl[i]["TOKEN_CLASS"],"m_operator"))){708 return false;709 }710 }711 if (((2<=length_of_tl && (((term(tl[0]["TOKEN_CLASS"],"id") || term(tl[0]["TOKEN_CLASS"],"string")) || term(tl[0]["TOKEN_CLASS"],"list_table")) || term(tl[0]["TOKEN_CLASS"],"num"))) && (term(tl[1]["TOKEN_STRING"],".") || term(tl[1]["TOKEN_CLASS"],"list_table")))){712 var index1 = TREE_INDEX;713 TREE_addNode(tree,"table_value","");714 var index2 = TREE_INDEX;715 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index1),"value","");716 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(0,1))&&table_value_key(TREE_getTreeAccordingToIndex(tree,index1),tl.slice(1,length_of_tl));717 }718 else if (((3<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"id")) && term(tl[1]["TOKEN_STRING"],"("))){719 var index = -1;720 var i = 0;721 var count = 0;722 for (i = 0 ; i<len(tl) ; i = i+1){723 if (term(tl[i]["TOKEN_STRING"],"(")){724 count = count+1;725 }726 else if (term(tl[i]["TOKEN_STRING"],")")){727 count = count-1;728 if (count===0){729 index = i;730 break;731 }732 }733 }734 if (index===length_of_tl-1){735 return false;736 }737 if ((typeof(tl[i+1])!=="undefined" && term(tl[i+1]["TOKEN_CLASS"],"relation"))){738 return false;739 }740 var tree_index = TREE_INDEX;741 TREE_addNode(tree,"table_value","");742 var tree_index2 = TREE_INDEX;743 TREE_addNode(TREE_getTreeAccordingToIndex(tree,tree_index),"func","");744 func(TREE_getTreeAccordingToIndex(tree,tree_index2),tl.slice(0,index+1));745 return table_value_key(TREE_getTreeAccordingToIndex(tree,tree_index),tl.slice(index+1,length_of_tl));746 }747 else{748 if (term(tl[0]["TOKEN_STRING"],"(")){749 var index_of_right = -1;750 var i = 0;751 var count = 0;752 for (i = 0 ; i<len(tl) ; i = i+1){753 if (term(tl[i]["TOKEN_STRING"],"(")){754 count = count+1;755 }756 else if (term(tl[0]["TOKEN_STRING"],")")){757 count = count-1;758 if (count===0){759 index_of_right = i;760 break;761 }762 }763 }764 if (index_of_right===-1){765 return false;766 }767 else{768 if (index_of_right===length_of_tl-1){769 return false;770 }771 if ((term(tl[index_of_right+1]["TOKEN_CLASS"],"list_table")===false || term(tl[index_of_right+1]["TOKEN_STRING"],".")===false)){772 return false;773 }774 var index = TREE_INDEX;775 TREE_addNode(tree,"table_value","");776 var index2 = TREE_INDEX;777 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"expr","");778 return expr(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(0,index_of_right+1))&&table_value_key(TREE_getTreeAccordingToIndex(tree,index),tl.slice(index_of_right+1,length_of_tl));779 }780 }781 return false;782 }783}784table_value_key = function(tree,tl){785 if (INCOMPLETE_STATEMENT===true){786 return false;787 }788 var length_of_tl = len(tl);789 if ((length_of_tl===1 && term(tl[0]["TOKEN_CLASS"],"list_table"))){790 var length = len(tl[0]["TOKEN_STRING"]);791 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);792 var key_tl = Walley_Lexical_Analyzie(string_inside);793 var index_of_colon = -1;794 var i = 0;795 for (i = 0 ; i<len(key_tl) ; i = i+1){796 if (term(key_tl[i]["TOKEN_STRING"],":")){797 index_of_colon = i;798 break;799 }800 }801 if (index_of_colon===-1){802 var index1 = TREE_INDEX;803 TREE_addNode(tree,"key","");804 var key_tree = TREE_init(key_tree,"key");805 value(key_tree,key_tl);806 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);807 return true;808 }809 else{810 var length_of_key_tl = len(key_tl);811 var index1 = TREE_INDEX;812 TREE_addNode(tree,"key","");813 var slice_tree = TREE_init("slice");814 var left_tl = null;815 var right_tl = null;816 if (index_of_colon===0){817 left_tl = null;818 }819 else{820 left_tl = key_tl.slice(0,index_of_colon);821 }822 if (index_of_colon===length_of_key_tl-1){823 right_tl = null;824 }825 else{826 right_tl = key_tl.slice(index_of_colon+1,length_of_key_tl);827 }828 var index_left = TREE_INDEX;829 if (left_tl===null){830 TREE_addNode(slice_tree,"0","num");831 }832 else{833 TREE_addNode(slice_tree,"value","");834 value(TREE_getTreeAccordingToIndex(slice_tree,index_left),left_tl);835 }836 var index_right = TREE_INDEX;837 if (right_tl===null){838 TREE_addNode(slice_tree,"its_length","special");839 }840 else{841 TREE_addNode(slice_tree,"value","");842 value(TREE_getTreeAccordingToIndex(slice_tree,index_right),right_tl);843 }844 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),slice_tree);845 return true;846 }847 }848 else if (((length_of_tl===2 && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id"))){849 var index1 = TREE_INDEX;850 TREE_addNode(tree,"key","");851 var key_tl = Walley_Lexical_Analyzie(toString(tl[1]["TOKEN_STRING"]));852 var key_tree = TREE_init("key");853 value(key_tree,key_tl);854 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);855 return true;856 }857 else if ((((4<=length_of_tl && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id")) && term(tl[2]["TOKEN_STRING"],"("))){858 var index_of_right = -1;859 var i = 0;860 var count = 0;861 for (i = 0 ; i<len(tl) ; i = i+1){862 if (term(tl[i]["TOKEN_STRING"],"(")){863 count = count+1;864 }865 else if (term(tl[i]["TOKEN_STRING"],")")){866 count = count-1;867 if (count===0){868 index_of_right = i;869 break;870 }871 }872 }873 if (index_of_right===-1){874 INCOMPLETE_STATEMENT = true;875 return false;876 }877 if (index_of_right===length_of_tl-1){878 var index1 = TREE_INDEX;879 TREE_addNode(tree,"key","");880 return func(TREE_getTreeAccordingToIndex(tree,index1),tl.slice(1,length_of_tl));881 }882 else{883 return table_value_key(tree,tl.slice(0,index_of_right+1))&&table_value_key(tree,tl.slice(index_of_right+1,length_of_tl));884 }885 }886 else if (((2<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"list_table")) && (term(tl[1]["TOKEN_STRING"],".") || term(tl[1]["TOKEN_CLASS"],"list_table")))){887 return table_value_key(tree,tl.slice(0,1))&&table_value_key(tree,tl.slice(1,length_of_tl));888 }889 else if (((3<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"list_table")) && term(tl[1]["TOKEN_STRING"],"("))){890 var index = -1;891 var i = 0;892 var count = 0;893 for (i = 0 ; i<len(tl) ; i = i+1){894 if (term(tl[i]["TOKEN_STRING"],"(")){895 count = count+1;896 }897 else if (term(tl[i]["TOKEN_STRING"],")")){898 count = count-1;899 if (count===0){900 index = i;901 break;902 }903 }904 }905 if (index===-1){906 INCOMPLETE_STATEMENT = true;907 return false;908 }909 var func_tree = TREE_init("func");910 var tree_index = TREE_INDEX;911 TREE_addNode(func_tree,"","table_call");912 TREE_addNode(TREE_getTreeAccordingToIndex(func_tree,tree_index),"","");913 tree_index = tree_index+1;914 var length = len(tl[0]["TOKEN_STRING"]);915 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);916 var string_inside_tl = Walley_Lexical_Analyzie(string_inside);917 value(TREE_getTreeAccordingToIndex(func_tree,tree_index),string_inside_tl);918 tree_index = TREE_INDEX;919 TREE_addNode(func_tree,"params","");920 if (2!==index){921 params(TREE_getTreeAccordingToIndex(func_tree,tree_index),tl.slice(2,index));922 }923 TREE_addTree(tree,func_tree);924 if (index===length_of_tl-1){925 return true;926 }927 return table_value(tree,tl.slice(index+1,length_of_tl));928 }929 else if ((((3<=length_of_tl && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id")) && (term(tl[2]["TOKEN_STRING"],".") || term(tl[2]["TOKEN_CLASS"],"list_table")))){930 return table_value_key(tree,tl.slice(0,2))&&table_value_key(tree,tl.slice(2,length_of_tl));931 }932 else{933 return false;934 }935}936expr = function(tree,tl){937 if (INCOMPLETE_STATEMENT){938 return false;939 }940 var length_of_tl = len(tl);941 var count_of_parenthesis = 0;942 var i = length_of_tl-1;943 for ( ; 0<=i ; i = i-1){944 if (tl[i]["TOKEN_STRING"]==="("){945 count_of_parenthesis = count_of_parenthesis+1;946 continue;947 }948 if (tl[i]["TOKEN_STRING"]===")"){949 count_of_parenthesis = count_of_parenthesis-1;950 continue;951 }952 if ((count_of_parenthesis===0 && ("+"===tl[i]["TOKEN_STRING"] || "-"===tl[i]["TOKEN_STRING"]))){953 var sign = tl[i]["TOKEN_STRING"];954 var index_of_first_sign = i;955 if (index_of_first_sign===0){956 temp_tl = {};957 var temp_token = Token_init();958 temp_token["TOKEN_STRING"] = "0";959 temp_token["TOKEN_CLASS"] = "num";960 temp_token["TOKEN_START"] = -1;961 temp_token["TOKEN_END"] = -1;962 temp_tl.append(temp_token);963 var a = 0;964 for (a = 0 ; a<len(tl) ; a = a+1){965 temp_tl.append(tl[a]);966 }967 return expr(tree,temp_tl);968 }969 var tl1 = tl.slice(0,index_of_first_sign);970 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);971 tree["name"] = sign;972 var index_of_expr1_node = TREE_INDEX;973 TREE_addNode(tree,"expr","");974 var index_of_expr2_node = TREE_INDEX;975 TREE_addNode(tree,"expr","");976 return expr(TREE_getTreeAccordingToIndex(tree,index_of_expr1_node),tl1)&&expr(TREE_getTreeAccordingToIndex(tree,index_of_expr2_node),tl2);977 }978 }979 return s_term(tree,tl);980}981s_term = function(tree,tl){982 if (INCOMPLETE_STATEMENT){983 return false;984 }985 var length_of_tl = len(tl);986 var count_of_parenthesis = 0;987 var i = length_of_tl-1;988 for ( ; 0<=i ; i = i-1){989 if (tl[i]["TOKEN_STRING"]==="("){990 count_of_parenthesis = count_of_parenthesis+1;991 continue;992 }993 if (tl[i]["TOKEN_STRING"]===")"){994 count_of_parenthesis = count_of_parenthesis-1;995 continue;996 }997 if ((count_of_parenthesis===0 && (("*"===tl[i]["TOKEN_STRING"] || "/"===tl[i]["TOKEN_STRING"]) || "%"===tl[i]["TOKEN_STRING"]))){998 var sign = tl[i]["TOKEN_STRING"];999 var index_of_first_sign = i;1000 var tl1 = tl.slice(0,index_of_first_sign);1001 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);1002 tree["name"] = sign;1003 var current_index = tree["index"];1004 TREE_addNode(tree,"s_term","");1005 TREE_addNodeAtIndex(tree,current_index,"p_term","");1006 var index_of_node1 = TREE_INDEX-2;1007 var index_of_node2 = TREE_INDEX-1;1008 return s_term(TREE_getTreeAccordingToIndex(tree,index_of_node1),tl1)&&p_term(TREE_getTreeAccordingToIndex(tree,index_of_node2),tl2);1009 }1010 }1011 return p_term(tree,tl);1012}1013p_term = function(tree,tl){1014 if (INCOMPLETE_STATEMENT){1015 return false;1016 }1017 var length_of_tl = len(tl);1018 var count_of_parenthesis = 0;1019 var i = length_of_tl-1;1020 for ( ; 0<=i ; i = i-1){1021 if (tl[i]["TOKEN_STRING"]==="("){1022 count_of_parenthesis = count_of_parenthesis+1;1023 continue;1024 }1025 if (tl[i]["TOKEN_STRING"]===")"){1026 count_of_parenthesis = count_of_parenthesis-1;1027 continue;1028 }1029 if ((count_of_parenthesis===0 && ("^"===tl[i]["TOKEN_STRING"] || "**"===tl[i]["TOKEN_STRING"]))){1030 var sign = "^";1031 var index_of_first_sign = i;1032 var tl1 = tl.slice(0,index_of_first_sign);1033 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);1034 tree["name"] = sign;1035 var current_index = tree["index"];1036 TREE_addNode(tree,"p_term","");1037 TREE_addNodeAtIndex(tree,current_index,"factor","");1038 var index_of_node1 = TREE_INDEX-2;1039 var index_of_node2 = TREE_INDEX-1;1040 return p_term(TREE_getTreeAccordingToIndex(tree,index_of_node1),tl1)&&factor(TREE_getTreeAccordingToIndex(tree,index_of_node2),tl2);1041 }1042 }1043 return factor(tree,tl);1044}1045factor = function(tree,tl){1046 if (INCOMPLETE_STATEMENT===true){1047 return false;1048 }1049 var length_of_tl = len(tl);1050 if ((term(tl[0]["TOKEN_STRING"],"(") && term(tl[length_of_tl-1]["TOKEN_STRING"],")"))){1051 tree["name"] = "expr";1052 tree["token_class"] = "";1053 return expr(tree,TL_subtl(tl,1,length_of_tl-1));1054 }1055 else{1056 return new_value(tree,tl)||value(tree,tl);1057 }1058}1059assignment = function(tree,tl){1060 var test = self_operator_stm(tree,tl)||self_assignment_stm(tree,tl);1061 if (test===true){1062 return true;1063 }1064 if (INCOMPLETE_STATEMENT===true){1065 return false;1066 }1067 var is_local = false;1068 if (term(tl[0]["TOKEN_STRING"],"local")){1069 is_local = true;1070 }1071 var count = 0;1072 var count_of_equal = 0;1073 var index_of_equal = -1;1074 var i = 0;1075 for (i = 0 ; i<len(tl) ; i = i+1){1076 if (((((term(tl[i]["TOKEN_STRING"],"(") || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"while"))){1077 count = count+1;1078 }1079 else if ((term(tl[i]["TOKEN_STRING"],")") || term(tl[i]["TOKEN_STRING"],"end"))){1080 count = count-1;1081 }1082 if ((count===0 && tl[i]["TOKEN_STRING"]==="=")){1083 count_of_equal = count_of_equal+1;1084 index_of_equal = i;1085 }1086 }1087 if (count_of_equal!==1){1088 return false;1089 }1090 else{1091 var length_of_tl = len(tl);1092 var save_TREE_INDEX = TREE_INDEX;1093 TREE_INDEX = 0;1094 var var_name_tree = TREE_init("var_name");1095 var var_name_list = {};1096 if (is_local===true){1097 var_name_list = tl.slice(1,index_of_equal);1098 }1099 else{1100 var_name_list = tl.slice(0,index_of_equal);1101 }1102 var_name(var_name_tree,var_name_list);1103 TREE_INDEX = 0;1104 var var_value_tree = TREE_init("var_value");1105 var var_value_list = tl.slice(index_of_equal+1,length_of_tl);1106 var_value(var_value_tree,var_value_list);1107 TREE_INDEX = save_TREE_INDEX;1108 var var_name_num = len(var_name_tree["node_list"]);1109 var i = 0;1110 var var_name_nl = var_name_tree["node_list"];1111 var var_value_nl = var_value_tree["node_list"];1112 for ( ; i<var_name_num ; i = i+1){1113 var index = TREE_INDEX;1114 TREE_addNode(tree,"=","");1115 if (is_local===true){1116 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"local","");1117 }1118 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),var_name_nl[i]);1119 if (typeof(var_value_nl[i])==="undefined"){1120 var temp_tree = TREE_init();1121 temp_tree["name"] = "none";1122 temp_tree["token_class"] = "id";1123 temp_tree["node_list"] = {};1124 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),temp_tree);1125 }1126 else{1127 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),var_value_nl[i]);1128 }1129 }1130 return true;1131 }1132}1133var_name = function(tree,tl){1134 if (INCOMPLETE_STATEMENT===true){1135 return false;1136 }1137 var index_of_comma = TL_indexOfTokenThatHasTokenString(tl,",");1138 if (index_of_comma!==-1){1139 var length_of_tl = len(tl);1140 var tl1 = tl.slice(0,index_of_comma);1141 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1142 return var_name(tree,tl1)&&var_name(tree,tl2);1143 }1144 else{1145 var length_of_tl = len(tl);1146 if (length_of_tl===1){1147 if ("id"===tl[0]["TOKEN_CLASS"]){1148 TREE_addNode(tree,tl[0]["TOKEN_STRING"],"id");1149 return true;1150 }1151 else{1152 return false;1153 }1154 }1155 else{1156 return table_value(tree,tl);1157 }1158 }1159 return false;1160}1161var_value = function(tree,tl){1162 if (INCOMPLETE_STATEMENT===true){1163 return false;1164 }1165 var length_of_tl = len(tl);1166 var index_of_comma = -1;1167 var i = 0;1168 var count = 0;1169 for ( ; i<length_of_tl ; i = i+1){1170 if (((((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"("))){1171 count = count+1;1172 }1173 if ((term(tl[i]["TOKEN_STRING"],"end") || term(tl[i]["TOKEN_STRING"],")"))){1174 count = count-1;1175 }1176 if ((count===0 && term(tl[i]["TOKEN_STRING"],","))){1177 index_of_comma = i;1178 break;1179 }1180 }1181 if (count!==0){1182 INCOMPLETE_STATEMENT = true;1183 return false;1184 }1185 if (index_of_comma!==-1){1186 var tl1 = tl.slice(0,index_of_comma);1187 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1188 var index_of_tl1 = TREE_INDEX;1189 TREE_addNode(tree,"value","");1190 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&var_value(tree,tl2);1191 }1192 else{1193 var index_of_tl = TREE_INDEX;1194 TREE_addNode(tree,"value","");1195 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl),tl);1196 }1197}1198func_assign = function(tree,tl){1199 if (INCOMPLETE_STATEMENT===true){1200 return false;1201 }1202 var length_of_tl = len(tl);1203 if (((4<=length_of_tl && term(tl[0]["TOKEN_STRING"],"def")) && term(tl[1]["TOKEN_STRING"],"("))){1204 var index_of_right = -1;1205 var count = 0;1206 var i = 0;1207 for ( ; i<length_of_tl ; i = i+1){1208 if (term(tl[i]["TOKEN_STRING"],"(")){1209 count = count+1;1210 }1211 if (term(tl[i]["TOKEN_STRING"],")")){1212 count = count-1;1213 if (count===0){1214 index_of_right = i;1215 break;1216 }1217 }1218 }1219 if (index_of_right===-1){1220 INCOMPLETE_STATEMENT = true;1221 console.log("INCOMPLETE_STATEMENT func_assign\n");1222 process.exit(0);1223 }1224 else{1225 TREE_addNode(tree,"def","");1226 var index = TREE_INDEX;1227 TREE_addNode(tree,"params","");1228 var params_tl = {};1229 if (index_of_right!==2){1230 params_tl = tl.slice(2,index_of_right);1231 }1232 else{1233 params_tl = {};1234 var add_token = Token_init();1235 add_token["TOKEN_CLASS"] = "id";1236 add_token["TOKEN_STRING"] = "none";1237 params_tl.append(add_token);1238 }1239 return params(TREE_getTreeAccordingToIndex(tree,index),params_tl);1240 }1241 }1242 return false;1243}1244return_stm = function(tree,tl){1245 if (INCOMPLETE_STATEMENT===true){1246 return false;1247 }1248 var length_of_tl = len(tl);1249 if ((2<=length_of_tl && term(tl[0]["TOKEN_STRING"],"return"))){1250 var index1 = TREE_INDEX;1251 TREE_addNode(tree,"return","");1252 var index2 = TREE_INDEX;1253 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index1),"value","");1254 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(1,length_of_tl));1255 }1256 return false;1257}1258func_value = function(tree,tl){1259 if (INCOMPLETE_STATEMENT===true){1260 return false;1261 }1262 var length_of_tl = len(tl);1263 if ((term(tl[0]["TOKEN_STRING"],"def") && term(tl[length_of_tl-1]["TOKEN_STRING"],"end"))){1264 tree["name"] = "func_value";1265 tree["token_class"] = "";1266 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1267 if (index_of_then===-1){1268 INCOMPLETE_STATEMENT = true;1269 return false;1270 }1271 func_assign(tree,tl.slice(0,index_of_then+1));1272 var walley_statements_index = TREE_INDEX;1273 TREE_addNode(tree,"walley_statements","");1274 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1275 }1276 return false;1277}1278params = function(tree,tl){1279 if (INCOMPLETE_STATEMENT===true){1280 return false;1281 }1282 if (len(tl)===0){1283 return true;1284 }1285 var length_of_tl = len(tl);1286 var index_of_comma = -1;1287 var count = 0;1288 var i = 0;1289 for (i = 0 ; i<length_of_tl ; i = i+1){1290 if (term(tl[i]["TOKEN_STRING"],"(")){1291 count = count+1;1292 continue;1293 }1294 if (term(tl[i]["TOKEN_STRING"],")")){1295 count = count-1;1296 continue;1297 }1298 if ((count===0 && term(tl[i]["TOKEN_STRING"],","))){1299 index_of_comma = i;1300 break;1301 }1302 }1303 if (index_of_comma===-1){1304 if (assignment(tree,tl)===true){1305 return true;1306 }1307 else{1308 var index = TREE_INDEX;1309 TREE_addNode(tree,"value","");1310 return value(TREE_getTreeAccordingToIndex(tree,index),tl);1311 }1312 }1313 else{1314 var tl1 = tl.slice(0,index_of_comma);1315 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1316 if (assignment(tree,tl1)===true){1317 return params(tree,tl2);1318 }1319 else{1320 var index_of_tl1 = TREE_INDEX;1321 TREE_addNode(tree,"value","");1322 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&params(tree,tl2);1323 }1324 }1325}1326func = function(tree,tl){1327 if (INCOMPLETE_STATEMENT===true){1328 return false;1329 }1330 var length_of_tl = len(tl);1331 var index_of_left = TL_indexOfTokenThatHasTokenString(tl,"(");1332 var index_of_right = -1;1333 if (index_of_left===-1){1334 return false;1335 }1336 var i = 0;1337 var count = 0;1338 for ( ; i<length_of_tl ; i = i+1){1339 if (term(tl[i]["TOKEN_STRING"],"(")){1340 count = count+1;1341 }1342 else if (term(tl[i]["TOKEN_STRING"],")")){1343 count = count-1;1344 if (count===0){1345 index_of_right = i;1346 break;1347 }1348 }1349 }1350 if (index_of_right===-1){1351 INCOMPLETE_STATEMENT = true;1352 return false;1353 }1354 if (((index_of_right+1!==length_of_tl || index_of_left===-1) || index_of_left===0)){1355 return false;1356 }1357 else{1358 var test_id = tl.slice(0,index_of_left);1359 var params_tl = {};1360 if (index_of_left+1===index_of_right){1361 params_tl = {};1362 }1363 else{1364 params_tl = tl.slice(index_of_left+1,index_of_right);1365 }1366 var length_of_test_id = len(test_id);1367 if ((length_of_test_id!==1 || test_id[0]["TOKEN_CLASS"]!=="id")){1368 return false;1369 }1370 tree["name"] = "func";1371 tree["token_class"] = "";1372 TREE_addNode(tree,"","call");1373 TREE_addNode(TREE_getTreeAccordingToIndex(tree,TREE_INDEX-1),toString(test_id[0]["TOKEN_STRING"]),"string");1374 var index = TREE_INDEX;1375 TREE_addNode(tree,"params","");1376 return params(TREE_getTreeAccordingToIndex(tree,index),params_tl);1377 }1378}1379relation = function(tree,tl){1380 if (INCOMPLETE_STATEMENT===true){1381 return false;1382 }1383 var length_of_tl = len(tl);1384 var i = length_of_tl-1;1385 var count = 0;1386 var index_of_and_or = -1;1387 for ( ; 0<=i ; i = i-1){1388 if (term(tl[i]["TOKEN_STRING"],"(")){1389 count = count+1;1390 continue;1391 }1392 if (term(tl[i]["TOKEN_STRING"],")")){1393 count = count-1;1394 continue;1395 }1396 if (((count===0 && term(tl[i]["TOKEN_CLASS"],"relation")) && tl[i]["TOKEN_STRING"]!=="not")){1397 index_of_and_or = i;1398 var and_or_string = tl[i]["TOKEN_STRING"];1399 var tl1 = tl.slice(0,index_of_and_or);1400 var tl2 = tl.slice(index_of_and_or+1,length_of_tl);1401 var index = TREE_INDEX;1402 TREE_addNode(tree,and_or_string,"");1403 var index1 = TREE_INDEX;1404 TREE_addNodeAtIndex(tree,index,"relation","");1405 var index2 = TREE_INDEX;1406 TREE_addNodeAtIndex(tree,index,"relation","");1407 return relation(TREE_getTreeAccordingToIndex(tree,index1),tl1)&&relation(TREE_getTreeAccordingToIndex(tree,index2),tl2);1408 }1409 }1410 if (term(tl[0]["TOKEN_STRING"],"not")){1411 TREE_addNode(tree,"not","");1412 var index = TREE_INDEX;1413 TREE_addNodeAtIndex(tree,index-1,"relation","");1414 return relation(TREE_getTreeAccordingToIndex(tree,index),tl.slice(1,length_of_tl));1415 }1416 return simple_relation(tree,tl);1417}1418simple_relation = function(tree,tl){1419 if (INCOMPLETE_STATEMENT===true){1420 return false;1421 }1422 var length_of_tl = len(tl);1423 if ((term("(",tl[0]["TOKEN_STRING"]) && term(")",tl[length_of_tl-1]["TOKEN_STRING"]))){1424 return relation(tree,tl.slice(1,length_of_tl-1));1425 }1426 else{1427 tree["name"] = "simple_relation";1428 var index_of_judge_sign = TL_indexOfTokenThatHasTokenClass(tl,"judge_sign");1429 if (index_of_judge_sign===-1){1430 return expr(tree,tl);1431 }1432 var tl1 = tl.slice(0,index_of_judge_sign);1433 var tl2 = tl.slice(index_of_judge_sign+1,length_of_tl);1434 var judge_sign = tl[index_of_judge_sign]["TOKEN_STRING"];1435 if ((term(">=",judge_sign) || term(">",judge_sign))){1436 var temp_tl = tl1;1437 tl1 = tl2;1438 tl2 = temp_tl;1439 if (term(">=",judge_sign)){1440 judge_sign = "<=";1441 }1442 else{1443 judge_sign = "<";1444 }1445 }1446 var index = TREE_INDEX;1447 TREE_addNode(tree,judge_sign,"");1448 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);1449 var index1 = TREE_INDEX;1450 TREE_addNode(temp_tree,"value","");1451 var index2 = TREE_INDEX;1452 TREE_addNode(temp_tree,"value","");1453 return value(TREE_getTreeAccordingToIndex(tree,index1),tl1)&&value(TREE_getTreeAccordingToIndex(tree,index2),tl2);1454 }1455 return false;1456}1457if_stms = function(tree,tl){1458 if (INCOMPLETE_STATEMENT===true){1459 return false;1460 }1461 var length_of_tl = len(tl);1462 if (term(tl[0]["TOKEN_STRING"],"if")){1463 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1464 if (index_of_then===-1){1465 INCOMPLETE_STATEMENT = true;1466 return false;1467 }1468 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1469 var relation_tl = tl.slice(1,index_of_then);1470 TREE_addNode(tree,"if","");1471 var index = TREE_INDEX;1472 TREE_addNode(tree,"relation","");1473 var walley_statements_index = TREE_INDEX;1474 TREE_addNode(tree,"walley_statements","");1475 return relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl)&&walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1));1476 }1477 else{1478 INCOMPLETE_STATEMENT = true;1479 return false;1480 }1481 }1482 return false;1483}1484elif_stms = function(tree,tl){1485 if (INCOMPLETE_STATEMENT===true){1486 return false;1487 }1488 var length_of_tl = len(tl);1489 if (term(tl[0]["TOKEN_STRING"],"elif")){1490 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1491 if (index_of_then===-1){1492 INCOMPLETE_STATEMENT = true;1493 return false;1494 }1495 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1496 var relation_tl = tl.slice(1,index_of_then);1497 TREE_addNode(tree,"elif","");1498 var index = TREE_INDEX;1499 TREE_addNode(tree,"relation","");1500 var walley_statements_index = TREE_INDEX;1501 TREE_addNode(tree,"walley_statements","");1502 return relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl)&&walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1));1503 }1504 else{1505 INCOMPLETE_STATEMENT = true;1506 return false;1507 }1508 }1509 return false;1510}1511else_stms = function(tree,tl){1512 if (INCOMPLETE_STATEMENT===true){1513 return false;1514 }1515 var length_of_tl = len(tl);1516 if (term(tl[0]["TOKEN_STRING"],"else")){1517 if (term(tl[length_of_tl-1]["TOKEN_STRING"],"end")){1518 TREE_addNode(tree,"else","");1519 var walley_statements_index = TREE_INDEX;1520 TREE_addNode(tree,"walley_statements","");1521 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(1,length_of_tl-1));1522 }1523 else{1524 INCOMPLETE_STATEMENT = true;1525 return false;1526 }1527 }1528 return false;1529}1530while_stms = function(tree,tl){1531 if (INCOMPLETE_STATEMENT===true){1532 return false;1533 }1534 var length_of_tl = len(tl);1535 if (term(tl[0]["TOKEN_STRING"],"while")){1536 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1537 if (index_of_then===-1){1538 INCOMPLETE_STATEMENT = true;1539 return false;1540 }1541 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1542 var relation_tl = tl.slice(1,index_of_then);1543 TREE_addNode(tree,"while","");1544 var index = TREE_INDEX;1545 TREE_addNode(tree,"relation","");1546 var walley_statements_index = TREE_INDEX;1547 TREE_addNode(tree,"walley_statements","");1548 return (relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1549 }1550 else{1551 INCOMPLETE_STATEMENT = true;1552 return false;1553 }1554 }1555 return false;1556}1557for_stms = function(tree,tl){1558 if (term(tl[0]["TOKEN_STRING"],"for")===false){1559 return false;1560 }1561 if (INCOMPLETE_STATEMENT===true){1562 return false;1563 }1564 var length_of_tl = len(tl);1565 if ((term(tl[4]["TOKEN_STRING"],"in") || term(tl[2]["TOKEN_STRING"],"in"))){1566 var index_of_then = -1;1567 var i = 0;1568 for ( ; i<length_of_tl ; i = i+1){1569 if (term(tl[i]["TOKEN_STRING"],"then")){1570 index_of_then = i;1571 break;1572 }1573 }1574 TREE_addNode(tree,"foreach","");1575 if (term(tl[1]["TOKEN_CLASS"],"id")===false){1576 Walley_Print_Error(TL_toString(tl),"for each statements error, for i,v in value, i,v must be id",tl[1]["TOKEN_START"]);1577 }1578 TREE_addNode(tree,tl[1]["TOKEN_STRING"],"foreach_index");1579 if (term(tl[2]["TOKEN_STRING"],",")){1580 if (term(tl[3]["TOKEN_CLASS"],"id")===false){1581 Walley_Print_Error(TL_toString(tl),"for each statements error, for i,v in value, i,v must be id",tl[3]["TOKEN_START"]);1582 }1583 TREE_addNode(tree,tl[3]["TOKEN_STRING"],"foreach_value");1584 var index = TREE_INDEX;1585 TREE_addNode(tree,"","foreach_in");1586 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"value","");1587 index = index+1;1588 value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(5,index_of_then));1589 }1590 else{1591 TREE_addNode(tree,"","foreach_value");1592 var index = TREE_INDEX;1593 TREE_addNode(tree,"","foreach_in");1594 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"value","");1595 index = index+1;1596 value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(3,index_of_then));1597 }1598 var walley_statements_index = TREE_INDEX;1599 TREE_addNode(tree,"walley_statements","");1600 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1601 }1602 var num_of_comma = 0;1603 var count_of_p = 0;1604 var index_of_comma = {0:-1,1:-1,2:-1};1605 var index = 0;1606 var i = 0;1607 var index_of_then = -1;1608 for ( ; i<length_of_tl ; i = i+1){1609 if (term(tl[i]["TOKEN_STRING"],"then")){1610 index_of_then = i;1611 break;1612 }1613 if (term(tl[i]["TOKEN_STRING"],"(")){1614 count_of_p = count_of_p+1;1615 continue;1616 }1617 if (term(tl[i]["TOKEN_STRING"],")")){1618 count_of_p = count_of_p-1;1619 continue;1620 }1621 if ((count_of_p===0 && term(tl[i]["TOKEN_STRING"],","))){1622 if (index<2){1623 index_of_comma[index] = i;1624 index = index+1;1625 }1626 num_of_comma = num_of_comma+1;1627 }1628 }1629 if ((index_of_then===-1 || term(tl[length_of_tl-1]["TOKEN_STRING"],"end")===false)){1630 INCOMPLETE_STATEMENT = true;1631 return false;1632 }1633 if (((length_of_tl!==2 && num_of_comma!==0) && num_of_comma<=2)){1634 if (num_of_comma===1){1635 var simple_relation_tl = tl.slice(1,index_of_comma[0]);1636 var assignment_tl = tl.slice(index_of_comma[0]+1,index_of_then);1637 TREE_addNode(tree,"for","");1638 var index_of_sr = TREE_INDEX;1639 TREE_addNode(tree,"simple_relation","");1640 var index_of_a = TREE_INDEX;1641 TREE_addNode(tree,"assignment","");1642 var walley_statements_index = TREE_INDEX;1643 TREE_addNode(tree,"walley_statements","");1644 return ((simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a),assignment_tl)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1645 }1646 else{1647 if (term(tl[1]["TOKEN_STRING"],",")){1648 var simple_relation_tl = tl.slice(2,index_of_comma[1]);1649 var assignment_tl = tl.slice(index_of_comma[1]+1,index_of_then);1650 TREE_addNode(tree,"for","");1651 var index_of_sr = TREE_INDEX;1652 TREE_addNode(tree,"simple_relation","");1653 var index_of_a = TREE_INDEX;1654 TREE_addNode(tree,"assignment","");1655 var walley_statements_index = TREE_INDEX;1656 TREE_addNode(tree,"walley_statements","");1657 return ((simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a),assignment_tl)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1658 }1659 else{1660 var assignment_tl1 = tl.slice(1,index_of_comma[0]);1661 var simple_relation_tl = tl.slice(index_of_comma[0]+1,index_of_comma[1]);1662 var assignment_tl2 = tl.slice(index_of_comma[1]+1,index_of_then);1663 TREE_addNode(tree,"for","");1664 var index_of_a_tl1 = TREE_INDEX;1665 TREE_addNode(tree,"assignment","");1666 var index_of_sr = TREE_INDEX;1667 TREE_addNode(tree,"simple_relation","");1668 var index_of_a_tl2 = TREE_INDEX;1669 TREE_addNode(tree,"assignment","");1670 var walley_statements_index = TREE_INDEX;1671 TREE_addNode(tree,"walley_statements","");1672 return (((assignment(TREE_getTreeAccordingToIndex(tree,index_of_a_tl1),assignment_tl1) && simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl)) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a_tl2),assignment_tl2)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1673 }1674 }1675 }1676 return false;1677}1678func_stms = function(tree,tl){1679 if (INCOMPLETE_STATEMENT===true){1680 return false;1681 }1682 var length_of_tl = len(tl);1683 if (term(tl[0]["TOKEN_STRING"],"def")){1684 if ((2<length_of_tl && term(tl[length_of_tl-1]["TOKEN_STRING"],"then"))){1685 TREE_addNode(tree,"def","");1686 var func_tl = tl.slice(1,length_of_tl-1);1687 var index = TREE_INDEX;1688 TREE_addNode(tree,"func","");1689 return func(TREE_getTreeAccordingToIndex(tree,index),func_tl)&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1690 }1691 else{1692 INCOMPLETE_STATEMENT = true;1693 return false;1694 }1695 }1696 return false;1697}1698end_stm = function(tree,tl){1699 if (INCOMPLETE_STATEMENT===true){1700 return false;1701 }1702 if ((len(tl)===1 && term(tl[0]["TOKEN_CLASS"],"end"))){1703 TREE_addNode(tree,"end","");1704 return true;1705 }1706 return false;1707}1708def_stms = function(tree,tl){1709 if (INCOMPLETE_STATEMENT===true){1710 return false;1711 }1712 var length_of_tl = len(tl);1713 if ((term(tl[0]["TOKEN_STRING"],"def") && term(tl[1]["TOKEN_STRING"],"(")===false)){1714 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1715 var index_of_left_bracket = TL_indexOfTokenThatHasTokenString(tl,"(");1716 if (index_of_then===-1){1717 INCOMPLETE_STATEMENT = true;1718 return false;1719 }1720 if (term(tl[length_of_tl-1]["TOKEN_STRING"],"end")===false){1721 INCOMPLETE_STATEMENT = true;1722 return false;1723 }1724 var new_tl = {};1725 var begin = 1;1726 var i = 0;1727 for ( ; i<index_of_left_bracket ; i = i+1){1728 if (begin<=i){1729 new_tl.append(tl[i]);1730 }1731 }1732 var add_token = Token_init();1733 add_token["TOKEN_STRING"] = "=";1734 add_token["TOKEN_CLASS"] = "assignment_operator";1735 new_tl.append(add_token);1736 i = 0;1737 for (i = 0 ; i<length_of_tl ; i = i+1){1738 if ((begin<=i && i<index_of_left_bracket)){1739 continue;1740 }1741 new_tl.append(tl[i]);1742 }1743 return assignment(tree,new_tl);1744 }1745 else{1746 return false;1747 }1748}1749self_operator_stm = function(tree,tl){1750 if (INCOMPLETE_STATEMENT===true){1751 return false;1752 }1753 var length_of_tl = len(tl);1754 if (tl[length_of_tl-1]["TOKEN_CLASS"]==="self_operator"){1755 var index = TREE_INDEX;1756 TREE_addNode(tree,"self_operator_stm","");1757 var valid_var_name = var_name(TREE_getTreeAccordingToIndex(tree,index),tl.slice(0,length_of_tl-1));1758 if (valid_var_name===true){1759 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),tl[length_of_tl-1]["TOKEN_STRING"],"self_operator");1760 return true;1761 }1762 else{1763 console.log("Error.. invalid self operation\n");1764 process.exit(0);1765 }1766 }1767 else{1768 return false;1769 }1770}1771self_assignment_stm = function(tree,tl){1772 if (INCOMPLETE_STATEMENT===true){1773 return false;1774 }1775 var length_of_tl = len(tl);1776 var index_of_self_assignment_operator = TL_indexOfTokenThatHasTokenClass(tl,"self_assignment");1777 if (index_of_self_assignment_operator===-1){1778 return false;1779 }1780 else{1781 var var_name_tl = tl.slice(0,index_of_self_assignment_operator);1782 var var_value_tl = tl.slice(index_of_self_assignment_operator+1,length_of_tl);1783 var temp_tree = TREE_init("self_assignment_stm");1784 var valid_var_name = var_name(temp_tree,var_name_tl);1785 if (valid_var_name===false){1786 return false;1787 }1788 TREE_addNode(temp_tree,tl[index_of_self_assignment_operator]["TOKEN_STRING"],"self_assignment");1789 var index2 = TREE_INDEX;1790 TREE_addNode(temp_tree,"","value");1791 var valid_var_value = value(TREE_getTreeAccordingToIndex(temp_tree,index2),var_value_tl);1792 if (valid_var_value===false){1793 return false;1794 }1795 else{1796 TREE_addTree(tree,temp_tree);1797 return true;1798 }1799 }1800}1801import_stm = function(tree,tl){1802 if (INCOMPLETE_STATEMENT===true){1803 return false;1804 }1805 if (tl[0]["TOKEN_CLASS"]==="import"){1806 TREE_addNode(tree,"import","");1807 var index = TREE_INDEX;1808 var length_of_tl = len(tl);1809 if ((length_of_tl!==2 || tl[1]["TOKEN_CLASS"]!=="string")){1810 console.log("Error.. only support import statements like 'import \" hello.wy \"'");1811 process.exit(0);1812 }1813 TREE_addNode(tree,tl[1]["TOKEN_STRING"],"import_file");1814 return true;1815 }1816 else{1817 return false;1818 }1819}1820statements = function(tree,tl){1821 if (INCOMPLETE_STATEMENT===true){1822 return false;1823 }1824 return (((((((((import_stm(tree,tl) || return_stm(tree,tl)) || if_stms(tree,tl)) || elif_stms(tree,tl)) || else_stms(tree,tl)) || while_stms(tree,tl)) || for_stms(tree,tl)) || def_stms(tree,tl)) || end_stm(tree,tl)) || assignment(tree,tl))||value(tree,tl);1825}1826walley_statements = function(tree,tl){1827 if (INCOMPLETE_STATEMENT===true){1828 return false;1829 }1830 var temp_tl = {val:{}};1831 var begin = {val:0};1832 while (sentences_separation(tl,temp_tl,begin)===true){1833 if (INCOMPLETE_STATEMENT===true){1834 return false;1835 }1836 var index = TREE_INDEX;1837 TREE_addNode(tree,"statements","");1838 if (statements(TREE_getTreeAccordingToIndex(tree,index),temp_tl["val"])===false){1839 console.log("Walley Statements Parse Error\n");1840 return false;1841 }1842 }1843 if (INCOMPLETE_STATEMENT===true){1844 return false;1845 }1846 return true;1847}1848sentences_separation = function(tl,output_tl,begin){1849 var length_of_tl = len(tl);1850 if (length_of_tl<=begin["val"]){1851 return false;1852 }1853 i = begin["val"];1854 var count_of_parenthesis = 0;1855 for ( ; i<length_of_tl ; i = i+1){1856 if (tl[i]["TOKEN_STRING"]==="("){1857 count_of_parenthesis++;1858 }1859 if (tl[i]["TOKEN_STRING"]===")"){1860 count_of_parenthesis--;1861 }1862 if ((((count_of_parenthesis===0 && i<length_of_tl-1) && (((((term(tl[i]["TOKEN_CLASS"],"num") || term(tl[i]["TOKEN_CLASS"],"string")) || term(tl[i]["TOKEN_CLASS"],"id")) || term(tl[i]["TOKEN_CLASS"],"list_table")) || term(tl[i]["TOKEN_STRING"],")")) || term(tl[i]["TOKEN_CLASS"],"self_operator"))) && ((((((term(tl[1+i]["TOKEN_CLASS"],"id") || term(tl[1+i]["TOKEN_CLASS"],"num")) || term(tl[i+1]["TOKEN_CLASS"],"return")) || term(tl[i+1]["TOKEN_STRING"],"continue")) || term(tl[1+i]["TOKEN_STRING"],"break")) || term(tl[1+i]["TOKEN_CLASS"],"local")) || term(tl[i+1]["TOKEN_CLASS"],"import")))){1863 var end_index = i+1;1864 var ahead_tl = tl.slice(begin["val"],end_index);1865 output_tl["val"] = ahead_tl;1866 begin["val"] = end_index;1867 return true;1868 }1869 if ((count_of_parenthesis===0 && ((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"while")))){1870 if (begin["val"]!==i){1871 if ((term(tl[i]["TOKEN_STRING"],"def") && term(tl[i+1]["TOKEN_STRING"],"("))){1872 console.log("");1873 }1874 else{1875 var end_index = i;1876 var ahead_tl = tl.slice(begin["val"],end_index);1877 begin["val"] = end_index;1878 output_tl["val"] = ahead_tl;1879 return true;1880 }1881 }1882 var count = 0;1883 for ( ; i<length_of_tl ; i = i+1){1884 if ((((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"while"))){1885 count = count+1;1886 }1887 if (term(tl[i]["TOKEN_STRING"],"end")){1888 count = count-1;1889 }1890 if (count===0){1891 break;1892 }1893 }1894 if (count===0){1895 var end_index = i+1;1896 var ahead_tl = tl.slice(begin["val"],end_index);1897 output_tl["val"] = ahead_tl;1898 begin["val"] = end_index;1899 return true;1900 }1901 else{1902 INCOMPLETE_STATEMENT = true;1903 return false;1904 }1905 }1906 if (term(tl[i]["TOKEN_STRING"],"if")){1907 if (begin["val"]!==i){1908 var end_index = i;1909 var ahead_tl = tl.slice(begin["val"],end_index);1910 begin["val"] = end_index;1911 output_tl["val"] = ahead_tl;1912 return true;1913 }1914 var count_of_if = 0;1915 var count_of_end = 0;1916 for ( ; i<length_of_tl ; i = i+1){1917 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1918 count_of_if = count_of_if+1;1919 count_of_end = count_of_end+1;1920 }1921 if (term(tl[i]["TOKEN_STRING"],"end")){1922 count_of_if = count_of_if-1;1923 count_of_end = count_of_end-1;1924 }1925 if (count_of_end===0){1926 break;1927 }1928 if ((count_of_if===1 && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){1929 var end_index = i;1930 var ahead_tl = tl.slice(begin["val"],end_index);1931 var end_token = Token_init();1932 end_token["TOKEN_STRING"] = "end";1933 end_token["TOKEN_CLASS"] = "end";1934 ahead_tl.append(end_token);1935 begin["val"] = end_index;1936 output_tl["val"] = ahead_tl;1937 return true;1938 }1939 }1940 if ((count_of_if!==count_of_end || count_of_if!==0)){1941 INCOMPLETE_STATEMENT = true;1942 return false;1943 }1944 else{1945 var end_index = i+1;1946 var ahead_tl = tl.slice(begin["val"],end_index);1947 begin["val"] = end_index-1;1948 output_tl["val"] = ahead_tl;1949 return true;1950 }1951 }1952 if (term(tl[i]["TOKEN_STRING"],"elif")){1953 var count_of_if = 0;1954 var count_of_end = 0;1955 var temp_i = i;1956 for ( ; i<length_of_tl ; i = i+1){1957 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1958 count_of_if = count_of_if+1;1959 count_of_end = count_of_end+1;1960 }1961 if (term(tl[i]["TOKEN_STRING"],"end")){1962 count_of_end = count_of_end-1;1963 count_of_if = count_of_if-1;1964 }1965 if (((count_of_if===0 && i!==temp_i) && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){1966 var end_index = i;1967 var ahead_tl = tl.slice(begin["val"],end_index);1968 var end_token = Token_init();1969 end_token["TOKEN_STRING"] = "end";1970 end_token["TOKEN_CLASS"] = "end";1971 ahead_tl.append(end_token);1972 begin["val"] = end_index;1973 output_tl["val"] = ahead_tl;1974 return true;1975 }1976 if ((count_of_end===-1 && count_of_if===-1)){1977 var end_index = i+1;1978 var ahead_tl = tl.slice(begin["val"],end_index);1979 begin["val"] = end_index-1;1980 output_tl["val"] = ahead_tl;1981 return true;1982 }1983 }1984 INCOMPLETE_STATEMENT = true;1985 return false;1986 }1987 if (term(tl[i]["TOKEN_STRING"],"else")){1988 var count_of_if = 0;1989 var count_of_end = 0;1990 var temp_i = i;1991 for ( ; i<length_of_tl ; i = i+1){1992 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1993 count_of_if = count_of_if+1;1994 count_of_end = count_of_end+1;1995 }1996 if (term(tl[i]["TOKEN_STRING"],"end")){1997 count_of_if = count_of_if-1;1998 count_of_end = count_of_end-1;1999 }2000 if (((count_of_if===0 && i!==temp_i) && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){2001 Walley_Print_Error(TL_toString(temp_tl),"elif or else statements error",tl[i]["TOKEN_START"]);2002 }2003 if (count_of_end===-1){2004 var end_index = i+1;2005 var ahead_tl = tl.slice(begin["val"],end_index);2006 begin["val"] = end_index-1;2007 output_tl["val"] = ahead_tl;2008 return true;2009 }2010 }2011 INCOMPLETE_STATEMENT = true;2012 return false;2013 }2014 if ((count_of_parenthesis===0 && term(tl[i]["TOKEN_STRING"],"end"))){2015 var end_index = i;2016 if (begin["val"]<i){2017 var ahead_tl = tl.slice(begin["val"],end_index);2018 begin["val"] = end_index;2019 output_tl["val"] = ahead_tl;2020 return true;2021 }2022 else{2023 begin["val"] = end_index;2024 }2025 end_index = i+1;2026 var ahead_tl = tl.slice(begin["val"],end_index);2027 begin["val"] = end_index;2028 output_tl["val"] = ahead_tl;2029 return true;2030 }2031 }2032 if (begin["val"]<length_of_tl){2033 var ahead_tl = tl.slice(begin["val"],length_of_tl);2034 begin["val"] = length_of_tl;2035 output_tl["val"] = ahead_tl;2036 return true;2037 }2038 return false;2039}2040parser = function(tl){2041 TREE_INDEX = 0;2042 var output_tree = TREE_init("walley_statements");2043 if (len(tl)===0){2044 return output_tree;2045 }2046 if ((walley_statements(output_tree,tl)===false && INCOMPLETE_STATEMENT===false)){2047 console.log("Fail to parse statements\n");2048 }2049 return output_tree;2050}2051ism_operator = function(input_str){2052 if ((((((term(input_str,"+") || term(input_str,"-")) || term(input_str,"*")) || term(input_str,"/")) || term(input_str,"^")) || term(input_str,"%"))){2053 return true;2054 }2055 return false;2056}2057Walley_Calculation = function(value1,value2,sign){2058 if ((value1[0]!=="\"" && value2[0]!=="\"")){2059 if (sign==="^"){2060 return eval("Math.pow("+value1+","+value2+")");2061 }2062 return eval(value1+sign+value2);2063 }2064 else{2065 var value1IsString = false;2066 var value2IsString = false;2067 if (value1[0]==="\""){2068 value1 = value1.slice(1,len(value1)-1);2069 value1IsString = true;2070 }2071 if (value2[0]==="\""){2072 value2 = value2.slice(1,len(value2)-1);2073 value2IsString = true;2074 }2075 if (sign[0]==="+"){2076 var output_str = "\""+value1+value2+"\"";2077 return output_str;2078 }2079 else if (sign[0]==="*"){2080 if ((value1IsString===true && value2IsString===true)){2081 console.log("Error.. Can not multiply two string %s and %s\n",value1,value2);2082 process.exit(0);2083 }2084 else{2085 var num = 0;2086 var mult_str = "";2087 if (value1IsString===true){2088 mult_str = value1;2089 num = parseInt(value2);2090 }2091 else{2092 mult_str = value2;2093 num = parseInt(value1);2094 }2095 var output_str = "\"";2096 var i = 0;2097 for ( ; i<num ; i = i+1){2098 output_str = output_str+mult_str;2099 }2100 output_str = output_str+"\"";2101 return output_str;2102 }2103 }2104 else{2105 console.log("Error.. Sign %s can not be used for string calculation for %s and %s\n",sign,value1,value2);2106 process.exit(0);2107 }2108 }2109}2110appendSpacesAhead = function(input_str,num){2111 for (i = 0 ; i<num ; i = i+1){2112 input_str = " "+input_str;2113 }2114 return input_str;2115}2116isString = function(input_str){2117 if ((input_str[0]!=="\"" || input_str[input_str["length"]-1]!=="\"")){2118 return false;2119 }2120 var count = 0;2121 var i = 0;2122 var length = input_str["length"];2123 for ( ; i<length ; i = i+1){2124 if (input_str[i]==="\""){2125 count = count+1;2126 }2127 }2128 if (count!==2){2129 return false;2130 }2131 else{2132 return true;2133 }2134}2135js_isTableValue = false;2136Code_Generation_2_Javascript = function(sl,tree){2137 if (term(tree["token_class"],"id")){2138 if (term(tree["name"],"continue")){2139 return "continue;";2140 }2141 if (term(tree["name"],"break")){2142 return "break;";2143 }2144 if (term(tree["name"],"none")){2145 return "null";2146 }2147 return tree["name"];2148 }2149 else if (term(tree["name"],"walley_statements")){2150 var nl = tree["node_list"];2151 var output_str = "";2152 var i = 0;2153 var length_of_nl = len(nl);2154 for (i = 0 ; i<length_of_nl ; i = i+1){2155 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2156 if (len(temp_str)!==0){2157 temp_str = appendSpacesAhead(temp_str,BEAUTIFUL_SPACES);2158 output_str = output_str+temp_str;2159 if (output_str[len(output_str)-1]!=="\n"){2160 if (output_str[len(output_str)-1]!==";"){2161 output_str = output_str+";\n";2162 }2163 else{2164 output_str = output_str+"\n";2165 }2166 }2167 }2168 }2169 return output_str;2170 }2171 else if (term(tree["name"],"statements")){2172 nl = tree["node_list"];2173 if (term(nl[0]["name"],"if")){2174 var append_str = "if (";2175 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2176 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2177 append_str = append_str+judge_str;2178 append_str = append_str+"){\n";2179 var i = 2;2180 var length_of_nl = len(nl);2181 var output_str = "";2182 for (i = 2 ; i<length_of_nl ; i = i+1){2183 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2184 if (len(temp_str)!==0){2185 output_str = output_str+temp_str;2186 if (output_str[len(output_str)-1]!=="\n"){2187 if (output_str[len(output_str)-1]!==";"){2188 output_str = output_str+";\n";2189 }2190 else{2191 output_str = output_str+"\n";2192 }2193 }2194 }2195 }2196 append_str = append_str+output_str;2197 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2198 return append_str;2199 }2200 else if (term(nl[0]["name"],"elif")){2201 var append_str = "}\n";2202 append_str = appendSpacesAhead(append_str,BEAUTIFUL_SPACES-4);2203 append_str = append_str+appendSpacesAhead("else if (",BEAUTIFUL_SPACES);2204 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2205 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2206 append_str = append_str+judge_str;2207 append_str = append_str+"){\n";2208 var i = 2;2209 var length_of_nl = len(nl);2210 var output_str = "";2211 for (i = 2 ; i<length_of_nl ; i = i+1){2212 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2213 if (len(temp_str)!==0){2214 output_str = output_str+temp_str;2215 if (output_str[len(output_str)-1]!=="\n"){2216 if (output_str[len(output_str)-1]!==";"){2217 output_str = output_str+";\n";2218 }2219 else{2220 output_str = output_str+"\n";2221 }2222 }2223 }2224 }2225 append_str = append_str+output_str;2226 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2227 return append_str;2228 }2229 else if (term(nl[0]["name"],"else")){2230 var append_str = "}\n";2231 append_str = appendSpacesAhead(append_str,BEAUTIFUL_SPACES-4);2232 append_str = append_str+appendSpacesAhead("else{\n",BEAUTIFUL_SPACES);2233 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2234 var i = 1;2235 var length_of_nl = len(nl);2236 var output_str = "";2237 for (i = 1 ; i<length_of_nl ; i = i+1){2238 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2239 if (len(temp_str)!==0){2240 output_str = output_str+temp_str;2241 if (output_str[len(output_str)-1]!=="\n"){2242 if (output_str[len(output_str)-1]!==";"){2243 output_str = output_str+";\n";2244 }2245 else{2246 output_str = output_str+"\n";2247 }2248 }2249 }2250 }2251 append_str = append_str+output_str;2252 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2253 return append_str;2254 }2255 else if (term(nl[0]["name"],"while")){2256 var append_str = "while (";2257 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2258 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2259 append_str = append_str+judge_str;2260 append_str = append_str+"){\n";2261 var i = 2;2262 var length_of_nl = len(nl);2263 var output_str = "";2264 for ( ; i<length_of_nl-1 ; i = i+1){2265 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2266 if (len(temp_str)!==0){2267 output_str = output_str+temp_str;2268 if (output_str[len(output_str)-1]!=="\n"){2269 if (output_str[len(output_str)-1]!==";"){2270 output_str = output_str+";\n";2271 }2272 else{2273 output_str = output_str+"\n";2274 }2275 }2276 }2277 }2278 append_str = append_str+output_str;2279 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2280 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2281 return append_str;2282 }2283 else if (term(nl[0]["name"],"for")){2284 var append_str = "for (";2285 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2286 var nl_index = 1;2287 if (term(nl[1]["name"],"assignment")){2288 append_str = append_str+Code_Generation_2_Javascript(sl,nl[1]["node_list"][0]);2289 append_str = append_str+" ; ";2290 nl_index = 2;2291 }2292 else{2293 append_str = append_str+" ; ";2294 nl_index = 1;2295 }2296 var judge_str = Code_Generation_2_Javascript(sl,nl[nl_index]);2297 append_str = append_str+judge_str;2298 append_str = append_str+" ; ";2299 nl_index = nl_index+1;2300 if (term(nl[nl_index]["name"],"assignment")){2301 append_str = append_str+Code_Generation_2_Javascript(sl,nl[nl_index]["node_list"][0]);2302 nl_index = nl_index+1;2303 }2304 append_str = append_str+"){\n";2305 var output_str = "";2306 var i = nl_index;2307 var length_of_nl = len(nl);2308 for ( ; i<length_of_nl-1 ; i = i+1){2309 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2310 if (len(temp_str)!==0){2311 output_str = output_str+temp_str;2312 if (output_str[len(output_str)-1]!=="\n"){2313 if (output_str[len(output_str)-1]!==";"){2314 output_str = output_str+";\n";2315 }2316 else{2317 output_str = output_str+"\n";2318 }2319 }2320 }2321 }2322 append_str = append_str+output_str;2323 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2324 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2325 return append_str;2326 }2327 else if (term(nl[0]["name"],"foreach")){2328 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2329 var append_str = "for(";2330 var foreach_index = nl[1]["name"];2331 append_str = append_str+foreach_index;2332 append_str = append_str+" in ";2333 var has_v = true;2334 if (term(nl[2]["name"],"")){2335 has_v = false;2336 }2337 var foreach_in_value = Code_Generation_2_Javascript(sl,nl[3]["node_list"][0]);2338 foreach_in_value = "WALLEY.stringToObject("+foreach_in_value+")";2339 append_str = append_str+foreach_in_value;2340 append_str = append_str+"){\n";2341 append_str = append_str+appendSpacesAhead("if(("+foreach_in_value+").hasOwnProperty("+foreach_index+")){\n",BEAUTIFUL_SPACES);2342 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2343 if (has_v===true){2344 var value_var_name = nl[2]["name"];2345 append_str = append_str+appendSpacesAhead(value_var_name,BEAUTIFUL_SPACES)+"=";2346 var in_value = "("+foreach_in_value+")";2347 var in_value_and_key = in_value+"["+foreach_index+"]";2348 append_str = append_str+in_value_and_key;2349 append_str = append_str+";\n";2350 }2351 var i = 4;2352 var length_of_nl = len(nl);2353 var output_str = "";2354 for ( ; i<length_of_nl-1 ; i = i+1){2355 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2356 if (len(temp_str)!==0){2357 output_str = output_str+temp_str;2358 if (output_str[len(output_str)-1]!=="\n"){2359 if (output_str[len(output_str)-1]!==";"){2360 output_str = output_str+";\n";2361 }2362 else{2363 output_str = output_str+"\n";2364 }2365 }2366 }2367 }2368 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2369 append_str = append_str+output_str;2370 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2371 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2372 append_str = append_str+appendSpacesAhead("};\n",BEAUTIFUL_SPACES);2373 return append_str;2374 }2375 else if (nl[0]["name"]==="import"){2376 var import_file = nl[1]["name"];2377 import_file = import_file.slice(1,import_file["length"]-1);2378 var fs = require("fs");2379 var content_in_import_file = fs.readFileSync(import_file,"utf8");2380 var output_str = exports.Code_Generation(content_in_import_file);2381 if (exports["INCOMPLETE_STATEMENT"]===true){2382 console.log("Error.. statements in file %s is incomplete\n",import_file);2383 process.exit(0);2384 }2385 return output_str;2386 }2387 else{2388 var append_str = "";2389 var i = 0;2390 var length_of_nl = len(nl);2391 var output_str = "";2392 for ( ; i<length_of_nl ; i = i+1){2393 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2394 if (len(temp_str)!==0){2395 output_str = output_str+temp_str;2396 if (output_str[len(output_str)-1]!=="\n"){2397 if (output_str[len(output_str)-1]!==";"){2398 output_str = output_str+";\n";2399 }2400 else{2401 output_str = output_str+"\n";2402 }2403 }2404 }2405 }2406 append_str = append_str+output_str;2407 return append_str;2408 }2409 return "";2410 }2411 else if (term(tree["name"],"relation")){2412 var judge_tree = tree["node_list"][0];2413 var left_tree = judge_tree["node_list"][0];2414 var right_tree = judge_tree["node_list"][1];2415 var left_str = Code_Generation_2_Javascript(sl,left_tree);2416 var right_str = Code_Generation_2_Javascript(sl,right_tree);2417 var append_str = left_str;2418 var relationship = null;2419 if (term(judge_tree["name"],"and")){2420 relationship = " && ";2421 }2422 else{2423 relationship = " || ";2424 }2425 append_str = append_str+relationship;2426 append_str = append_str+right_str;2427 append_str = "("+append_str+")";2428 return append_str;2429 }2430 else if (term(tree["name"],"simple_relation")){2431 var judge_tree = tree["node_list"][0];2432 var left_tree = judge_tree["node_list"][0];2433 var right_tree = judge_tree["node_list"][1];2434 var left_str = Code_Generation_2_Javascript(sl,left_tree);2435 var right_str = Code_Generation_2_Javascript(sl,right_tree);2436 var append_str = left_str;2437 var judge_sign = judge_tree["name"];2438 if (term(judge_sign,"==")){2439 judge_sign = "===";2440 }2441 else if (term(judge_sign,"!=")){2442 judge_sign = "!==";2443 }2444 append_str = append_str+judge_sign;2445 append_str = append_str+right_str;2446 return append_str;2447 }2448 else if (term(tree["name"],"self_operator_stm")){2449 var var_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2450 return var_name+tree["node_list"][1]["name"];2451 }2452 else if (term(tree["name"],"self_assignment_stm")){2453 var var_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2454 var append_string = var_name;2455 append_string = append_string+tree["node_list"][1]["name"];2456 var var_value = Code_Generation_2_Javascript(sl,tree["node_list"][2]);2457 append_string = append_string+var_value;2458 return append_string;2459 }2460 else if (term(tree["name"],"=")){2461 var is_local = false;2462 var append_string = "";2463 var nl = tree["node_list"];2464 var var_name_tree = nl[0];2465 if (term(var_name_tree["name"],"local")){2466 is_local = true;2467 var_name_tree = nl[1];2468 }2469 var var_value_tree = null;2470 if (is_local===true){2471 var_value_tree = nl[2];2472 }2473 else{2474 var_value_tree = nl[1];2475 }2476 var var_name = Code_Generation_2_Javascript(sl,var_name_tree);2477 append_string = var_name;2478 if (is_local===true){2479 append_string = "var "+append_string;2480 }2481 append_string = append_string+" = ";2482 var var_value = Code_Generation_2_Javascript(sl,var_value_tree);2483 append_string = append_string+var_value;2484 return append_string;2485 }2486 else if (term(tree["name"],"func_value")){2487 var append_string = "function(";2488 var param_str = Code_Generation_2_Javascript(sl,tree["node_list"][1]);2489 append_string = append_string+param_str;2490 append_string = append_string+"){\n";2491 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2492 var nl = tree["node_list"];2493 var i = 2;2494 var output_str = "";2495 var length_of_nl = len(nl);2496 for ( ; i<length_of_nl-1 ; i = i+1){2497 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2498 if (len(temp_str)!==0){2499 output_str = output_str+temp_str;2500 if (output_str[len(output_str)-1]!=="\n"){2501 if (output_str[len(output_str)-1]!==";"){2502 output_str = output_str+";\n";2503 }2504 else{2505 output_str = output_str+"\n";2506 }2507 }2508 }2509 }2510 append_string = append_string+output_str;2511 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2512 append_string = append_string+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2513 return append_string;2514 }2515 else if (term(tree["token_class"],"table")){2516 var append_str = "{";2517 var nl = tree["node_list"];2518 var i = 0;2519 var length_of_nl = len(nl);2520 for (i = 0 ; i<length_of_nl ; i = i+1){2521 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2522 append_str = append_str+temp_str;2523 if (i+1!==length_of_nl){2524 append_str = append_str+",";2525 }2526 }2527 append_str = append_str+"}";2528 return append_str;2529 }2530 else if (term(tree["name"],"table_expr")){2531 var key_tree = tree["node_list"][0];2532 var value_tree = tree["node_list"][1];2533 var left = Code_Generation_2_Javascript(sl,key_tree["node_list"][0]);2534 var left_is_string = isString(left);2535 if ((left_is_string===false && isdigit(left)===false)){2536 console.log("Error.. invalid key %s\n",left);2537 process.exit(0);2538 }2539 if (left_is_string===true){2540 left = left.slice(1,left["length"]-1);2541 }2542 var right = Code_Generation_2_Javascript(sl,value_tree);2543 return left+":"+right;2544 }2545 else if (term(tree["name"],"table_value")){2546 var nl = tree["node_list"];2547 var var_name = Code_Generation_2_Javascript(sl,nl[0]);2548 var var_name_is_table = false;2549 if (nl[0]["token_class"]==="table"){2550 var_name_is_table = true;2551 }2552 var append_str = var_name;2553 js_isTableValue = true;2554 var i = 1;2555 var length_of_nl = len(nl);2556 for ( ; i<length_of_nl ; i = i+1){2557 var key_tree = nl[i];2558 var key_str = Code_Generation_2_Javascript(sl,key_tree);2559 if ((var_name_is_table===true && key_str.indexOf(".slice(")===0)){2560 append_str = "WALLEY.slice("+append_str+","+key_str.slice(7,key_str["length"]-1)+")";2561 continue;2562 }2563 append_str = append_str+key_str;2564 }2565 js_isTableValue = false;2566 return append_str;2567 }2568 else if (term(tree["name"],"key")){2569 if (term(tree["node_list"][0]["name"],"slice")){2570 var append_str = ".slice(";2571 var nl = tree["node_list"][0]["node_list"];2572 var left = nl[0];2573 var right = nl[1];2574 var left_str = Code_Generation_2_Javascript(sl,left);2575 append_str = append_str+left_str;2576 js_isTableValue = false;2577 if (term(right["name"],"its_length")){2578 console.log("");2579 }2580 else{2581 append_str = append_str+",";2582 var right_str = Code_Generation_2_Javascript(sl,right);2583 append_str = append_str+right_str;2584 }2585 append_str = append_str+")";2586 js_isTableValue = true;2587 return append_str;2588 }2589 else{2590 var key_tree = tree["node_list"][0];2591 js_isTableValue = false;2592 var append_str = "["+Code_Generation_2_Javascript(sl,key_tree)+"]";2593 js_isTableValue = true;2594 return append_str;2595 }2596 }2597 else if (term(tree["name"],"func")){2598 var used_to_be_js_isTableValue = false;2599 var append_str = "";2600 if (js_isTableValue===false){2601 var func_name_string = Code_Generation_2_Javascript(sl,tree["node_list"][0]["node_list"][0]);2602 var func_name = func_name_string.slice(1,len(func_name_string)-1);2603 append_str = func_name;2604 }2605 else{2606 var func_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]["node_list"][0]);2607 if (isString(func_name)===true){2608 append_str = "."+func_name.slice(1,func_name["length"]-1);2609 }2610 else{2611 append_str = "["+func_name+"]";2612 }2613 used_to_be_js_isTableValue = true;2614 js_isTableValue = false;2615 }2616 append_str = append_str+"(";2617 var params_tree = tree["node_list"][1];2618 var params_nl = params_tree["node_list"];2619 var i = 0;2620 var length_of_params_nl = len(params_nl);2621 for (i = 0 ; i<length_of_params_nl ; i = i+1){2622 append_str = append_str+Code_Generation_2_Javascript(sl,params_nl[i]);2623 if (i+1!==length_of_params_nl){2624 append_str = append_str+",";2625 }2626 }2627 append_str = append_str+")";2628 if (used_to_be_js_isTableValue===true){2629 js_isTableValue = true;2630 }2631 return append_str;2632 }2633 else if ((term(tree["name"],"and") || term(tree["name"],"or"))){2634 var left_str = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2635 var right_str = Code_Generation_2_Javascript(sl,tree["node_list"][1]);2636 var judge_sign = "&&";2637 if (term(tree["name"],"or")){2638 judge_sign = "||";2639 }2640 return left_str+judge_sign+right_str;2641 }2642 else if (term(tree["name"],"params")){2643 var append_string = "";2644 var nl = tree["node_list"];2645 var i = 0;2646 var length_of_nl = len(nl);2647 for ( ; i<length_of_nl ; i = i+1){2648 if (term(nl[i]["name"],"=")){2649 console.log("Does not support = in params now \n");2650 }2651 var need_to_be_appended = Code_Generation_2_Javascript(sl,nl[i]);2652 if (term(need_to_be_appended,"null")){2653 continue;2654 }2655 append_string = append_string+need_to_be_appended;2656 if (i+1!==length_of_nl){2657 append_string = append_string+",";2658 }2659 }2660 return append_string;2661 }2662 else if (term(tree["name"],"end")){2663 return "}\n";2664 }2665 else if (term(tree["token_class"],"num")){2666 return tree["name"];2667 }2668 else if (term(tree["token_class"],"string")){2669 return tree["name"];2670 }2671 else if (term(tree["name"],"value")){2672 var nl = tree["node_list"];2673 return Code_Generation_2_Javascript(sl,nl[0]);2674 }2675 else if (ism_operator(tree["name"])){2676 var nl = tree["node_list"];2677 var left = nl[0];2678 var right = nl[1];2679 var left_str = Code_Generation_2_Javascript(sl,left);2680 var right_str = Code_Generation_2_Javascript(sl,right);2681 if (((isdigit(left_str) || isString(left_str)) && (isdigit(right_str) || isString(right_str)))){2682 var value = Walley_Calculation(left_str,right_str,tree["name"]);2683 return value;2684 }2685 var left_need_bracket = true;2686 var right_need_bracket = true;2687 if (((term(left["token_class"],"id") || term(left["token_class"],"string")) || term(left["token_class"],"num"))){2688 left_need_bracket = false;2689 }2690 if (((term(right["token_class"],"id") || term(right["token_class"],"string")) || term(right["token_class"],"num"))){2691 right_need_bracket = false;2692 }2693 var need_bracket = false;2694 if ((((term(tree["name"],"*") || term(tree["name"],"//")) || term(tree["name"],"^")) || term(tree["name"],"%"))){2695 need_bracket = true;2696 }2697 if (need_bracket){2698 if (left_need_bracket){2699 left_str = "("+left_str+")";2700 }2701 if (right_need_bracket){2702 right_str = "("+right_str+")";2703 }2704 if (term(tree["name"],"^")){2705 var append_str = "Math.pow("+left_str+","+right_str+")";2706 return append_str;2707 }2708 else{2709 var append_str = left_str+tree["name"]+right_str;2710 return append_str;2711 }2712 }2713 else{2714 if (term(tree["name"],"^")){2715 return "Math.pow("+left_str+","+right_str+")";2716 }2717 else{2718 var append_str = left_str;2719 append_str = append_str+tree["name"];2720 append_str = append_str+right_str;2721 return append_str;2722 }2723 }2724 }2725 else if (term(tree["name"],"expr")){2726 return Code_Generation_2_Javascript(sl,tree["node_list"][0]);2727 }2728 else if (term(tree["name"],"return")){2729 var append_str = "return ";2730 var nl = tree["node_list"];2731 append_str = append_str+Code_Generation_2_Javascript(sl,nl[0]);2732 append_str = append_str+";\n";2733 return append_str;2734 }2735 else if (tree["name"]==="new_value"){2736 js_isTableValue = true;2737 var append_str = "new ";2738 var nl = tree["node_list"];2739 for (i = 0 ; i<len(nl) ; i = i+1){2740 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2741 if (i===0){2742 temp_str = temp_str.slice(1,temp_str["length"]);2743 }2744 append_str+=temp_str;2745 }2746 js_isTableValue = false;2747 return append_str;2748 }2749 else{2750 console.log("Code Generation Error..\n");2751 process.exit(0);2752 }2753}2754exports["Code_Generation"] = function(input_str){2755 INCOMPLETE_STATEMENT = false;2756 var tl = Walley_Lexical_Analyzie(input_str);2757 var tree = parser(tl);2758 var sl = {};2759 var output = Code_Generation_2_Javascript(sl,tree);2760 if (output!==""){2761 sl.append(output);2762 }2763 var output_str = "";2764 var length = len(sl);2765 for (i = 0 ; i<length ; i = i+1){2766 output_str = output_str+sl[i];2767 }2768 exports["INCOMPLETE_STATEMENT"] = INCOMPLETE_STATEMENT;2769 return output_str;...

Full Screen

Full Screen

walley_dev.js

Source:walley_dev.js Github

copy

Full Screen

1none=null;function isalpha(input_char){return/^[a-z]+$/i.test(input_char)}function isdigit(e){return!isNaN(parseFloat(e))&&isFinite(e)}String.prototype.find=function(find_str,start){if(typeof start=="undefined"){start=0}return this.indexOf(find_str,start)};String.prototype.tolower=function(){return this.toLowerCase()};String.prototype.toupper=function(){return this.toUpperCase()};String.prototype.reverse=function(){return this.split("").reverse().join("")};Math["cot"]=function(num){return 1/Math.tan(num)};Math["sec"]=function(num){return 1/Math.cos(num)};Math["csc"]=function(num){return 1/Math.sin(num)};Object.prototype.slice=function(start,end){var return_obj={};var a=0;for(var i=start;i<end;i++){return_obj[a]=this[i];a++}return return_obj};Object.prototype.append=function(e){var t=this.maxn()+1;this[t]=e};Object.prototype.maxn=function(){var t=0;if(typeof this[0]=="undefined"){return-1}while(typeof this[t]!="undefined"){t=t+1}return t-1};Object.prototype.insert=function(insert_obj,pos){if(typeof pos=="undefined"){pos=table.maxn(this)+1;this[pos]=insert_obj}else{this[pos]=insert_obj}};Object.prototype.remove=function(pos){if(typeof pos=="undefined"){pos=table.maxn(obj)}delete this[pos]};Object.prototype.length=function(){return Object.keys(this).length};function len(obj){if(typeof obj=="string"){return obj.length}else if(typeof obj=="object"){return Object.keys(obj).length}else{console.log("Error..\nfunctin len() only support table or string\n")}}WALLEY={};WALLEY.stringToObject=function(input_str){if(typeof input_str=="string"){obj={};for(var i=0;i<input_str.length;i=i+1){obj[i]=input_str[i]}return obj}else{return input_str}};WALLEY.slice=function(obj,start,end){if(typeof obj=="object"){var return_obj={};var a=0;for(var i=start;i<end;i++){return_obj[a]=obj[i];a++}return return_obj}else if(typeof obj=="string"){return this.slice(start,end)}else{console.log("Error.. WALLEY.slice only support object and string type")}};function range(start,end,step){if(typeof end=="undefined"&&typeof step=="undefined"){end=start;start=0;step=1}else if(typeof step=="undefined"){step=1}var return_obj={};var count=0;for(var i=start;i<end;i=i+step){return_obj[count]=i;count++}return return_obj}2BEAUTIFUL_SPACES = 0;3if (typeof(exports)==="undefined"){4 exports = {};5}6INCOMPLETE_STATEMENT = false;7toString = function(input_str){8 if (input_str[0]==="\""){9 return input_str;10 }11 else{12 return "\""+input_str+"\"";13 }14}15Walley_Print_Error = function(input_str,error_message,error_start_index){16 console.log("Error.. %s\n",error_message);17 console.log("%s\n",input_str);18 var empty = "";19 var i = 0;20 for ( ; i<error_start_index ; i = i+1){21 empty = empty+" ";22 }23 empty = empty+"^";24 console.log("%s\n",empty);25}26Token_init = function(){27 var Token = {};28 Token["TOKEN_CLASS"] = "";29 Token["TOKEN_STRING"] = "";30 Token["TOKEN_START"] = -1;31 Token["TOKEN_END"] = -1;32 return Token;33}34TOKEN_print = function(token){35 console.log(token["TOKEN_CLASS"]+":"+"|"+token["TOKEN_STRING"]+"|"+token["TOKEN_START"]+"|"+token["TOKEN_END"]);36}37TL_toString = function(tl){38 var return_string = "";39 for(i in WALLEY.stringToObject(tl)){40 if((WALLEY.stringToObject(tl)).hasOwnProperty(i)){41 v=(WALLEY.stringToObject(tl))[i];42 return_string = return_string+v["TOKEN_STRING"];43 }44 };45}46TL_addToken = function(tl,add_token){47 var temp_token = Token_init();48 temp_token["TOKEN_CLASS"] = add_token["TOKEN_CLASS"];49 temp_token["TOKEN_STRING"] = add_token["TOKEN_STRING"];50 temp_token["TOKEN_START"] = add_token["TOKEN_START"];51 temp_token["TOKEN_END"] = add_token["TOKEN_END"];52 tl.append(temp_token);53}54TL_indexOfTokenThatHasTokenString = function(tl,token_string){55 var output = -1;56 var i = 0;57 for (i = 0 ; i<len(tl) ; i = i+1){58 if (tl[i]["TOKEN_STRING"]===token_string){59 return i;60 }61 }62 return -1;63}64TL_indexOfTokenThatHasTokenClass = function(tl,token_string){65 var output = -1;66 var i = 0;67 for (i = 0 ; i<len(tl) ; i = i+1){68 if (tl[i]["TOKEN_CLASS"]===token_string){69 return i;70 }71 }72 return -1;73}74match = function(input_str,index,match_string){75 var length_of_input_str = len(input_str);76 var length_of_match_str = len(match_string);77 if (length_of_input_str<index+length_of_match_str){78 return false;79 }80 var i = 0;81 var match = true;82 for ( ; i<length_of_match_str ; i = i+1){83 if (input_str[index+i]!==match_string[i]){84 match = false;85 break;86 }87 }88 if (match===true){89 return true;90 }91 else{92 return false;93 }94}95term = function(input_str1,input_str2){96 if (input_str1===input_str2){97 return true;98 }99 else{100 return false;101 }102}103LIST_indexOfFinalBracket = function(input_str,index_of_first_bracket){104 var count = 0;105 var in_string = false;106 var length_of_input_str = len(input_str);107 var i = index_of_first_bracket;108 for ( ; i<length_of_input_str ; i = i+1){109 if (((in_string===false && input_str[i]==="\"") && input_str[i-1]!=="\\")){110 in_string = true;111 continue;112 }113 if (((in_string===true && input_str[i]==="\"") && input_str[i-1]!=="\\")){114 in_string = false;115 continue;116 }117 if (in_string===false){118 if (input_str[i]==="["){119 count = count+1;120 continue;121 }122 if (input_str[i]==="]"){123 count = count-1;124 if (count===0){125 return i;126 }127 else{128 continue;129 }130 }131 }132 }133 return -1;134}135indexOfFinalDoubleQuote = function(input_str,first_index){136 var first_char = input_str[first_index];137 var i = first_index+1;138 var length = len(input_str);139 if (first_char==="\""){140 for ( ; i<length ; i = i+1){141 if ((input_str[i]==="\"" && input_str[i-1]!=="\\")){142 return i;143 }144 if ((input_str[i]==="\"" && input_str[i-1]==="\\")){145 if (input_str[i-2]==="\\"){146 return i;147 }148 }149 }150 }151 return -1;152}153Walley_Analyze_Token_Class = function(input_str,i){154 var return_obj = {};155 var length = len(input_str);156 if ((match(input_str,i,"&&") || match(input_str,i,"||"))){157 console.log("Error.. Does not support && and ||");158 console.log("Please use ' and ' and ' or ' instead");159 }160 if ((match(input_str,i,"++") || match(input_str,i,"--"))){161 end_index = i+2;162 return_obj[0] = end_index;163 return_obj[1] = "self_operator";164 return return_obj;165 }166 if (((((match(input_str,i,"+=") || match(input_str,i,"-=")) || match(input_str,i,"*=")) || match(input_str,i,"//=")) || match(input_str,i,"%="))){167 end_index = i+2;168 return_obj[0] = end_index;169 return_obj[1] = "self_assignment";170 return return_obj;171 }172 if (match(input_str,i,"**")){173 end_index = i+2;174 return_obj[0] = end_index;175 return_obj[1] = "m_operator";176 return return_obj;177 }178 if ((((((input_str[i]==="+" || input_str[i]==="-") || input_str[i]==="*") || input_str[i]==="/") || input_str[i]==="^") || input_str[i]==="%")){179 end_index = i+1;180 return_obj[0] = end_index;181 return_obj[1] = "m_operator";182 return return_obj;183 }184 if ((input_str[i]==="," || input_str[i]===":")){185 end_index = i+1;186 return_obj[0] = end_index;187 return_obj[1] = "punctuation";188 return return_obj;189 }190 if ((((match(input_str,i,"==") || match(input_str,i,">=")) || match(input_str,i,"<=")) || match(input_str,i,"!="))){191 end_index = i+2;192 return_obj[0] = end_index;193 return_obj[1] = "judge_sign";194 return return_obj;195 }196 if ((input_str[i]===">" || input_str[i]==="<")){197 end_index = i+1;198 return_obj[0] = end_index;199 return_obj[1] = "judge_sign";200 return return_obj;201 }202 if (((i<=length-2 && input_str[i]==="#") && input_str[i+1]==="~")){203 end_index = i+2;204 return_obj[0] = end_index;205 return_obj[1] = "l_annotation";206 return return_obj;207 }208 if ((i<=length-2 && (input_str[i]==="~" && input_str[i+1]==="#"))){209 end_index = i+2;210 return_obj[0] = end_index;211 return_obj[1] = "r_annotation";212 }213 if (input_str[i]==="="){214 end_index = i+1;215 return_obj[0] = end_index;216 return_obj[1] = "assignment_operator";217 return return_obj;218 }219 if (input_str[i]==="#"){220 end_index = i+1;221 return_obj[0] = end_index;222 return_obj[1] = "annotation";223 return return_obj;224 }225 if ((((input_str[i]==="(" || input_str[i]===")") || input_str[i]==="{") || input_str[i]==="}")){226 end_index = i+1;227 var output = input_str[i];228 return_obj[0] = end_index;229 return_obj[1] = output;230 return return_obj;231 }232 if (input_str[i]==="["){233 var index_of_final = LIST_indexOfFinalBracket(input_str,i);234 if (index_of_final===-1){235 INCOMPLETE_STATEMENT = true;236 }237 end_index = index_of_final+1;238 return_obj[0] = end_index;239 return_obj[1] = "list_table";240 return return_obj;241 }242 if (input_str[i]==="\""){243 var index_of_right_dq = indexOfFinalDoubleQuote(input_str,i);244 if (index_of_right_dq===-1){245 console.log("incomplete str\n");246 process.exit(0);247 }248 else{249 end_index = index_of_right_dq+1;250 return_obj[0] = end_index;251 return_obj[1] = "string";252 return return_obj;253 }254 }255 if (isdigit(input_str[i])===true){256 var a = i;257 var temp_str = input_str[i];258 while (isdigit(temp_str)){259 a = a+1;260 temp_str = temp_str+input_str[a];261 }262 end_index = a;263 return_obj[0] = end_index;264 return_obj[1] = "num";265 return return_obj;266 }267 if (((input_str[i]===" " || input_str[i]==="\n") || input_str[i]==="\t")){268 var a = i+1;269 for ( ; a<length ; a = a+1){270 if (((input_str[a]!==" " && input_str[a]!=="\n") && input_str[a]!=="\t")){271 break;272 }273 }274 end_index = a;275 return_obj[0] = end_index;276 return_obj[1] = "white_space";277 return return_obj;278 }279 if (((isalpha(input_str[i]) || input_str[i]==="_") || input_str[i]==="$")){280 var a = i+1;281 for ( ; a<length ; a = a+1){282 if ((((isalpha(input_str[a]) || input_str[a]==="_") || input_str[a]==="$") || isdigit(input_str[a]))){283 continue;284 }285 else{286 break;287 }288 }289 var id_string = input_str.slice(i,a);290 if (id_string==="import"){291 end_index = i+6;292 return_obj[0] = end_index;293 return_obj[1] = "import";294 return return_obj;295 }296 else if ((id_string==="and" || id_string==="not")){297 end_index = i+3;298 return_obj[0] = end_index;299 return_obj[1] = "relation";300 return return_obj;301 }302 else if (id_string==="or"){303 end_index = i+2;304 return_obj[0] = end_index;305 return_obj[1] = "relation";306 return return_obj;307 }308 else if (id_string==="if"){309 end_index = i+2;310 return_obj[0] = end_index;311 return_obj[1] = "keyword";312 return return_obj;313 }314 else if ((id_string==="def" || id_string==="for")){315 end_index = i+3;316 return_obj[0] = end_index;317 return_obj[1] = "keyword";318 return return_obj;319 }320 else if (((id_string==="elif" || id_string==="else") || id_string==="case")){321 end_index = i+4;322 return_obj[0] = end_index;323 return_obj[1] = "keyword";324 return return_obj;325 }326 else if (id_string==="while"){327 end_index = i+5;328 return_obj[0] = end_index;329 return_obj[1] = "keyword";330 return return_obj;331 }332 else if (id_string==="then"){333 end_index = i+4;334 return_obj[0] = end_index;335 return_obj[1] = "then";336 return return_obj;337 }338 else if (id_string==="end"){339 end_index = i+3;340 return_obj[0] = end_index;341 return_obj[1] = "end";342 return return_obj;343 }344 else if (id_string==="return"){345 end_index = i+6;346 return_obj[0] = end_index;347 return_obj[1] = "return";348 return return_obj;349 }350 else if (id_string==="local"){351 end_index = i+5;352 return_obj[0] = end_index;353 return_obj[1] = "local";354 return return_obj;355 }356 else if (id_string==="switch"){357 end_index = i+6;358 return_obj[0] = end_index;359 return_obj[1] = "keyword";360 return return_obj;361 }362 else if (id_string==="new"){363 end_index = i+3;364 return_obj[0] = end_index;365 return_obj[1] = "new";366 return return_obj;367 }368 else{369 end_index = a;370 return_obj[0] = end_index;371 return_obj[1] = "id";372 return return_obj;373 }374 }375 if (input_str[i]==="."){376 var a = i+1;377 end_index = a;378 return_obj[0] = end_index;379 return_obj[1] = "dot";380 return return_obj;381 }382 Walley_Print_Error(input_str,"Can not analyze this input",i);383 process.exit(0);384}385Walley_Lexical_Analyzie = function(input_str){386 var i = 0;387 var length = len(input_str);388 var tl = {};389 var end_index = 0;390 for ( ; i<length ; i = i+1){391 var output_data = Walley_Analyze_Token_Class(input_str,i);392 end_index = output_data[0];393 var token_class = output_data[1];394 if (INCOMPLETE_STATEMENT===true){395 break;396 }397 if (token_class==="white_space"){398 i = end_index-1;399 continue;400 }401 if (token_class==="annotation"){402 for (i = end_index ; i<length ; i = i+1){403 if (input_str[i]==="\n"){404 break;405 }406 }407 continue;408 }409 if (token_class==="l_annotation"){410 i = end_index;411 var count = 0;412 var find_right_annotation = false;413 for ( ; i<length-1 ; i = i+1){414 if (input_str[i]==="\""){415 count = count+1;416 continue;417 }418 if (((count%2===0 && input_str[i]==="~") && input_str[i+1]==="#")){419 i = i+1;420 find_right_annotation = true;421 break;422 }423 }424 if (find_right_annotation===false){425 INCOMPLETE_STATEMENT = true;426 return tl;427 }428 continue;429 }430 temp_token = Token_init();431 temp_token["TOKEN_START"] = i;432 temp_token["TOKEN_END"] = end_index;433 temp_token["TOKEN_CLASS"] = token_class;434 var token_string = "";435 token_string = input_str.slice(i,end_index).trim();436 temp_token["TOKEN_STRING"] = token_string;437 tl.append(temp_token);438 i = end_index-1;439 }440 return tl;441}442TREE_INDEX = 0;443TREE_init = function(name){444 var TREE = {};445 TREE["name"] = name||"";446 TREE["token_class"] = "";447 TREE["index"] = 0;448 TREE["layer"] = 0;449 TREE["node_list"] = {};450 TREE_INDEX = TREE_INDEX+1;451 return TREE;452}453TREE_addNode = function(tree,name,token_class){454 var length_of_nl = len(tree["node_list"]);455 tree["node_list"][length_of_nl] = TREE_init();456 tree["node_list"][length_of_nl]["name"] = name;457 tree["node_list"][length_of_nl]["token_class"] = token_class;458 tree["node_list"][length_of_nl]["index"] = TREE_INDEX-1;459 tree["node_list"][length_of_nl]["layer"] = tree["layer"]+1;460 tree["node_list"][length_of_nl]["node_list"] = {};461}462TREE_addTree = function(tree,add_tree){463 var index = TREE_INDEX;464 var length_of_nl = len(tree["node_list"]);465 tree["node_list"][length_of_nl] = add_tree;466 tree["node_list"][length_of_nl]["index"] = index;467 tree["node_list"][length_of_nl]["layer"] = tree["layer"]+1;468 TREE_INDEX = TREE_INDEX+1;469}470TREE_getTreeAccordingToIndex = function(tree,index){471 if (index===tree["index"]){472 return tree;473 }474 else{475 var nl = tree["node_list"];476 if (len(nl)===0){477 return null;478 }479 var i = 0;480 var length = len(nl);481 for ( ; i<length ; i = i+1){482 var node = nl[i];483 if (index===node["index"]){484 return node;485 }486 }487 nl = tree["node_list"];488 i = 0;489 for ( ; i<length ; i = i+1){490 found_tree = TREE_getTreeAccordingToIndex(nl[i],index);491 if (found_tree!==null){492 return found_tree;493 }494 }495 }496 return null;497}498TREE_print = function(tree){499 process["stdout"].write("("+tree["token_class"]+" "+tree["name"]);500 var length_of_node_list = len(tree["node_list"]);501 if (length_of_node_list!==0){502 var i = 0;503 var nl = tree["node_list"];504 for (i = 0 ; i<length_of_node_list ; i = i+1){505 TREE_print(nl[i]);506 }507 }508 process["stdout"].write(")");509}510TREE_changeNameAccordingToIndex = function(tree,index,change_to_name){511 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);512 temp_tree["name"] = change_to_name;513}514TREE_layer = function(tree){515 var temp_tree = TREE_getTreeAccordingToIndex(tree,TREE_INDEX);516 return temp_tree["layer"];517}518TREE_addNodeAtIndex = function(tree,index,add_name,add_token_class){519 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);520 TREE_addNode(temp_tree,add_name,add_token_class);521}522elements = function(tree,tl){523 if (INCOMPLETE_STATEMENT===true){524 return false;525 }526 var length_of_tl = len(tl);527 var index_of_comma = TL_indexOfTokenThatHasTokenString(tl,",");528 if (index_of_comma===-1){529 var index_of_tl = TREE_INDEX;530 TREE_addNode(tree,"value","");531 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl),tl);532 }533 else{534 var tl1 = tl.slice(0,index_of_comma);535 var tl2 = tl.slice(index_of_comma+1,length_of_tl);536 var index_of_tl1 = TREE_INDEX;537 TREE_addNode(tree,"value","");538 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&elements(tree,tl2);539 }540}541value = function(tree,tl){542 if (INCOMPLETE_STATEMENT){543 return false;544 }545 var length_of_tl = len(tl);546 if (length_of_tl===0){547 tree["name"] = "none";548 tree["token_class"] = "id";549 return true;550 }551 else if (length_of_tl===1){552 if ((("num"===tl[0]["TOKEN_CLASS"] || "string"===tl[0]["TOKEN_CLASS"]) || "id"===tl[0]["TOKEN_CLASS"])){553 tree["name"] = tl[0]["TOKEN_STRING"];554 tree["token_class"] = tl[0]["TOKEN_CLASS"];555 return true;556 }557 else if ("list_table"===tl[0]["TOKEN_CLASS"]){558 tree["name"] = tl[0]["TOKEN_STRING"];559 tree["token_class"] = "table";560 var key_index = {val:0};561 return table(tree,tl,key_index);562 }563 else{564 return false;565 }566 }567 else{568 return (((func_value(tree,tl) || table_value(tree,tl)) || func(tree,tl)) || relation(tree,tl))||expr(tree,tl);569 }570}571new_value = function(tree,tl){572 if (tl[0]["TOKEN_STRING"]==="new"){573 tree["name"] = "new_value";574 tree["token_class"] = "";575 tl[0]["TOKEN_STRING"] = ".";576 tl[0]["TOKEN_CLASS"] = "dot";577 return table_value_key(tree,tl);578 }579 return false;580}581table_elements = function(tree,tl,key_index){582 if (INCOMPLETE_STATEMENT){583 return false;584 }585 var length_of_tl = len(tl);586 var i = 0;587 var index_of_comma = -1;588 var count = 0;589 for (i = 0 ; i<length_of_tl ; i = i+1){590 if (tl[i]["TOKEN_STRING"]==="("){591 count++;592 continue;593 }594 if (tl[i]["TOKEN_STRING"]===")"){595 count--;596 continue;597 }598 if ((count===0 && tl[i]["TOKEN_STRING"]===",")){599 index_of_comma = i;600 break;601 }602 }603 if (index_of_comma!==-1){604 table_expr_tl = tl.slice(0,index_of_comma);605 table_elements_tl = tl.slice(index_of_comma+1,length_of_tl);606 var index1 = TREE_INDEX;607 TREE_addNode(tree,"table_expr","");608 return table_expr(TREE_getTreeAccordingToIndex(tree,index1),table_expr_tl,key_index)&&table_elements(tree,table_elements_tl,key_index);609 }610 else{611 var index = TREE_INDEX;612 TREE_addNode(tree,"table_expr","");613 return table_expr(TREE_getTreeAccordingToIndex(tree,index),tl,key_index);614 }615}616table_expr = function(tree,tl,key_index){617 if (INCOMPLETE_STATEMENT===true){618 return false;619 }620 var length_of_tl = len(tl);621 if ((((3<length_of_tl && term(tl[0]["TOKEN_CLASS"],"@")) && term(tl[1]["TOKEN_CLASS"],"id")) && term(tl[2]["TOKEN_STRING"],"="))){622 var append_key = tl[1]["TOKEN_STRING"];623 var length_of_append_key = len(append_key);624 var new_key = "@"+append_key;625 TREE_addNode(tree,new_key,"key");626 var index = TREE_INDEX;627 TREE_addNode(tree,"value","");628 return value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(3,length_of_tl));629 }630 else if ((term(tl[0]["TOKEN_CLASS"],"id") && term(tl[1]["TOKEN_STRING"],"="))){631 var index1 = TREE_INDEX;632 TREE_addNode(tree,"key","");633 var key_tl = Walley_Lexical_Analyzie(toString(tl[0]["TOKEN_STRING"]));634 var key_tree = TREE_init("key");635 value(key_tree,key_tl);636 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);637 var index2 = TREE_INDEX;638 TREE_addNode(tree,"value","");639 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(2,length_of_tl));640 }641 else if (((term(tl[0]["TOKEN_CLASS"],"list_table") && typeof(tl[1])!=="undefined") && term(tl[1]["TOKEN_STRING"],"="))){642 var length = len(tl[0]["TOKEN_STRING"]);643 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);644 var index1 = TREE_INDEX;645 TREE_addNode(tree,"key","");646 var key_tl = Walley_Lexical_Analyzie(string_inside);647 TREE;648 key_tree = TREE_init("key");649 value(key_tree,key_tl);650 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);651 var index2 = TREE_INDEX;652 TREE_addNode(tree,"value","");653 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(2,length_of_tl));654 }655 else{656 var index1 = TREE_INDEX;657 TREE_addNode(tree,"key","");658 var key_tl = Walley_Lexical_Analyzie(key_index["val"]+"");659 var key_tree = TREE_init("key");660 value(key_tree,key_tl);661 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);662 var index = TREE_INDEX;663 TREE_addNode(tree,"value","");664 key_index["val"] = key_index["val"]+1;665 return value(TREE_getTreeAccordingToIndex(tree,index),tl);666 }667 return false;668}669table = function(tree,tl,key_index){670 if (INCOMPLETE_STATEMENT===true){671 return false;672 }673 var length_of_tl = len(tl);674 if (length_of_tl===1){675 var list_string = tl[0]["TOKEN_STRING"];676 var length_of_list_string = len(list_string);677 if ((list_string[0]==="[" && list_string[length_of_list_string-1]==="]")){678 var list_string2 = list_string.slice(1,len(list_string)-1).trim();679 if (list_string2===""){680 return true;681 }682 var table_tl = Walley_Lexical_Analyzie(list_string2);683 return table_elements(tree,table_tl,key_index);684 }685 else{686 return false;687 }688 }689 else{690 return false;691 }692}693table_value = function(tree,tl){694 if (INCOMPLETE_STATEMENT===true){695 return false;696 }697 var length_of_tl = len(tl);698 var i = 0;699 var count = 0;700 for (i = 0 ; i<length_of_tl ; i = i+1){701 if (term(tl[i]["TOKEN_STRING"],"(")){702 count = count+1;703 }704 else if (term(tl[i]["TOKEN_STRING"],")")){705 count = count-1;706 }707 if ((count===0 && term(tl[i]["TOKEN_CLASS"],"m_operator"))){708 return false;709 }710 }711 if (((2<=length_of_tl && (((term(tl[0]["TOKEN_CLASS"],"id") || term(tl[0]["TOKEN_CLASS"],"string")) || term(tl[0]["TOKEN_CLASS"],"list_table")) || term(tl[0]["TOKEN_CLASS"],"num"))) && (term(tl[1]["TOKEN_STRING"],".") || term(tl[1]["TOKEN_CLASS"],"list_table")))){712 var index1 = TREE_INDEX;713 TREE_addNode(tree,"table_value","");714 var index2 = TREE_INDEX;715 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index1),"value","");716 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(0,1))&&table_value_key(TREE_getTreeAccordingToIndex(tree,index1),tl.slice(1,length_of_tl));717 }718 else if (((3<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"id")) && term(tl[1]["TOKEN_STRING"],"("))){719 var index = -1;720 var i = 0;721 var count = 0;722 for (i = 0 ; i<len(tl) ; i = i+1){723 if (term(tl[i]["TOKEN_STRING"],"(")){724 count = count+1;725 }726 else if (term(tl[i]["TOKEN_STRING"],")")){727 count = count-1;728 if (count===0){729 index = i;730 break;731 }732 }733 }734 if (index===length_of_tl-1){735 return false;736 }737 if ((typeof(tl[i+1])!=="undefined" && term(tl[i+1]["TOKEN_CLASS"],"relation"))){738 return false;739 }740 var tree_index = TREE_INDEX;741 TREE_addNode(tree,"table_value","");742 var tree_index2 = TREE_INDEX;743 TREE_addNode(TREE_getTreeAccordingToIndex(tree,tree_index),"func","");744 func(TREE_getTreeAccordingToIndex(tree,tree_index2),tl.slice(0,index+1));745 return table_value_key(TREE_getTreeAccordingToIndex(tree,tree_index),tl.slice(index+1,length_of_tl));746 }747 else{748 if (term(tl[0]["TOKEN_STRING"],"(")){749 var index_of_right = -1;750 var i = 0;751 var count = 0;752 for (i = 0 ; i<len(tl) ; i = i+1){753 if (term(tl[i]["TOKEN_STRING"],"(")){754 count = count+1;755 }756 else if (term(tl[0]["TOKEN_STRING"],")")){757 count = count-1;758 if (count===0){759 index_of_right = i;760 break;761 }762 }763 }764 if (index_of_right===-1){765 return false;766 }767 else{768 if (index_of_right===length_of_tl-1){769 return false;770 }771 if ((term(tl[index_of_right+1]["TOKEN_CLASS"],"list_table")===false || term(tl[index_of_right+1]["TOKEN_STRING"],".")===false)){772 return false;773 }774 var index = TREE_INDEX;775 TREE_addNode(tree,"table_value","");776 var index2 = TREE_INDEX;777 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"expr","");778 return expr(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(0,index_of_right+1))&&table_value_key(TREE_getTreeAccordingToIndex(tree,index),tl.slice(index_of_right+1,length_of_tl));779 }780 }781 return false;782 }783}784table_value_key = function(tree,tl){785 if (INCOMPLETE_STATEMENT===true){786 return false;787 }788 var length_of_tl = len(tl);789 if ((length_of_tl===1 && term(tl[0]["TOKEN_CLASS"],"list_table"))){790 var length = len(tl[0]["TOKEN_STRING"]);791 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);792 var key_tl = Walley_Lexical_Analyzie(string_inside);793 var index_of_colon = -1;794 var i = 0;795 for (i = 0 ; i<len(key_tl) ; i = i+1){796 if (term(key_tl[i]["TOKEN_STRING"],":")){797 index_of_colon = i;798 break;799 }800 }801 if (index_of_colon===-1){802 var index1 = TREE_INDEX;803 TREE_addNode(tree,"key","");804 var key_tree = TREE_init(key_tree,"key");805 value(key_tree,key_tl);806 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);807 return true;808 }809 else{810 var length_of_key_tl = len(key_tl);811 var index1 = TREE_INDEX;812 TREE_addNode(tree,"key","");813 var slice_tree = TREE_init("slice");814 var left_tl = null;815 var right_tl = null;816 if (index_of_colon===0){817 left_tl = null;818 }819 else{820 left_tl = key_tl.slice(0,index_of_colon);821 }822 if (index_of_colon===length_of_key_tl-1){823 right_tl = null;824 }825 else{826 right_tl = key_tl.slice(index_of_colon+1,length_of_key_tl);827 }828 var index_left = TREE_INDEX;829 if (left_tl===null){830 TREE_addNode(slice_tree,"0","num");831 }832 else{833 TREE_addNode(slice_tree,"value","");834 value(TREE_getTreeAccordingToIndex(slice_tree,index_left),left_tl);835 }836 var index_right = TREE_INDEX;837 if (right_tl===null){838 TREE_addNode(slice_tree,"its_length","special");839 }840 else{841 TREE_addNode(slice_tree,"value","");842 value(TREE_getTreeAccordingToIndex(slice_tree,index_right),right_tl);843 }844 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),slice_tree);845 return true;846 }847 }848 else if (((length_of_tl===2 && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id"))){849 var index1 = TREE_INDEX;850 TREE_addNode(tree,"key","");851 var key_tl = Walley_Lexical_Analyzie(toString(tl[1]["TOKEN_STRING"]));852 var key_tree = TREE_init("key");853 value(key_tree,key_tl);854 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index1),key_tree);855 return true;856 }857 else if ((((4<=length_of_tl && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id")) && term(tl[2]["TOKEN_STRING"],"("))){858 var index_of_right = -1;859 var i = 0;860 var count = 0;861 for (i = 0 ; i<len(tl) ; i = i+1){862 if (term(tl[i]["TOKEN_STRING"],"(")){863 count = count+1;864 }865 else if (term(tl[i]["TOKEN_STRING"],")")){866 count = count-1;867 if (count===0){868 index_of_right = i;869 break;870 }871 }872 }873 if (index_of_right===-1){874 INCOMPLETE_STATEMENT = true;875 return false;876 }877 if (index_of_right===length_of_tl-1){878 var index1 = TREE_INDEX;879 TREE_addNode(tree,"key","");880 return func(TREE_getTreeAccordingToIndex(tree,index1),tl.slice(1,length_of_tl));881 }882 else{883 return table_value_key(tree,tl.slice(0,index_of_right+1))&&table_value_key(tree,tl.slice(index_of_right+1,length_of_tl));884 }885 }886 else if (((2<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"list_table")) && (term(tl[1]["TOKEN_STRING"],".") || term(tl[1]["TOKEN_CLASS"],"list_table")))){887 return table_value_key(tree,tl.slice(0,1))&&table_value_key(tree,tl.slice(1,length_of_tl));888 }889 else if (((3<=length_of_tl && term(tl[0]["TOKEN_CLASS"],"list_table")) && term(tl[1]["TOKEN_STRING"],"("))){890 var index = -1;891 var i = 0;892 var count = 0;893 for (i = 0 ; i<len(tl) ; i = i+1){894 if (term(tl[i]["TOKEN_STRING"],"(")){895 count = count+1;896 }897 else if (term(tl[i]["TOKEN_STRING"],")")){898 count = count-1;899 if (count===0){900 index = i;901 break;902 }903 }904 }905 if (index===-1){906 INCOMPLETE_STATEMENT = true;907 return false;908 }909 var func_tree = TREE_init("func");910 var tree_index = TREE_INDEX;911 TREE_addNode(func_tree,"","table_call");912 TREE_addNode(TREE_getTreeAccordingToIndex(func_tree,tree_index),"","");913 tree_index = tree_index+1;914 var length = len(tl[0]["TOKEN_STRING"]);915 var string_inside = tl[0]["TOKEN_STRING"].slice(1,length-1);916 var string_inside_tl = Walley_Lexical_Analyzie(string_inside);917 value(TREE_getTreeAccordingToIndex(func_tree,tree_index),string_inside_tl);918 tree_index = TREE_INDEX;919 TREE_addNode(func_tree,"params","");920 if (2!==index){921 params(TREE_getTreeAccordingToIndex(func_tree,tree_index),tl.slice(2,index));922 }923 TREE_addTree(tree,func_tree);924 if (index===length_of_tl-1){925 return true;926 }927 return table_value(tree,tl.slice(index+1,length_of_tl));928 }929 else if ((((3<=length_of_tl && term(tl[0]["TOKEN_STRING"],".")) && term(tl[1]["TOKEN_CLASS"],"id")) && (term(tl[2]["TOKEN_STRING"],".") || term(tl[2]["TOKEN_CLASS"],"list_table")))){930 return table_value_key(tree,tl.slice(0,2))&&table_value_key(tree,tl.slice(2,length_of_tl));931 }932 else{933 return false;934 }935}936expr = function(tree,tl){937 if (INCOMPLETE_STATEMENT){938 return false;939 }940 var length_of_tl = len(tl);941 var count_of_parenthesis = 0;942 var i = length_of_tl-1;943 for ( ; 0<=i ; i = i-1){944 if (tl[i]["TOKEN_STRING"]==="("){945 count_of_parenthesis = count_of_parenthesis+1;946 continue;947 }948 if (tl[i]["TOKEN_STRING"]===")"){949 count_of_parenthesis = count_of_parenthesis-1;950 continue;951 }952 if ((count_of_parenthesis===0 && ("+"===tl[i]["TOKEN_STRING"] || "-"===tl[i]["TOKEN_STRING"]))){953 var sign = tl[i]["TOKEN_STRING"];954 var index_of_first_sign = i;955 if (index_of_first_sign===0){956 temp_tl = {};957 var temp_token = Token_init();958 temp_token["TOKEN_STRING"] = "0";959 temp_token["TOKEN_CLASS"] = "num";960 temp_token["TOKEN_START"] = -1;961 temp_token["TOKEN_END"] = -1;962 temp_tl.append(temp_token);963 var a = 0;964 for (a = 0 ; a<len(tl) ; a = a+1){965 temp_tl.append(tl[a]);966 }967 return expr(tree,temp_tl);968 }969 var tl1 = tl.slice(0,index_of_first_sign);970 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);971 tree["name"] = sign;972 var index_of_expr1_node = TREE_INDEX;973 TREE_addNode(tree,"expr","");974 var index_of_expr2_node = TREE_INDEX;975 TREE_addNode(tree,"expr","");976 return expr(TREE_getTreeAccordingToIndex(tree,index_of_expr1_node),tl1)&&expr(TREE_getTreeAccordingToIndex(tree,index_of_expr2_node),tl2);977 }978 }979 return s_term(tree,tl);980}981s_term = function(tree,tl){982 if (INCOMPLETE_STATEMENT){983 return false;984 }985 var length_of_tl = len(tl);986 var count_of_parenthesis = 0;987 var i = length_of_tl-1;988 for ( ; 0<=i ; i = i-1){989 if (tl[i]["TOKEN_STRING"]==="("){990 count_of_parenthesis = count_of_parenthesis+1;991 continue;992 }993 if (tl[i]["TOKEN_STRING"]===")"){994 count_of_parenthesis = count_of_parenthesis-1;995 continue;996 }997 if ((count_of_parenthesis===0 && (("*"===tl[i]["TOKEN_STRING"] || "/"===tl[i]["TOKEN_STRING"]) || "%"===tl[i]["TOKEN_STRING"]))){998 var sign = tl[i]["TOKEN_STRING"];999 var index_of_first_sign = i;1000 var tl1 = tl.slice(0,index_of_first_sign);1001 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);1002 tree["name"] = sign;1003 var current_index = tree["index"];1004 TREE_addNode(tree,"s_term","");1005 TREE_addNodeAtIndex(tree,current_index,"p_term","");1006 var index_of_node1 = TREE_INDEX-2;1007 var index_of_node2 = TREE_INDEX-1;1008 return s_term(TREE_getTreeAccordingToIndex(tree,index_of_node1),tl1)&&p_term(TREE_getTreeAccordingToIndex(tree,index_of_node2),tl2);1009 }1010 }1011 return p_term(tree,tl);1012}1013p_term = function(tree,tl){1014 if (INCOMPLETE_STATEMENT){1015 return false;1016 }1017 var length_of_tl = len(tl);1018 var count_of_parenthesis = 0;1019 var i = length_of_tl-1;1020 for ( ; 0<=i ; i = i-1){1021 if (tl[i]["TOKEN_STRING"]==="("){1022 count_of_parenthesis = count_of_parenthesis+1;1023 continue;1024 }1025 if (tl[i]["TOKEN_STRING"]===")"){1026 count_of_parenthesis = count_of_parenthesis-1;1027 continue;1028 }1029 if ((count_of_parenthesis===0 && ("^"===tl[i]["TOKEN_STRING"] || "**"===tl[i]["TOKEN_STRING"]))){1030 var sign = "^";1031 var index_of_first_sign = i;1032 var tl1 = tl.slice(0,index_of_first_sign);1033 var tl2 = tl.slice(index_of_first_sign+1,length_of_tl);1034 tree["name"] = sign;1035 var current_index = tree["index"];1036 TREE_addNode(tree,"p_term","");1037 TREE_addNodeAtIndex(tree,current_index,"factor","");1038 var index_of_node1 = TREE_INDEX-2;1039 var index_of_node2 = TREE_INDEX-1;1040 return p_term(TREE_getTreeAccordingToIndex(tree,index_of_node1),tl1)&&factor(TREE_getTreeAccordingToIndex(tree,index_of_node2),tl2);1041 }1042 }1043 return factor(tree,tl);1044}1045factor = function(tree,tl){1046 if (INCOMPLETE_STATEMENT===true){1047 return false;1048 }1049 var length_of_tl = len(tl);1050 if ((term(tl[0]["TOKEN_STRING"],"(") && term(tl[length_of_tl-1]["TOKEN_STRING"],")"))){1051 tree["name"] = "expr";1052 tree["token_class"] = "";1053 return expr(tree,TL_subtl(tl,1,length_of_tl-1));1054 }1055 else{1056 return new_value(tree,tl)||value(tree,tl);1057 }1058}1059assignment = function(tree,tl){1060 var test = self_operator_stm(tree,tl)||self_assignment_stm(tree,tl);1061 if (test===true){1062 return true;1063 }1064 if (INCOMPLETE_STATEMENT===true){1065 return false;1066 }1067 var is_local = false;1068 if (term(tl[0]["TOKEN_STRING"],"local")){1069 is_local = true;1070 }1071 var count = 0;1072 var count_of_equal = 0;1073 var index_of_equal = -1;1074 var i = 0;1075 for (i = 0 ; i<len(tl) ; i = i+1){1076 if (((((term(tl[i]["TOKEN_STRING"],"(") || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"while"))){1077 count = count+1;1078 }1079 else if ((term(tl[i]["TOKEN_STRING"],")") || term(tl[i]["TOKEN_STRING"],"end"))){1080 count = count-1;1081 }1082 if ((count===0 && tl[i]["TOKEN_STRING"]==="=")){1083 count_of_equal = count_of_equal+1;1084 index_of_equal = i;1085 }1086 }1087 if (count_of_equal!==1){1088 return false;1089 }1090 else{1091 var length_of_tl = len(tl);1092 var save_TREE_INDEX = TREE_INDEX;1093 TREE_INDEX = 0;1094 var var_name_tree = TREE_init("var_name");1095 var var_name_list = {};1096 if (is_local===true){1097 var_name_list = tl.slice(1,index_of_equal);1098 }1099 else{1100 var_name_list = tl.slice(0,index_of_equal);1101 }1102 var_name(var_name_tree,var_name_list);1103 TREE_INDEX = 0;1104 var var_value_tree = TREE_init("var_value");1105 var var_value_list = tl.slice(index_of_equal+1,length_of_tl);1106 var_value(var_value_tree,var_value_list);1107 TREE_INDEX = save_TREE_INDEX;1108 var var_name_num = len(var_name_tree["node_list"]);1109 var i = 0;1110 var var_name_nl = var_name_tree["node_list"];1111 var var_value_nl = var_value_tree["node_list"];1112 for ( ; i<var_name_num ; i = i+1){1113 var index = TREE_INDEX;1114 TREE_addNode(tree,"=","");1115 if (is_local===true){1116 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"local","");1117 }1118 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),var_name_nl[i]);1119 if (typeof(var_value_nl[i])==="undefined"){1120 var temp_tree = TREE_init();1121 temp_tree["name"] = "none";1122 temp_tree["token_class"] = "id";1123 temp_tree["node_list"] = {};1124 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),temp_tree);1125 }1126 else{1127 TREE_addTree(TREE_getTreeAccordingToIndex(tree,index),var_value_nl[i]);1128 }1129 }1130 return true;1131 }1132}1133var_name = function(tree,tl){1134 if (INCOMPLETE_STATEMENT===true){1135 return false;1136 }1137 var index_of_comma = TL_indexOfTokenThatHasTokenString(tl,",");1138 if (index_of_comma!==-1){1139 var length_of_tl = len(tl);1140 var tl1 = tl.slice(0,index_of_comma);1141 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1142 return var_name(tree,tl1)&&var_name(tree,tl2);1143 }1144 else{1145 var length_of_tl = len(tl);1146 if (length_of_tl===1){1147 if ("id"===tl[0]["TOKEN_CLASS"]){1148 TREE_addNode(tree,tl[0]["TOKEN_STRING"],"id");1149 return true;1150 }1151 else{1152 return false;1153 }1154 }1155 else{1156 return table_value(tree,tl);1157 }1158 }1159 return false;1160}1161var_value = function(tree,tl){1162 if (INCOMPLETE_STATEMENT===true){1163 return false;1164 }1165 var length_of_tl = len(tl);1166 var index_of_comma = -1;1167 var i = 0;1168 var count = 0;1169 for ( ; i<length_of_tl ; i = i+1){1170 if (((((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"("))){1171 count = count+1;1172 }1173 if ((term(tl[i]["TOKEN_STRING"],"end") || term(tl[i]["TOKEN_STRING"],")"))){1174 count = count-1;1175 }1176 if ((count===0 && term(tl[i]["TOKEN_STRING"],","))){1177 index_of_comma = i;1178 break;1179 }1180 }1181 if (count!==0){1182 INCOMPLETE_STATEMENT = true;1183 return false;1184 }1185 if (index_of_comma!==-1){1186 var tl1 = tl.slice(0,index_of_comma);1187 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1188 var index_of_tl1 = TREE_INDEX;1189 TREE_addNode(tree,"value","");1190 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&var_value(tree,tl2);1191 }1192 else{1193 var index_of_tl = TREE_INDEX;1194 TREE_addNode(tree,"value","");1195 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl),tl);1196 }1197}1198func_assign = function(tree,tl){1199 if (INCOMPLETE_STATEMENT===true){1200 return false;1201 }1202 var length_of_tl = len(tl);1203 if (((4<=length_of_tl && term(tl[0]["TOKEN_STRING"],"def")) && term(tl[1]["TOKEN_STRING"],"("))){1204 var index_of_right = -1;1205 var count = 0;1206 var i = 0;1207 for ( ; i<length_of_tl ; i = i+1){1208 if (term(tl[i]["TOKEN_STRING"],"(")){1209 count = count+1;1210 }1211 if (term(tl[i]["TOKEN_STRING"],")")){1212 count = count-1;1213 if (count===0){1214 index_of_right = i;1215 break;1216 }1217 }1218 }1219 if (index_of_right===-1){1220 INCOMPLETE_STATEMENT = true;1221 console.log("INCOMPLETE_STATEMENT func_assign\n");1222 process.exit(0);1223 }1224 else{1225 TREE_addNode(tree,"def","");1226 var index = TREE_INDEX;1227 TREE_addNode(tree,"params","");1228 var params_tl = {};1229 if (index_of_right!==2){1230 params_tl = tl.slice(2,index_of_right);1231 }1232 else{1233 params_tl = {};1234 var add_token = Token_init();1235 add_token["TOKEN_CLASS"] = "id";1236 add_token["TOKEN_STRING"] = "none";1237 params_tl.append(add_token);1238 }1239 return params(TREE_getTreeAccordingToIndex(tree,index),params_tl);1240 }1241 }1242 return false;1243}1244return_stm = function(tree,tl){1245 if (INCOMPLETE_STATEMENT===true){1246 return false;1247 }1248 var length_of_tl = len(tl);1249 if ((2<=length_of_tl && term(tl[0]["TOKEN_STRING"],"return"))){1250 var index1 = TREE_INDEX;1251 TREE_addNode(tree,"return","");1252 var index2 = TREE_INDEX;1253 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index1),"value","");1254 return value(TREE_getTreeAccordingToIndex(tree,index2),tl.slice(1,length_of_tl));1255 }1256 return false;1257}1258func_value = function(tree,tl){1259 if (INCOMPLETE_STATEMENT===true){1260 return false;1261 }1262 var length_of_tl = len(tl);1263 if ((term(tl[0]["TOKEN_STRING"],"def") && term(tl[length_of_tl-1]["TOKEN_STRING"],"end"))){1264 tree["name"] = "func_value";1265 tree["token_class"] = "";1266 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1267 if (index_of_then===-1){1268 INCOMPLETE_STATEMENT = true;1269 return false;1270 }1271 func_assign(tree,tl.slice(0,index_of_then+1));1272 var walley_statements_index = TREE_INDEX;1273 TREE_addNode(tree,"walley_statements","");1274 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1275 }1276 return false;1277}1278params = function(tree,tl){1279 if (INCOMPLETE_STATEMENT===true){1280 return false;1281 }1282 if (len(tl)===0){1283 return true;1284 }1285 var length_of_tl = len(tl);1286 var index_of_comma = -1;1287 var count = 0;1288 var i = 0;1289 for (i = 0 ; i<length_of_tl ; i = i+1){1290 if (term(tl[i]["TOKEN_STRING"],"(")){1291 count = count+1;1292 continue;1293 }1294 if (term(tl[i]["TOKEN_STRING"],")")){1295 count = count-1;1296 continue;1297 }1298 if ((count===0 && term(tl[i]["TOKEN_STRING"],","))){1299 index_of_comma = i;1300 break;1301 }1302 }1303 if (index_of_comma===-1){1304 if (assignment(tree,tl)===true){1305 return true;1306 }1307 else{1308 var index = TREE_INDEX;1309 TREE_addNode(tree,"value","");1310 return value(TREE_getTreeAccordingToIndex(tree,index),tl);1311 }1312 }1313 else{1314 var tl1 = tl.slice(0,index_of_comma);1315 var tl2 = tl.slice(index_of_comma+1,length_of_tl);1316 if (assignment(tree,tl1)===true){1317 return params(tree,tl2);1318 }1319 else{1320 var index_of_tl1 = TREE_INDEX;1321 TREE_addNode(tree,"value","");1322 return value(TREE_getTreeAccordingToIndex(tree,index_of_tl1),tl1)&&params(tree,tl2);1323 }1324 }1325}1326func = function(tree,tl){1327 if (INCOMPLETE_STATEMENT===true){1328 return false;1329 }1330 var length_of_tl = len(tl);1331 var index_of_left = TL_indexOfTokenThatHasTokenString(tl,"(");1332 var index_of_right = -1;1333 if (index_of_left===-1){1334 return false;1335 }1336 var i = 0;1337 var count = 0;1338 for ( ; i<length_of_tl ; i = i+1){1339 if (term(tl[i]["TOKEN_STRING"],"(")){1340 count = count+1;1341 }1342 else if (term(tl[i]["TOKEN_STRING"],")")){1343 count = count-1;1344 if (count===0){1345 index_of_right = i;1346 break;1347 }1348 }1349 }1350 if (index_of_right===-1){1351 INCOMPLETE_STATEMENT = true;1352 return false;1353 }1354 if (((index_of_right+1!==length_of_tl || index_of_left===-1) || index_of_left===0)){1355 return false;1356 }1357 else{1358 var test_id = tl.slice(0,index_of_left);1359 var params_tl = {};1360 if (index_of_left+1===index_of_right){1361 params_tl = {};1362 }1363 else{1364 params_tl = tl.slice(index_of_left+1,index_of_right);1365 }1366 var length_of_test_id = len(test_id);1367 if ((length_of_test_id!==1 || test_id[0]["TOKEN_CLASS"]!=="id")){1368 return false;1369 }1370 tree["name"] = "func";1371 tree["token_class"] = "";1372 TREE_addNode(tree,"","call");1373 TREE_addNode(TREE_getTreeAccordingToIndex(tree,TREE_INDEX-1),toString(test_id[0]["TOKEN_STRING"]),"string");1374 var index = TREE_INDEX;1375 TREE_addNode(tree,"params","");1376 return params(TREE_getTreeAccordingToIndex(tree,index),params_tl);1377 }1378}1379relation = function(tree,tl){1380 if (INCOMPLETE_STATEMENT===true){1381 return false;1382 }1383 var length_of_tl = len(tl);1384 var i = length_of_tl-1;1385 var count = 0;1386 var index_of_and_or = -1;1387 for ( ; 0<=i ; i = i-1){1388 if (term(tl[i]["TOKEN_STRING"],"(")){1389 count = count+1;1390 continue;1391 }1392 if (term(tl[i]["TOKEN_STRING"],")")){1393 count = count-1;1394 continue;1395 }1396 if (((count===0 && term(tl[i]["TOKEN_CLASS"],"relation")) && tl[i]["TOKEN_STRING"]!=="not")){1397 index_of_and_or = i;1398 var and_or_string = tl[i]["TOKEN_STRING"];1399 var tl1 = tl.slice(0,index_of_and_or);1400 var tl2 = tl.slice(index_of_and_or+1,length_of_tl);1401 var index = TREE_INDEX;1402 TREE_addNode(tree,and_or_string,"");1403 var index1 = TREE_INDEX;1404 TREE_addNodeAtIndex(tree,index,"relation","");1405 var index2 = TREE_INDEX;1406 TREE_addNodeAtIndex(tree,index,"relation","");1407 return relation(TREE_getTreeAccordingToIndex(tree,index1),tl1)&&relation(TREE_getTreeAccordingToIndex(tree,index2),tl2);1408 }1409 }1410 if (term(tl[0]["TOKEN_STRING"],"not")){1411 TREE_addNode(tree,"not","");1412 var index = TREE_INDEX;1413 TREE_addNodeAtIndex(tree,index-1,"relation","");1414 return relation(TREE_getTreeAccordingToIndex(tree,index),tl.slice(1,length_of_tl));1415 }1416 return simple_relation(tree,tl);1417}1418simple_relation = function(tree,tl){1419 if (INCOMPLETE_STATEMENT===true){1420 return false;1421 }1422 var length_of_tl = len(tl);1423 if ((term("(",tl[0]["TOKEN_STRING"]) && term(")",tl[length_of_tl-1]["TOKEN_STRING"]))){1424 return relation(tree,tl.slice(1,length_of_tl-1));1425 }1426 else{1427 tree["name"] = "simple_relation";1428 var index_of_judge_sign = TL_indexOfTokenThatHasTokenClass(tl,"judge_sign");1429 if (index_of_judge_sign===-1){1430 return expr(tree,tl);1431 }1432 var tl1 = tl.slice(0,index_of_judge_sign);1433 var tl2 = tl.slice(index_of_judge_sign+1,length_of_tl);1434 var judge_sign = tl[index_of_judge_sign]["TOKEN_STRING"];1435 if ((term(">=",judge_sign) || term(">",judge_sign))){1436 var temp_tl = tl1;1437 tl1 = tl2;1438 tl2 = temp_tl;1439 if (term(">=",judge_sign)){1440 judge_sign = "<=";1441 }1442 else{1443 judge_sign = "<";1444 }1445 }1446 var index = TREE_INDEX;1447 TREE_addNode(tree,judge_sign,"");1448 var temp_tree = TREE_getTreeAccordingToIndex(tree,index);1449 var index1 = TREE_INDEX;1450 TREE_addNode(temp_tree,"value","");1451 var index2 = TREE_INDEX;1452 TREE_addNode(temp_tree,"value","");1453 return value(TREE_getTreeAccordingToIndex(tree,index1),tl1)&&value(TREE_getTreeAccordingToIndex(tree,index2),tl2);1454 }1455 return false;1456}1457if_stms = function(tree,tl){1458 if (INCOMPLETE_STATEMENT===true){1459 return false;1460 }1461 var length_of_tl = len(tl);1462 if (term(tl[0]["TOKEN_STRING"],"if")){1463 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1464 if (index_of_then===-1){1465 INCOMPLETE_STATEMENT = true;1466 return false;1467 }1468 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1469 var relation_tl = tl.slice(1,index_of_then);1470 TREE_addNode(tree,"if","");1471 var index = TREE_INDEX;1472 TREE_addNode(tree,"relation","");1473 var walley_statements_index = TREE_INDEX;1474 TREE_addNode(tree,"walley_statements","");1475 return relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl)&&walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1));1476 }1477 else{1478 INCOMPLETE_STATEMENT = true;1479 return false;1480 }1481 }1482 return false;1483}1484elif_stms = function(tree,tl){1485 if (INCOMPLETE_STATEMENT===true){1486 return false;1487 }1488 var length_of_tl = len(tl);1489 if (term(tl[0]["TOKEN_STRING"],"elif")){1490 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1491 if (index_of_then===-1){1492 INCOMPLETE_STATEMENT = true;1493 return false;1494 }1495 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1496 var relation_tl = tl.slice(1,index_of_then);1497 TREE_addNode(tree,"elif","");1498 var index = TREE_INDEX;1499 TREE_addNode(tree,"relation","");1500 var walley_statements_index = TREE_INDEX;1501 TREE_addNode(tree,"walley_statements","");1502 return relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl)&&walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1));1503 }1504 else{1505 INCOMPLETE_STATEMENT = true;1506 return false;1507 }1508 }1509 return false;1510}1511else_stms = function(tree,tl){1512 if (INCOMPLETE_STATEMENT===true){1513 return false;1514 }1515 var length_of_tl = len(tl);1516 if (term(tl[0]["TOKEN_STRING"],"else")){1517 if (term(tl[length_of_tl-1]["TOKEN_STRING"],"end")){1518 TREE_addNode(tree,"else","");1519 var walley_statements_index = TREE_INDEX;1520 TREE_addNode(tree,"walley_statements","");1521 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(1,length_of_tl-1));1522 }1523 else{1524 INCOMPLETE_STATEMENT = true;1525 return false;1526 }1527 }1528 return false;1529}1530while_stms = function(tree,tl){1531 if (INCOMPLETE_STATEMENT===true){1532 return false;1533 }1534 var length_of_tl = len(tl);1535 if (term(tl[0]["TOKEN_STRING"],"while")){1536 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1537 if (index_of_then===-1){1538 INCOMPLETE_STATEMENT = true;1539 return false;1540 }1541 if ((term(tl[length_of_tl-1]["TOKEN_STRING"],"end") && 2<length_of_tl)){1542 var relation_tl = tl.slice(1,index_of_then);1543 TREE_addNode(tree,"while","");1544 var index = TREE_INDEX;1545 TREE_addNode(tree,"relation","");1546 var walley_statements_index = TREE_INDEX;1547 TREE_addNode(tree,"walley_statements","");1548 return (relation(TREE_getTreeAccordingToIndex(tree,index),relation_tl) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1549 }1550 else{1551 INCOMPLETE_STATEMENT = true;1552 return false;1553 }1554 }1555 return false;1556}1557for_stms = function(tree,tl){1558 if (term(tl[0]["TOKEN_STRING"],"for")===false){1559 return false;1560 }1561 if (INCOMPLETE_STATEMENT===true){1562 return false;1563 }1564 var length_of_tl = len(tl);1565 if ((term(tl[4]["TOKEN_STRING"],"in") || term(tl[2]["TOKEN_STRING"],"in"))){1566 var index_of_then = -1;1567 var i = 0;1568 for ( ; i<length_of_tl ; i = i+1){1569 if (term(tl[i]["TOKEN_STRING"],"then")){1570 index_of_then = i;1571 break;1572 }1573 }1574 TREE_addNode(tree,"foreach","");1575 if (term(tl[1]["TOKEN_CLASS"],"id")===false){1576 Walley_Print_Error(TL_toString(tl),"for each statements error, for i,v in value, i,v must be id",tl[1]["TOKEN_START"]);1577 }1578 TREE_addNode(tree,tl[1]["TOKEN_STRING"],"foreach_index");1579 if (term(tl[2]["TOKEN_STRING"],",")){1580 if (term(tl[3]["TOKEN_CLASS"],"id")===false){1581 Walley_Print_Error(TL_toString(tl),"for each statements error, for i,v in value, i,v must be id",tl[3]["TOKEN_START"]);1582 }1583 TREE_addNode(tree,tl[3]["TOKEN_STRING"],"foreach_value");1584 var index = TREE_INDEX;1585 TREE_addNode(tree,"","foreach_in");1586 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"value","");1587 index = index+1;1588 value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(5,index_of_then));1589 }1590 else{1591 TREE_addNode(tree,"","foreach_value");1592 var index = TREE_INDEX;1593 TREE_addNode(tree,"","foreach_in");1594 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),"value","");1595 index = index+1;1596 value(TREE_getTreeAccordingToIndex(tree,index),tl.slice(3,index_of_then));1597 }1598 var walley_statements_index = TREE_INDEX;1599 TREE_addNode(tree,"walley_statements","");1600 return walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1601 }1602 var num_of_comma = 0;1603 var count_of_p = 0;1604 var index_of_comma = {0:-1,1:-1,2:-1};1605 var index = 0;1606 var i = 0;1607 var index_of_then = -1;1608 for ( ; i<length_of_tl ; i = i+1){1609 if (term(tl[i]["TOKEN_STRING"],"then")){1610 index_of_then = i;1611 break;1612 }1613 if (term(tl[i]["TOKEN_STRING"],"(")){1614 count_of_p = count_of_p+1;1615 continue;1616 }1617 if (term(tl[i]["TOKEN_STRING"],")")){1618 count_of_p = count_of_p-1;1619 continue;1620 }1621 if ((count_of_p===0 && term(tl[i]["TOKEN_STRING"],","))){1622 if (index<2){1623 index_of_comma[index] = i;1624 index = index+1;1625 }1626 num_of_comma = num_of_comma+1;1627 }1628 }1629 if ((index_of_then===-1 || term(tl[length_of_tl-1]["TOKEN_STRING"],"end")===false)){1630 INCOMPLETE_STATEMENT = true;1631 return false;1632 }1633 if (((length_of_tl!==2 && num_of_comma!==0) && num_of_comma<=2)){1634 if (num_of_comma===1){1635 var simple_relation_tl = tl.slice(1,index_of_comma[0]);1636 var assignment_tl = tl.slice(index_of_comma[0]+1,index_of_then);1637 TREE_addNode(tree,"for","");1638 var index_of_sr = TREE_INDEX;1639 TREE_addNode(tree,"simple_relation","");1640 var index_of_a = TREE_INDEX;1641 TREE_addNode(tree,"assignment","");1642 var walley_statements_index = TREE_INDEX;1643 TREE_addNode(tree,"walley_statements","");1644 return ((simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a),assignment_tl)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1645 }1646 else{1647 if (term(tl[1]["TOKEN_STRING"],",")){1648 var simple_relation_tl = tl.slice(2,index_of_comma[1]);1649 var assignment_tl = tl.slice(index_of_comma[1]+1,index_of_then);1650 TREE_addNode(tree,"for","");1651 var index_of_sr = TREE_INDEX;1652 TREE_addNode(tree,"simple_relation","");1653 var index_of_a = TREE_INDEX;1654 TREE_addNode(tree,"assignment","");1655 var walley_statements_index = TREE_INDEX;1656 TREE_addNode(tree,"walley_statements","");1657 return ((simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a),assignment_tl)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1658 }1659 else{1660 var assignment_tl1 = tl.slice(1,index_of_comma[0]);1661 var simple_relation_tl = tl.slice(index_of_comma[0]+1,index_of_comma[1]);1662 var assignment_tl2 = tl.slice(index_of_comma[1]+1,index_of_then);1663 TREE_addNode(tree,"for","");1664 var index_of_a_tl1 = TREE_INDEX;1665 TREE_addNode(tree,"assignment","");1666 var index_of_sr = TREE_INDEX;1667 TREE_addNode(tree,"simple_relation","");1668 var index_of_a_tl2 = TREE_INDEX;1669 TREE_addNode(tree,"assignment","");1670 var walley_statements_index = TREE_INDEX;1671 TREE_addNode(tree,"walley_statements","");1672 return (((assignment(TREE_getTreeAccordingToIndex(tree,index_of_a_tl1),assignment_tl1) && simple_relation(TREE_getTreeAccordingToIndex(tree,index_of_sr),simple_relation_tl)) && assignment(TREE_getTreeAccordingToIndex(tree,index_of_a_tl2),assignment_tl2)) && walley_statements(TREE_getTreeAccordingToIndex(tree,walley_statements_index),tl.slice(index_of_then+1,length_of_tl-1)))&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1673 }1674 }1675 }1676 return false;1677}1678func_stms = function(tree,tl){1679 if (INCOMPLETE_STATEMENT===true){1680 return false;1681 }1682 var length_of_tl = len(tl);1683 if (term(tl[0]["TOKEN_STRING"],"def")){1684 if ((2<length_of_tl && term(tl[length_of_tl-1]["TOKEN_STRING"],"then"))){1685 TREE_addNode(tree,"def","");1686 var func_tl = tl.slice(1,length_of_tl-1);1687 var index = TREE_INDEX;1688 TREE_addNode(tree,"func","");1689 return func(TREE_getTreeAccordingToIndex(tree,index),func_tl)&&end_stm(tree,tl.slice(length_of_tl-1,length_of_tl));1690 }1691 else{1692 INCOMPLETE_STATEMENT = true;1693 return false;1694 }1695 }1696 return false;1697}1698end_stm = function(tree,tl){1699 if (INCOMPLETE_STATEMENT===true){1700 return false;1701 }1702 if ((len(tl)===1 && term(tl[0]["TOKEN_CLASS"],"end"))){1703 TREE_addNode(tree,"end","");1704 return true;1705 }1706 return false;1707}1708def_stms = function(tree,tl){1709 if (INCOMPLETE_STATEMENT===true){1710 return false;1711 }1712 var length_of_tl = len(tl);1713 if ((term(tl[0]["TOKEN_STRING"],"def") && term(tl[1]["TOKEN_STRING"],"(")===false)){1714 var index_of_then = TL_indexOfTokenThatHasTokenString(tl,"then");1715 var index_of_left_bracket = TL_indexOfTokenThatHasTokenString(tl,"(");1716 if (index_of_then===-1){1717 INCOMPLETE_STATEMENT = true;1718 return false;1719 }1720 if (term(tl[length_of_tl-1]["TOKEN_STRING"],"end")===false){1721 INCOMPLETE_STATEMENT = true;1722 return false;1723 }1724 var new_tl = {};1725 var begin = 1;1726 var i = 0;1727 for ( ; i<index_of_left_bracket ; i = i+1){1728 if (begin<=i){1729 new_tl.append(tl[i]);1730 }1731 }1732 var add_token = Token_init();1733 add_token["TOKEN_STRING"] = "=";1734 add_token["TOKEN_CLASS"] = "assignment_operator";1735 new_tl.append(add_token);1736 i = 0;1737 for (i = 0 ; i<length_of_tl ; i = i+1){1738 if ((begin<=i && i<index_of_left_bracket)){1739 continue;1740 }1741 new_tl.append(tl[i]);1742 }1743 return assignment(tree,new_tl);1744 }1745 else{1746 return false;1747 }1748}1749self_operator_stm = function(tree,tl){1750 if (INCOMPLETE_STATEMENT===true){1751 return false;1752 }1753 var length_of_tl = len(tl);1754 if (tl[length_of_tl-1]["TOKEN_CLASS"]==="self_operator"){1755 var index = TREE_INDEX;1756 TREE_addNode(tree,"self_operator_stm","");1757 var valid_var_name = var_name(TREE_getTreeAccordingToIndex(tree,index),tl.slice(0,length_of_tl-1));1758 if (valid_var_name===true){1759 TREE_addNode(TREE_getTreeAccordingToIndex(tree,index),tl[length_of_tl-1]["TOKEN_STRING"],"self_operator");1760 return true;1761 }1762 else{1763 console.log("Error.. invalid self operation\n");1764 process.exit(0);1765 }1766 }1767 else{1768 return false;1769 }1770}1771self_assignment_stm = function(tree,tl){1772 if (INCOMPLETE_STATEMENT===true){1773 return false;1774 }1775 var length_of_tl = len(tl);1776 var index_of_self_assignment_operator = TL_indexOfTokenThatHasTokenClass(tl,"self_assignment");1777 if (index_of_self_assignment_operator===-1){1778 return false;1779 }1780 else{1781 var var_name_tl = tl.slice(0,index_of_self_assignment_operator);1782 var var_value_tl = tl.slice(index_of_self_assignment_operator+1,length_of_tl);1783 var temp_tree = TREE_init("self_assignment_stm");1784 var valid_var_name = var_name(temp_tree,var_name_tl);1785 if (valid_var_name===false){1786 return false;1787 }1788 TREE_addNode(temp_tree,tl[index_of_self_assignment_operator]["TOKEN_STRING"],"self_assignment");1789 var index2 = TREE_INDEX;1790 TREE_addNode(temp_tree,"","value");1791 var valid_var_value = value(TREE_getTreeAccordingToIndex(temp_tree,index2),var_value_tl);1792 if (valid_var_value===false){1793 return false;1794 }1795 else{1796 TREE_addTree(tree,temp_tree);1797 return true;1798 }1799 }1800}1801import_stm = function(tree,tl){1802 if (INCOMPLETE_STATEMENT===true){1803 return false;1804 }1805 if (tl[0]["TOKEN_CLASS"]==="import"){1806 TREE_addNode(tree,"import","");1807 var index = TREE_INDEX;1808 var length_of_tl = len(tl);1809 if ((length_of_tl!==2 || tl[1]["TOKEN_CLASS"]!=="string")){1810 console.log("Error.. only support import statements like 'import \" hello.wy \"'");1811 process.exit(0);1812 }1813 TREE_addNode(tree,tl[1]["TOKEN_STRING"],"import_file");1814 return true;1815 }1816 else{1817 return false;1818 }1819}1820statements = function(tree,tl){1821 if (INCOMPLETE_STATEMENT===true){1822 return false;1823 }1824 return (((((((((import_stm(tree,tl) || return_stm(tree,tl)) || if_stms(tree,tl)) || elif_stms(tree,tl)) || else_stms(tree,tl)) || while_stms(tree,tl)) || for_stms(tree,tl)) || def_stms(tree,tl)) || end_stm(tree,tl)) || assignment(tree,tl))||value(tree,tl);1825}1826walley_statements = function(tree,tl){1827 if (INCOMPLETE_STATEMENT===true){1828 return false;1829 }1830 var temp_tl = {val:{}};1831 var begin = {val:0};1832 while (sentences_separation(tl,temp_tl,begin)===true){1833 if (INCOMPLETE_STATEMENT===true){1834 return false;1835 }1836 var index = TREE_INDEX;1837 TREE_addNode(tree,"statements","");1838 if (statements(TREE_getTreeAccordingToIndex(tree,index),temp_tl["val"])===false){1839 console.log("Walley Statements Parse Error\n");1840 return false;1841 }1842 }1843 if (INCOMPLETE_STATEMENT===true){1844 return false;1845 }1846 return true;1847}1848sentences_separation = function(tl,output_tl,begin){1849 var length_of_tl = len(tl);1850 if (length_of_tl<=begin["val"]){1851 return false;1852 }1853 i = begin["val"];1854 var count_of_parenthesis = 0;1855 for ( ; i<length_of_tl ; i = i+1){1856 if (tl[i]["TOKEN_STRING"]==="("){1857 count_of_parenthesis++;1858 }1859 if (tl[i]["TOKEN_STRING"]===")"){1860 count_of_parenthesis--;1861 }1862 if ((((count_of_parenthesis===0 && i<length_of_tl-1) && (((((term(tl[i]["TOKEN_CLASS"],"num") || term(tl[i]["TOKEN_CLASS"],"string")) || term(tl[i]["TOKEN_CLASS"],"id")) || term(tl[i]["TOKEN_CLASS"],"list_table")) || term(tl[i]["TOKEN_STRING"],")")) || term(tl[i]["TOKEN_CLASS"],"self_operator"))) && ((((((term(tl[1+i]["TOKEN_CLASS"],"id") || term(tl[1+i]["TOKEN_CLASS"],"num")) || term(tl[i+1]["TOKEN_CLASS"],"return")) || term(tl[i+1]["TOKEN_STRING"],"continue")) || term(tl[1+i]["TOKEN_STRING"],"break")) || term(tl[1+i]["TOKEN_CLASS"],"local")) || term(tl[i+1]["TOKEN_CLASS"],"import")))){1863 var end_index = i+1;1864 var ahead_tl = tl.slice(begin["val"],end_index);1865 output_tl["val"] = ahead_tl;1866 begin["val"] = end_index;1867 return true;1868 }1869 if ((count_of_parenthesis===0 && ((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"while")))){1870 if (begin["val"]!==i){1871 if ((term(tl[i]["TOKEN_STRING"],"def") && term(tl[i+1]["TOKEN_STRING"],"("))){1872 console.log("");1873 }1874 else{1875 var end_index = i;1876 var ahead_tl = tl.slice(begin["val"],end_index);1877 begin["val"] = end_index;1878 output_tl["val"] = ahead_tl;1879 return true;1880 }1881 }1882 var count = 0;1883 for ( ; i<length_of_tl ; i = i+1){1884 if ((((term(tl[i]["TOKEN_STRING"],"def") || term(tl[i]["TOKEN_STRING"],"for")) || term(tl[i]["TOKEN_STRING"],"if")) || term(tl[i]["TOKEN_STRING"],"while"))){1885 count = count+1;1886 }1887 if (term(tl[i]["TOKEN_STRING"],"end")){1888 count = count-1;1889 }1890 if (count===0){1891 break;1892 }1893 }1894 if (count===0){1895 var end_index = i+1;1896 var ahead_tl = tl.slice(begin["val"],end_index);1897 output_tl["val"] = ahead_tl;1898 begin["val"] = end_index;1899 return true;1900 }1901 else{1902 INCOMPLETE_STATEMENT = true;1903 return false;1904 }1905 }1906 if (term(tl[i]["TOKEN_STRING"],"if")){1907 if (begin["val"]!==i){1908 var end_index = i;1909 var ahead_tl = tl.slice(begin["val"],end_index);1910 begin["val"] = end_index;1911 output_tl["val"] = ahead_tl;1912 return true;1913 }1914 var count_of_if = 0;1915 var count_of_end = 0;1916 for ( ; i<length_of_tl ; i = i+1){1917 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1918 count_of_if = count_of_if+1;1919 count_of_end = count_of_end+1;1920 }1921 if (term(tl[i]["TOKEN_STRING"],"end")){1922 count_of_if = count_of_if-1;1923 count_of_end = count_of_end-1;1924 }1925 if (count_of_end===0){1926 break;1927 }1928 if ((count_of_if===1 && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){1929 var end_index = i;1930 var ahead_tl = tl.slice(begin["val"],end_index);1931 var end_token = Token_init();1932 end_token["TOKEN_STRING"] = "end";1933 end_token["TOKEN_CLASS"] = "end";1934 ahead_tl.append(end_token);1935 begin["val"] = end_index;1936 output_tl["val"] = ahead_tl;1937 return true;1938 }1939 }1940 if ((count_of_if!==count_of_end || count_of_if!==0)){1941 INCOMPLETE_STATEMENT = true;1942 return false;1943 }1944 else{1945 var end_index = i+1;1946 var ahead_tl = tl.slice(begin["val"],end_index);1947 begin["val"] = end_index-1;1948 output_tl["val"] = ahead_tl;1949 return true;1950 }1951 }1952 if (term(tl[i]["TOKEN_STRING"],"elif")){1953 var count_of_if = 0;1954 var count_of_end = 0;1955 var temp_i = i;1956 for ( ; i<length_of_tl ; i = i+1){1957 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1958 count_of_if = count_of_if+1;1959 count_of_end = count_of_end+1;1960 }1961 if (term(tl[i]["TOKEN_STRING"],"end")){1962 count_of_end = count_of_end-1;1963 count_of_if = count_of_if-1;1964 }1965 if (((count_of_if===0 && i!==temp_i) && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){1966 var end_index = i;1967 var ahead_tl = tl.slice(begin["val"],end_index);1968 var end_token = Token_init();1969 end_token["TOKEN_STRING"] = "end";1970 end_token["TOKEN_CLASS"] = "end";1971 ahead_tl.append(end_token);1972 begin["val"] = end_index;1973 output_tl["val"] = ahead_tl;1974 return true;1975 }1976 if ((count_of_end===-1 && count_of_if===-1)){1977 var end_index = i+1;1978 var ahead_tl = tl.slice(begin["val"],end_index);1979 begin["val"] = end_index-1;1980 output_tl["val"] = ahead_tl;1981 return true;1982 }1983 }1984 INCOMPLETE_STATEMENT = true;1985 return false;1986 }1987 if (term(tl[i]["TOKEN_STRING"],"else")){1988 var count_of_if = 0;1989 var count_of_end = 0;1990 var temp_i = i;1991 for ( ; i<length_of_tl ; i = i+1){1992 if ((((term(tl[i]["TOKEN_STRING"],"if") || term(tl[i]["TOKEN_STRING"],"def")) || term(tl[i]["TOKEN_STRING"],"while")) || term(tl[i]["TOKEN_STRING"],"for"))){1993 count_of_if = count_of_if+1;1994 count_of_end = count_of_end+1;1995 }1996 if (term(tl[i]["TOKEN_STRING"],"end")){1997 count_of_if = count_of_if-1;1998 count_of_end = count_of_end-1;1999 }2000 if (((count_of_if===0 && i!==temp_i) && (term(tl[i]["TOKEN_STRING"],"elif") || term(tl[i]["TOKEN_STRING"],"else")))){2001 Walley_Print_Error(TL_toString(temp_tl),"elif or else statements error",tl[i]["TOKEN_START"]);2002 }2003 if (count_of_end===-1){2004 var end_index = i+1;2005 var ahead_tl = tl.slice(begin["val"],end_index);2006 begin["val"] = end_index-1;2007 output_tl["val"] = ahead_tl;2008 return true;2009 }2010 }2011 INCOMPLETE_STATEMENT = true;2012 return false;2013 }2014 if ((count_of_parenthesis===0 && term(tl[i]["TOKEN_STRING"],"end"))){2015 var end_index = i;2016 if (begin["val"]<i){2017 var ahead_tl = tl.slice(begin["val"],end_index);2018 begin["val"] = end_index;2019 output_tl["val"] = ahead_tl;2020 return true;2021 }2022 else{2023 begin["val"] = end_index;2024 }2025 end_index = i+1;2026 var ahead_tl = tl.slice(begin["val"],end_index);2027 begin["val"] = end_index;2028 output_tl["val"] = ahead_tl;2029 return true;2030 }2031 }2032 if (begin["val"]<length_of_tl){2033 var ahead_tl = tl.slice(begin["val"],length_of_tl);2034 begin["val"] = length_of_tl;2035 output_tl["val"] = ahead_tl;2036 return true;2037 }2038 return false;2039}2040parser = function(tl){2041 TREE_INDEX = 0;2042 var output_tree = TREE_init("walley_statements");2043 if (len(tl)===0){2044 return output_tree;2045 }2046 if ((walley_statements(output_tree,tl)===false && INCOMPLETE_STATEMENT===false)){2047 console.log("Fail to parse statements\n");2048 }2049 return output_tree;2050}2051ism_operator = function(input_str){2052 if ((((((term(input_str,"+") || term(input_str,"-")) || term(input_str,"*")) || term(input_str,"/")) || term(input_str,"^")) || term(input_str,"%"))){2053 return true;2054 }2055 return false;2056}2057Walley_Calculation = function(value1,value2,sign){2058 if ((value1[0]!=="\"" && value2[0]!=="\"")){2059 if (sign==="^"){2060 return eval("Math.pow("+value1+","+value2+")");2061 }2062 return eval(value1+sign+value2);2063 }2064 else{2065 var value1IsString = false;2066 var value2IsString = false;2067 if (value1[0]==="\""){2068 value1 = value1.slice(1,len(value1)-1);2069 value1IsString = true;2070 }2071 if (value2[0]==="\""){2072 value2 = value2.slice(1,len(value2)-1);2073 value2IsString = true;2074 }2075 if (sign[0]==="+"){2076 var output_str = "\""+value1+value2+"\"";2077 return output_str;2078 }2079 else if (sign[0]==="*"){2080 if ((value1IsString===true && value2IsString===true)){2081 console.log("Error.. Can not multiply two string %s and %s\n",value1,value2);2082 process.exit(0);2083 }2084 else{2085 var num = 0;2086 var mult_str = "";2087 if (value1IsString===true){2088 mult_str = value1;2089 num = parseInt(value2);2090 }2091 else{2092 mult_str = value2;2093 num = parseInt(value1);2094 }2095 var output_str = "\"";2096 var i = 0;2097 for ( ; i<num ; i = i+1){2098 output_str = output_str+mult_str;2099 }2100 output_str = output_str+"\"";2101 return output_str;2102 }2103 }2104 else{2105 console.log("Error.. Sign %s can not be used for string calculation for %s and %s\n",sign,value1,value2);2106 process.exit(0);2107 }2108 }2109}2110appendSpacesAhead = function(input_str,num){2111 for (i = 0 ; i<num ; i = i+1){2112 input_str = " "+input_str;2113 }2114 return input_str;2115}2116isString = function(input_str){2117 if ((input_str[0]!=="\"" || input_str[input_str["length"]-1]!=="\"")){2118 return false;2119 }2120 var count = 0;2121 var i = 0;2122 var length = input_str["length"];2123 for ( ; i<length ; i = i+1){2124 if (input_str[i]==="\""){2125 count = count+1;2126 }2127 }2128 if (count!==2){2129 return false;2130 }2131 else{2132 return true;2133 }2134}2135js_isTableValue = false;2136Code_Generation_2_Javascript = function(sl,tree){2137 if (term(tree["token_class"],"id")){2138 if (term(tree["name"],"continue")){2139 return "continue;";2140 }2141 if (term(tree["name"],"break")){2142 return "break;";2143 }2144 if (term(tree["name"],"none")){2145 return "null";2146 }2147 return tree["name"];2148 }2149 else if (term(tree["name"],"walley_statements")){2150 var nl = tree["node_list"];2151 var output_str = "";2152 var i = 0;2153 var length_of_nl = len(nl);2154 for (i = 0 ; i<length_of_nl ; i = i+1){2155 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2156 if (len(temp_str)!==0){2157 temp_str = appendSpacesAhead(temp_str,BEAUTIFUL_SPACES);2158 output_str = output_str+temp_str;2159 if (output_str[len(output_str)-1]!=="\n"){2160 if (output_str[len(output_str)-1]!==";"){2161 output_str = output_str+";\n";2162 }2163 else{2164 output_str = output_str+"\n";2165 }2166 }2167 }2168 }2169 return output_str;2170 }2171 else if (term(tree["name"],"statements")){2172 nl = tree["node_list"];2173 if (term(nl[0]["name"],"if")){2174 var append_str = "if (";2175 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2176 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2177 append_str = append_str+judge_str;2178 append_str = append_str+"){\n";2179 var i = 2;2180 var length_of_nl = len(nl);2181 var output_str = "";2182 for (i = 2 ; i<length_of_nl ; i = i+1){2183 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2184 if (len(temp_str)!==0){2185 output_str = output_str+temp_str;2186 if (output_str[len(output_str)-1]!=="\n"){2187 if (output_str[len(output_str)-1]!==";"){2188 output_str = output_str+";\n";2189 }2190 else{2191 output_str = output_str+"\n";2192 }2193 }2194 }2195 }2196 append_str = append_str+output_str;2197 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2198 return append_str;2199 }2200 else if (term(nl[0]["name"],"elif")){2201 var append_str = "}\n";2202 append_str = appendSpacesAhead(append_str,BEAUTIFUL_SPACES-4);2203 append_str = append_str+appendSpacesAhead("else if (",BEAUTIFUL_SPACES);2204 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2205 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2206 append_str = append_str+judge_str;2207 append_str = append_str+"){\n";2208 var i = 2;2209 var length_of_nl = len(nl);2210 var output_str = "";2211 for (i = 2 ; i<length_of_nl ; i = i+1){2212 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2213 if (len(temp_str)!==0){2214 output_str = output_str+temp_str;2215 if (output_str[len(output_str)-1]!=="\n"){2216 if (output_str[len(output_str)-1]!==";"){2217 output_str = output_str+";\n";2218 }2219 else{2220 output_str = output_str+"\n";2221 }2222 }2223 }2224 }2225 append_str = append_str+output_str;2226 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2227 return append_str;2228 }2229 else if (term(nl[0]["name"],"else")){2230 var append_str = "}\n";2231 append_str = appendSpacesAhead(append_str,BEAUTIFUL_SPACES-4);2232 append_str = append_str+appendSpacesAhead("else{\n",BEAUTIFUL_SPACES);2233 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2234 var i = 1;2235 var length_of_nl = len(nl);2236 var output_str = "";2237 for (i = 1 ; i<length_of_nl ; i = i+1){2238 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2239 if (len(temp_str)!==0){2240 output_str = output_str+temp_str;2241 if (output_str[len(output_str)-1]!=="\n"){2242 if (output_str[len(output_str)-1]!==";"){2243 output_str = output_str+";\n";2244 }2245 else{2246 output_str = output_str+"\n";2247 }2248 }2249 }2250 }2251 append_str = append_str+output_str;2252 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2253 return append_str;2254 }2255 else if (term(nl[0]["name"],"while")){2256 var append_str = "while (";2257 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2258 var judge_str = Code_Generation_2_Javascript(sl,nl[1]);2259 append_str = append_str+judge_str;2260 append_str = append_str+"){\n";2261 var i = 2;2262 var length_of_nl = len(nl);2263 var output_str = "";2264 for ( ; i<length_of_nl-1 ; i = i+1){2265 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2266 if (len(temp_str)!==0){2267 output_str = output_str+temp_str;2268 if (output_str[len(output_str)-1]!=="\n"){2269 if (output_str[len(output_str)-1]!==";"){2270 output_str = output_str+";\n";2271 }2272 else{2273 output_str = output_str+"\n";2274 }2275 }2276 }2277 }2278 append_str = append_str+output_str;2279 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2280 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2281 return append_str;2282 }2283 else if (term(nl[0]["name"],"for")){2284 var append_str = "for (";2285 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2286 var nl_index = 1;2287 if (term(nl[1]["name"],"assignment")){2288 append_str = append_str+Code_Generation_2_Javascript(sl,nl[1]["node_list"][0]);2289 append_str = append_str+" ; ";2290 nl_index = 2;2291 }2292 else{2293 append_str = append_str+" ; ";2294 nl_index = 1;2295 }2296 var judge_str = Code_Generation_2_Javascript(sl,nl[nl_index]);2297 append_str = append_str+judge_str;2298 append_str = append_str+" ; ";2299 nl_index = nl_index+1;2300 if (term(nl[nl_index]["name"],"assignment")){2301 append_str = append_str+Code_Generation_2_Javascript(sl,nl[nl_index]["node_list"][0]);2302 nl_index = nl_index+1;2303 }2304 append_str = append_str+"){\n";2305 var output_str = "";2306 var i = nl_index;2307 var length_of_nl = len(nl);2308 for ( ; i<length_of_nl-1 ; i = i+1){2309 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2310 if (len(temp_str)!==0){2311 output_str = output_str+temp_str;2312 if (output_str[len(output_str)-1]!=="\n"){2313 if (output_str[len(output_str)-1]!==";"){2314 output_str = output_str+";\n";2315 }2316 else{2317 output_str = output_str+"\n";2318 }2319 }2320 }2321 }2322 append_str = append_str+output_str;2323 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2324 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2325 return append_str;2326 }2327 else if (term(nl[0]["name"],"foreach")){2328 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2329 var append_str = "for(";2330 var foreach_index = nl[1]["name"];2331 append_str = append_str+foreach_index;2332 append_str = append_str+" in ";2333 var has_v = true;2334 if (term(nl[2]["name"],"")){2335 has_v = false;2336 }2337 var foreach_in_value = Code_Generation_2_Javascript(sl,nl[3]["node_list"][0]);2338 foreach_in_value = "WALLEY.stringToObject("+foreach_in_value+")";2339 append_str = append_str+foreach_in_value;2340 append_str = append_str+"){\n";2341 append_str = append_str+appendSpacesAhead("if(("+foreach_in_value+").hasOwnProperty("+foreach_index+")){\n",BEAUTIFUL_SPACES);2342 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2343 if (has_v===true){2344 var value_var_name = nl[2]["name"];2345 append_str = append_str+appendSpacesAhead(value_var_name,BEAUTIFUL_SPACES)+"=";2346 var in_value = "("+foreach_in_value+")";2347 var in_value_and_key = in_value+"["+foreach_index+"]";2348 append_str = append_str+in_value_and_key;2349 append_str = append_str+";\n";2350 }2351 var i = 4;2352 var length_of_nl = len(nl);2353 var output_str = "";2354 for ( ; i<length_of_nl-1 ; i = i+1){2355 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2356 if (len(temp_str)!==0){2357 output_str = output_str+temp_str;2358 if (output_str[len(output_str)-1]!=="\n"){2359 if (output_str[len(output_str)-1]!==";"){2360 output_str = output_str+";\n";2361 }2362 else{2363 output_str = output_str+"\n";2364 }2365 }2366 }2367 }2368 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2369 append_str = append_str+output_str;2370 append_str = append_str+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2371 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2372 append_str = append_str+appendSpacesAhead("};\n",BEAUTIFUL_SPACES);2373 return append_str;2374 }2375 else if (nl[0]["name"]==="import"){2376 var import_file = nl[1]["name"];2377 import_file = import_file.slice(1,import_file["length"]-1);2378 var fs = require("fs");2379 var content_in_import_file = fs.readFileSync(import_file,"utf8");2380 var output_str = exports.Code_Generation(content_in_import_file);2381 if (exports["INCOMPLETE_STATEMENT"]===true){2382 console.log("Error.. statements in file %s is incomplete\n",import_file);2383 process.exit(0);2384 }2385 return output_str;2386 }2387 else{2388 var append_str = "";2389 var i = 0;2390 var length_of_nl = len(nl);2391 var output_str = "";2392 for ( ; i<length_of_nl ; i = i+1){2393 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2394 if (len(temp_str)!==0){2395 output_str = output_str+temp_str;2396 if (output_str[len(output_str)-1]!=="\n"){2397 if (output_str[len(output_str)-1]!==";"){2398 output_str = output_str+";\n";2399 }2400 else{2401 output_str = output_str+"\n";2402 }2403 }2404 }2405 }2406 append_str = append_str+output_str;2407 return append_str;2408 }2409 return "";2410 }2411 else if (term(tree["name"],"relation")){2412 var judge_tree = tree["node_list"][0];2413 var left_tree = judge_tree["node_list"][0];2414 var right_tree = judge_tree["node_list"][1];2415 var left_str = Code_Generation_2_Javascript(sl,left_tree);2416 var right_str = Code_Generation_2_Javascript(sl,right_tree);2417 var append_str = left_str;2418 var relationship = null;2419 if (term(judge_tree["name"],"and")){2420 relationship = " && ";2421 }2422 else{2423 relationship = " || ";2424 }2425 append_str = append_str+relationship;2426 append_str = append_str+right_str;2427 append_str = "("+append_str+")";2428 return append_str;2429 }2430 else if (term(tree["name"],"simple_relation")){2431 var judge_tree = tree["node_list"][0];2432 var left_tree = judge_tree["node_list"][0];2433 var right_tree = judge_tree["node_list"][1];2434 var left_str = Code_Generation_2_Javascript(sl,left_tree);2435 var right_str = Code_Generation_2_Javascript(sl,right_tree);2436 var append_str = left_str;2437 var judge_sign = judge_tree["name"];2438 if (term(judge_sign,"==")){2439 judge_sign = "===";2440 }2441 else if (term(judge_sign,"!=")){2442 judge_sign = "!==";2443 }2444 append_str = append_str+judge_sign;2445 append_str = append_str+right_str;2446 return append_str;2447 }2448 else if (term(tree["name"],"self_operator_stm")){2449 var var_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2450 return var_name+tree["node_list"][1]["name"];2451 }2452 else if (term(tree["name"],"self_assignment_stm")){2453 var var_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2454 var append_string = var_name;2455 append_string = append_string+tree["node_list"][1]["name"];2456 var var_value = Code_Generation_2_Javascript(sl,tree["node_list"][2]);2457 append_string = append_string+var_value;2458 return append_string;2459 }2460 else if (term(tree["name"],"=")){2461 var is_local = false;2462 var append_string = "";2463 var nl = tree["node_list"];2464 var var_name_tree = nl[0];2465 if (term(var_name_tree["name"],"local")){2466 is_local = true;2467 var_name_tree = nl[1];2468 }2469 var var_value_tree = null;2470 if (is_local===true){2471 var_value_tree = nl[2];2472 }2473 else{2474 var_value_tree = nl[1];2475 }2476 var var_name = Code_Generation_2_Javascript(sl,var_name_tree);2477 append_string = var_name;2478 if (is_local===true){2479 append_string = "var "+append_string;2480 }2481 append_string = append_string+" = ";2482 var var_value = Code_Generation_2_Javascript(sl,var_value_tree);2483 append_string = append_string+var_value;2484 return append_string;2485 }2486 else if (term(tree["name"],"func_value")){2487 var append_string = "function(";2488 var param_str = Code_Generation_2_Javascript(sl,tree["node_list"][1]);2489 append_string = append_string+param_str;2490 append_string = append_string+"){\n";2491 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES+4;2492 var nl = tree["node_list"];2493 var i = 2;2494 var output_str = "";2495 var length_of_nl = len(nl);2496 for ( ; i<length_of_nl-1 ; i = i+1){2497 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2498 if (len(temp_str)!==0){2499 output_str = output_str+temp_str;2500 if (output_str[len(output_str)-1]!=="\n"){2501 if (output_str[len(output_str)-1]!==";"){2502 output_str = output_str+";\n";2503 }2504 else{2505 output_str = output_str+"\n";2506 }2507 }2508 }2509 }2510 append_string = append_string+output_str;2511 BEAUTIFUL_SPACES = BEAUTIFUL_SPACES-4;2512 append_string = append_string+appendSpacesAhead("}\n",BEAUTIFUL_SPACES);2513 return append_string;2514 }2515 else if (term(tree["token_class"],"table")){2516 var append_str = "{";2517 var nl = tree["node_list"];2518 var i = 0;2519 var length_of_nl = len(nl);2520 for (i = 0 ; i<length_of_nl ; i = i+1){2521 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2522 append_str = append_str+temp_str;2523 if (i+1!==length_of_nl){2524 append_str = append_str+",";2525 }2526 }2527 append_str = append_str+"}";2528 return append_str;2529 }2530 else if (term(tree["name"],"table_expr")){2531 var key_tree = tree["node_list"][0];2532 var value_tree = tree["node_list"][1];2533 var left = Code_Generation_2_Javascript(sl,key_tree["node_list"][0]);2534 var left_is_string = isString(left);2535 if ((left_is_string===false && isdigit(left)===false)){2536 console.log("Error.. invalid key %s\n",left);2537 process.exit(0);2538 }2539 if (left_is_string===true){2540 left = left.slice(1,left["length"]-1);2541 }2542 var right = Code_Generation_2_Javascript(sl,value_tree);2543 return left+":"+right;2544 }2545 else if (term(tree["name"],"table_value")){2546 var nl = tree["node_list"];2547 var var_name = Code_Generation_2_Javascript(sl,nl[0]);2548 var var_name_is_table = false;2549 if (nl[0]["token_class"]==="table"){2550 var_name_is_table = true;2551 }2552 var append_str = var_name;2553 js_isTableValue = true;2554 var i = 1;2555 var length_of_nl = len(nl);2556 for ( ; i<length_of_nl ; i = i+1){2557 var key_tree = nl[i];2558 var key_str = Code_Generation_2_Javascript(sl,key_tree);2559 if ((var_name_is_table===true && key_str.indexOf(".slice(")===0)){2560 append_str = "WALLEY.slice("+append_str+","+key_str.slice(7,key_str["length"]-1)+")";2561 continue;2562 }2563 append_str = append_str+key_str;2564 }2565 js_isTableValue = false;2566 return append_str;2567 }2568 else if (term(tree["name"],"key")){2569 if (term(tree["node_list"][0]["name"],"slice")){2570 var append_str = ".slice(";2571 var nl = tree["node_list"][0]["node_list"];2572 var left = nl[0];2573 var right = nl[1];2574 var left_str = Code_Generation_2_Javascript(sl,left);2575 append_str = append_str+left_str;2576 js_isTableValue = false;2577 if (term(right["name"],"its_length")){2578 console.log("");2579 }2580 else{2581 append_str = append_str+",";2582 var right_str = Code_Generation_2_Javascript(sl,right);2583 append_str = append_str+right_str;2584 }2585 append_str = append_str+")";2586 js_isTableValue = true;2587 return append_str;2588 }2589 else{2590 var key_tree = tree["node_list"][0];2591 js_isTableValue = false;2592 var append_str = "["+Code_Generation_2_Javascript(sl,key_tree)+"]";2593 js_isTableValue = true;2594 return append_str;2595 }2596 }2597 else if (term(tree["name"],"func")){2598 var used_to_be_js_isTableValue = false;2599 var append_str = "";2600 if (js_isTableValue===false){2601 var func_name_string = Code_Generation_2_Javascript(sl,tree["node_list"][0]["node_list"][0]);2602 var func_name = func_name_string.slice(1,len(func_name_string)-1);2603 append_str = func_name;2604 }2605 else{2606 var func_name = Code_Generation_2_Javascript(sl,tree["node_list"][0]["node_list"][0]);2607 if (isString(func_name)===true){2608 append_str = "."+func_name.slice(1,func_name["length"]-1);2609 }2610 else{2611 append_str = "["+func_name+"]";2612 }2613 used_to_be_js_isTableValue = true;2614 js_isTableValue = false;2615 }2616 append_str = append_str+"(";2617 var params_tree = tree["node_list"][1];2618 var params_nl = params_tree["node_list"];2619 var i = 0;2620 var length_of_params_nl = len(params_nl);2621 for (i = 0 ; i<length_of_params_nl ; i = i+1){2622 append_str = append_str+Code_Generation_2_Javascript(sl,params_nl[i]);2623 if (i+1!==length_of_params_nl){2624 append_str = append_str+",";2625 }2626 }2627 append_str = append_str+")";2628 if (used_to_be_js_isTableValue===true){2629 js_isTableValue = true;2630 }2631 return append_str;2632 }2633 else if ((term(tree["name"],"and") || term(tree["name"],"or"))){2634 var left_str = Code_Generation_2_Javascript(sl,tree["node_list"][0]);2635 var right_str = Code_Generation_2_Javascript(sl,tree["node_list"][1]);2636 var judge_sign = "&&";2637 if (term(tree["name"],"or")){2638 judge_sign = "||";2639 }2640 return left_str+judge_sign+right_str;2641 }2642 else if (term(tree["name"],"params")){2643 var append_string = "";2644 var nl = tree["node_list"];2645 var i = 0;2646 var length_of_nl = len(nl);2647 for ( ; i<length_of_nl ; i = i+1){2648 if (term(nl[i]["name"],"=")){2649 console.log("Does not support = in params now \n");2650 }2651 var need_to_be_appended = Code_Generation_2_Javascript(sl,nl[i]);2652 if (term(need_to_be_appended,"null")){2653 continue;2654 }2655 append_string = append_string+need_to_be_appended;2656 if (i+1!==length_of_nl){2657 append_string = append_string+",";2658 }2659 }2660 return append_string;2661 }2662 else if (term(tree["name"],"end")){2663 return "}\n";2664 }2665 else if (term(tree["token_class"],"num")){2666 return tree["name"];2667 }2668 else if (term(tree["token_class"],"string")){2669 return tree["name"];2670 }2671 else if (term(tree["name"],"value")){2672 var nl = tree["node_list"];2673 return Code_Generation_2_Javascript(sl,nl[0]);2674 }2675 else if (ism_operator(tree["name"])){2676 var nl = tree["node_list"];2677 var left = nl[0];2678 var right = nl[1];2679 var left_str = Code_Generation_2_Javascript(sl,left);2680 var right_str = Code_Generation_2_Javascript(sl,right);2681 if (((isdigit(left_str) || isString(left_str)) && (isdigit(right_str) || isString(right_str)))){2682 var value = Walley_Calculation(left_str,right_str,tree["name"]);2683 return value;2684 }2685 var left_need_bracket = true;2686 var right_need_bracket = true;2687 if (((term(left["token_class"],"id") || term(left["token_class"],"string")) || term(left["token_class"],"num"))){2688 left_need_bracket = false;2689 }2690 if (((term(right["token_class"],"id") || term(right["token_class"],"string")) || term(right["token_class"],"num"))){2691 right_need_bracket = false;2692 }2693 var need_bracket = false;2694 if ((((term(tree["name"],"*") || term(tree["name"],"//")) || term(tree["name"],"^")) || term(tree["name"],"%"))){2695 need_bracket = true;2696 }2697 if (need_bracket){2698 if (left_need_bracket){2699 left_str = "("+left_str+")";2700 }2701 if (right_need_bracket){2702 right_str = "("+right_str+")";2703 }2704 if (term(tree["name"],"^")){2705 var append_str = "Math.pow("+left_str+","+right_str+")";2706 return append_str;2707 }2708 else{2709 var append_str = left_str+tree["name"]+right_str;2710 return append_str;2711 }2712 }2713 else{2714 if (term(tree["name"],"^")){2715 return "Math.pow("+left_str+","+right_str+")";2716 }2717 else{2718 var append_str = left_str;2719 append_str = append_str+tree["name"];2720 append_str = append_str+right_str;2721 return append_str;2722 }2723 }2724 }2725 else if (term(tree["name"],"expr")){2726 return Code_Generation_2_Javascript(sl,tree["node_list"][0]);2727 }2728 else if (term(tree["name"],"return")){2729 var append_str = "return ";2730 var nl = tree["node_list"];2731 append_str = append_str+Code_Generation_2_Javascript(sl,nl[0]);2732 append_str = append_str+";\n";2733 return append_str;2734 }2735 else if (tree["name"]==="new_value"){2736 js_isTableValue = true;2737 var append_str = "new ";2738 var nl = tree["node_list"];2739 for (i = 0 ; i<len(nl) ; i = i+1){2740 var temp_str = Code_Generation_2_Javascript(sl,nl[i]);2741 if (i===0){2742 temp_str = temp_str.slice(1,temp_str["length"]);2743 }2744 append_str+=temp_str;2745 }2746 js_isTableValue = false;2747 return append_str;2748 }2749 else{2750 console.log("Code Generation Error..\n");2751 process.exit(0);2752 }2753}2754exports["Code_Generation"] = function(input_str){2755 INCOMPLETE_STATEMENT = false;2756 var tl = Walley_Lexical_Analyzie(input_str);2757 var tree = parser(tl);2758 var sl = {};2759 var output = Code_Generation_2_Javascript(sl,tree);2760 if (output!==""){2761 sl.append(output);2762 }2763 var output_str = "";2764 var length = len(sl);2765 for (i = 0 ; i<length ; i = i+1){2766 output_str = output_str+sl[i];2767 }2768 exports["INCOMPLETE_STATEMENT"] = INCOMPLETE_STATEMENT;2769 return output_str;...

Full Screen

Full Screen

web.js

Source:web.js Github

copy

Full Screen

1'use strict';2/**3 * Module dependencies.4 */5var emailUtils = require('../email-utils');6var mongoose = require('mongoose');7var crypto = require('crypto');8var moment = require('moment');9var thunk = require('thunkify');10var bitcoinAddress = require('bitcoin-address');11var Token = mongoose.model('Token');12var Connection = mongoose.model('Connection');13exports.index = function *(next) {14 yield this.render('index', {});15}16exports.rebindEmail = function *(next) {17}18exports.bindEmail = function *(next) {19 var token_string = this.params.token_string;20 var query = Token.where({ token_string: token_string });21 var token = yield query.findOne().exec();22 var now = moment();23 if (token) {24 if (moment(token.expiration_date).diff(now) <= 0) {25 // token expirated26 yield this.render('notice', { notice: 'Token expirated.' });27 } else {28 // token works29 yield this.render('bind', { email: token.email });30 }31 } else {32 // token is regenerated or token is not avaiable33 yield this.render('notice', { notice: 'Make sure you open the link from the latest email.' });34 }35}36exports.bindBitcoinAddress = function *(next) {37 var bitcoin_address = this.request.body.bitcoin_address;38 var token_string = this.request.body.token_string;39 if (bitcoinAddress.validate(bitcoin_address) && token_string) {40 var query = Connection.where({ bitcoin_address: bitcoin_address });41 var connection = yield query.findOne().exec();42 if (connection) {43 yield this.render('notice', { 'notice': 'The Bitcoin address has binded to another email. You can not bind it to more than one email, unless you unbind it first.' });44 } else {45 var token_string = this.request.body.token_string;46 var query = Token.where({ token_string: token_string });47 var token = yield query.findOne().exec();48 if (token) {49 var email = token.email.trim().toLowerCase();50 var email_hash = crypto.createHash('md5').update(email).digest('hex');51 var connection = new Connection({ email: email, email_hash: email_hash, bitcoin_address: bitcoin_address });52 connection.save = thunk(connection.save);53 connection = yield connection.save();54 connection = connection[0];55 yield this.render('notice', { 'notice': 'Binded successfully.' });56 var html_body = yield this.render('email-templates/bind-success-premailer', {57 writeResp: false,58 bitcoin_address: bitcoin_address,59 token_string: token.token_string60 });61 emailUtils.sendEmail(token.email, 'Binded successfully', html_body);62 } else {63 yield this.render('notice', { 'notice': 'Make sure you open the url from email directly.' });64 }65 }66 } else {67 yield this.render('notice', { 'notice': 'The Bitcoin address is invalide.' });68 }69}70exports.unbindEmail = function *(next) {71}72exports.sendEmailIfNeeded = function *(next) {73 var body = this.request.body;74 try {75 var email = body['email'];76 }77 catch (err) {78 if (this.response.status == 404) {79 this.throw(400, 'Missing email field.');80 } else {81 this.throw(err);82 }83 return;84 }85 if (this.checkBody('email').isEmail("Bad email."));86 if (this.errors) {87 this.throw(422, 'Validation Failed');88 return;89 } else {90 var email = this.request.body.email;91 email = email.trim().toLowerCase();92 // check if the email has been request before.93 var query = Token.where({ email: email });94 var token = yield query.findOne().exec();95 var now = moment();96 if (!token) {97 // fresh incoming email98 var hash = crypto.createHash('md5').update(email + new Date().toString()).digest('hex');99 var newToken = new Token({ email: email, token_string: hash, expiration_date: now.add(1, 'day').toDate()});100 newToken.save = thunk(newToken.save);101 newToken = yield newToken.save();102 token = newToken[0];103 } else if (moment(token.expiration_date).diff(now) <= 0) {104 // token expirated105 var hash = crypto.createHash('md5').update(email + new Date().toString()).digest('hex');106 token.token_string = hash;107 token.expiration_date = now.add(1, 'day').toDate();108 token.save = thunk(token.save);109 token = yield token.save();110 token = token[0];111 } else {112 // email has been requested before113 }114 // check if the email has binded to a bitcoin address.115 var query = Connection.where({ email: email });116 var connection = yield query.findOne().exec();117 // send email118 if (connection) {119 // binded120 var html_body = yield this.render('email-templates/binded-premailer', {121 writeResp: false,122 bitcoin_address: connection.bitcoin_address,123 token_string: token.token_string124 });125 emailUtils.sendEmail(email, 'Request for your action', html_body);126 } else {127 var html_body = yield this.render('email-templates/bind-premailer', {128 writeResp: false,129 token_string: token.token_string130 });131 emailUtils.sendEmail(email, 'Bind to your bitcoin address', html_body);132 }133 }134 this.status = 200;135 this.body = { 'statusCode': 200 };136}137exports.notice = function *(next) {138 yield this.render('notice', { 'notice': this.params.notice_message });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TOKEN_STRING } from 'ng-mocks';2import { TOKEN_STRING } from 'ng-mocks';3import { TOKEN_STRING } from 'ng-mocks';4import { TOKEN_STRING } from 'ng-mocks';5import { TOKEN_STRING } from 'ng-mocks';6import { TOKEN_STRING } from 'ng-mocks';7import { TOKEN_STRING } from 'ng-mocks';8import { TOKEN_STRING } from 'ng-mocks';9import { TOKEN_STRING } from 'ng-mocks';10import { TOKEN_STRING } from 'ng-mocks';11import { TOKEN_STRING } from 'ng-mocks';12import { TOKEN_STRING } from 'ng-mocks';13import { TOKEN_STRING } from 'ng-mocks';14import { TOKEN_STRING } from 'ng-mocks';15import { TOKEN_STRING } from 'ng-mocks';16import { TOKEN_STRING } from 'ng-mocks';17import { TOKEN_STRING } from 'ng-mocks';18import { TOKEN_STRING } from 'ng-mocks';19import { TOKEN_STRING } from 'ng-mocks';20import { TOKEN_STRING } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TestBed } from '@angular/core/testing';2import { Component } from '@angular/core';3import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';4@Component({5})6class TestComponent {}7describe('TestComponent', () => {8 beforeEach(() => MockBuilder(TestComponent));9 it('should render', () => {10 const fixture = MockRender(TestComponent);11 expect(ngMocks.formatText(fixture)).toEqual('test template');12 });13});14import { TestBed } from '@angular/core/testing';15import { Component } from '@angular/core';16import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';17@Component({18})19class TestComponent {}20describe('TestComponent', () => {21 beforeEach(() => MockBuilder(TestComponent));22 it('should render', () => {23 const fixture = MockRender(TestComponent);24 expect(ngMocks.formatText(fixture)).toEqual('test template');25 });26});27import { TestBed } from '@angular/core/testing';28import { Component } from '@angular/core';29import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';30@Component({31})32class TestComponent {}33describe('TestComponent', () => {34 beforeEach(() => MockBuilder(TestComponent));35 it('should render', () => {36 const fixture = MockRender(TestComponent);37 expect(ngMocks.formatText(fixture)).toEqual('test template');38 });39});40import { TestBed } from '@angular/core/testing';41import { Component } from '@angular/core';42import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';43@Component({44})45class TestComponent {}46describe('TestComponent', () => {47 beforeEach(()

Full Screen

Using AI Code Generation

copy

Full Screen

1var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;2var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;3var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;4var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;5var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;6var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;7var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;8var TOKEN_STRING = require('ng-mocks').TOKEN_STRING;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Component } from '@angular/core';2import { TestBed } from '@angular/core/testing';3import { ngMocks } from 'ng-mocks';4@Component({5})6class AppComponent {}7describe('AppComponent', () => {8 beforeEach(() => {9 TestBed.configureTestingModule({10 });11 });12 it('should create the app', () => {13 const fixture = TestBed.createComponent(AppComponent);14 const app = fixture.componentInstance;15 expect(app).toBeTruthy();16 });17 it('should render title', () => {18 const fixture = TestBed.createComponent(AppComponent);19 fixture.detectChanges();20 const compiled = fixture.nativeElement;21 expect(compiled.querySelector('#test').textContent).toContain('Test');22 });23});24import { Component } from '@angular/core';25import { TestBed } from '@angular/core/testing';26import { ngMocks } from 'ng-mocks';27@Component({28})29class AppComponent {}30describe('AppComponent', () => {31 beforeEach(() => {32 TestBed.configureTestingModule({33 });34 });35 it('should create the app', () => {36 const fixture = TestBed.createComponent(AppComponent);37 const app = fixture.componentInstance;38 expect(app).toBeTruthy();39 });40 it('should render title', () => {41 const fixture = TestBed.createComponent(AppComponent);42 fixture.detectChanges();43 const compiled = fixture.nativeElement;44 expect(compiled.querySelector('#test').textContent).toContain('Test');45 });46});47import { Component } from '@angular/core';48import { TestBed } from '@angular/core/testing';

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful