Best Python code snippet using slash
Codegen.py
Source:Codegen.py
...106 if token[i] not in wordarray and token[i].isalpha():107 next()108 funcparm = []109 if token[i-1] == "main":110 print (str(q).ljust(4) + "\tfunc \t\t" + token[i-1] + "\t\tvoid\t\t0")111 q += 1112 currfunc = token[i-1]113114 else:115 if token[i-2] == "void":116 if token[i+1] == "void":117 print (str(q).ljust(4) + "\tfunc \t\t" + token[i-1].ljust(4) + "\t\tvoid\t\t0")118 q += 1119 currfunc = token[i-1]120 else:121 f = i + 1122 paramcount = 0123 qch = q + 1124 while token[f] != ")":125 if token[f] == "int":126 paramcount += 1127 funcparm.append(str(qch).ljust(4) + "\tparam\t\t4 \t\t\t\t\t" + token[f+1])128 qch += 1129 f += 2130 if token[f] == ",":131 f += 1132 print (str(q).ljust(4) + "\tfunc \t\t" + token[i-1].ljust(4) + "\t\t" + token[i-2].ljust(4) + "\t\t" + str(paramcount))133 q = qch134 for v in funcparm:135 print (v)136 currfunc = token[i-1]137138 else:139 if token[i+1] == "void":140 print (str(q).ljust(4) + "\tfunc \t\t" + token[i-1].ljust(4) + "\t\t" + token[i-2].ljust(4) + "\t\t0")141 q += 1142 currfunc = token[i-1]143 else:144 f = i + 1145 paramcount = 0146 qch = q + 1147 while token[f] != ")":148 if token[f] == "int":149 paramcount += 1150 funcparm.append(str(qch).ljust(4) + "\tparam\t\t4 \t\t\t\t\t" + token[f+1])151 qch += 1152 f += 2153 if token[f] == ",":154 f += 1155 print (str(q).ljust(4) + "\tfunc \t\t" + token[i-1].ljust(4) + "\t\t" + token[i-2].ljust(4) + "\t\t" + str(paramcount))156 q = qch157 for v in funcparm:158 print (v)159 currfunc = token[i-1]160161 if token[i] == ";":162 next()163 elif token[i] == "[":164 next()165 if token[i].isnumeric():166 next()167 if token[i] == "]":168 next()169 eat(";")170 else:171 reject()172 else:173 reject()174 elif token[i] == "(":175 next()176 params()177 if token[i] == ")":178 next()179 compoundstmt()180 else:181 reject()182 else:183 reject()184 else:185 reject()186187188def var_declaration():189 global q190 type_specifier()191 if token[i] not in wordarray and token[i].isalpha:192 next()193 if token[i] != "[":194 if inwlistq == 1:195 whilelistq.append(str(q).ljust(4) + "\talloc\t\t4 \t\t \t\t" + token[i-1])196 q += 1197 elif iniflist == 1:198 iflist.append(str(q).ljust(4) + "\talloc\t\t4 \t\t \t\t" + token[i-1])199 q += 1200 else:201 print (str(q).ljust(4) + "\talloc\t\t4 \t\t \t\t" + token[i-1])202 q += 1203204 else:205 reject()206 if token[i] == ";":207 next()208 elif token[i] == "[":209 next()210211 alloc = int(token[i]) * int(4)212213 if inwlistq == 1:214 whilelistq.append(str(q).ljust(4) + "\talloc\t\t" + str(alloc).ljust(4) + "\t\t \t\t" + token[i-2])215 q += 1216 elif iniflist == 1:217 iflist.append(str(q).ljust(4) + "\talloc\t\t" + str(alloc).ljust(4) + "\t\t \t\t" + token[i-2])218 q += 1219 else:220 print (str(q).ljust(4) + "\talloc\t\t" + str(alloc).ljust(4) + "\t\t \t\t" + token[i-2])221 q += 1222223 if token[i].isnumeric():224 next()225 if token[i] == "]":226 next()227 eat(";")228 else:229 reject()230 else:231 reject()232 else:233 reject()234235236def type_specifier():237 if token[i] == "int" or token[i] == "void":238 next()239 else:240 return241242def params():243 if token[i] == "int" or token[i] == "void":244 paramslist()245 else:246 reject()247248249def paramslist():250 param()251 paramslistprime()252253254def paramslistprime():255 if token[i] == ",":256 next()257 param()258 paramslistprime()259 elif token[i] == ")":260 return261 else:262 return263264265def param():266 type_specifier()267 if token[i] not in wordarray and token[i].isalpha():268 next()269 if token[i] == "[":270 next()271 eat("]")272 else:273 if token[i-1] == "void":274 return275 else:276 reject()277278279def compoundstmt():280 global currfunc, q, incurrfun281 if token[i] == "{":282 next()283 incurrfun += 1284285 if incurrfun > 1:286 if inwlistq == 1:287 whilelistq.append(str(q).ljust(4) + "\tblock\t\t \t\t ")288 q += 1289 elif iniflist == 1:290 iflist.append(str(q).ljust(4) + "\tblock\t\t \t\t ")291 q += 1292 else:293 print (str(q).ljust(4) + "\tblock\t\t \t\t ")294 q += 1295296 else:297 return298299 local_declaration()300 statementlist()301302 if token[i] == "}":303 next()304305 incurrfun -= 1306 if incurrfun > 0:307 if inwlistq == 1:308 whilelistq.append(str(q).ljust(4) + "\tend \t\tblock\t\t")309 q += 1310 elif iniflist == 1:311 iflist.append(str(q).ljust(4) + "\tend \t\tblock\t\t")312 q += 1313 else:314 print (str(q).ljust(4) + "\tend \t\tblock\t\t")315 q += 1316317 if incurrfun == 0:318 print (str(q).ljust(4) + "\tend \t\tfunc\t\t" + currfunc)319 q += 1320321 else:322 reject()323324325def local_declaration():326 ldprime()327328329def ldprime():330 if token[i] == "int" or token[i] == "void":331 var_declaration()332 ldprime()333 else:334 return335336337def statementlist():338 slprime()339340341def slprime():342 if token[i] not in wordarray and token[i].isalpha():343 statement()344 slprime()345 elif token[i].isnumeric():346 statement()347 slprime()348 elif token[i] == "(" or token[i] == ";" or token[i] == "{" or token[i] == "if" or token[i] == "while" or token[i] == "return":349 statement()350 slprime()351 elif token[i] == "}":352 return353 else:354 return355356357def statement():358 if token[i] not in wordarray and token[i].isalpha():359 expstmt()360 elif token[i].isnumeric():361 expstmt()362 elif token[i] == "(" or token[i] == ";":363 expstmt()364 elif token[i] == "{":365 compoundstmt()366 elif token[i] == "if":367 selectionstmt()368 elif token[i] == "while":369 itstmt()370 elif token[i] == "return":371 retstmt()372 else:373 reject()374375376def expstmt():377 if token[i] not in wordarray and token[i].isalpha():378 exp()379 eat(";")380 elif token[i].isnumeric:381 exp()382 eat(";")383 elif token[i] == "(":384 exp()385 eat(";")386 elif token[i] == ";":387 next()388 else:389 reject()390391392def selectionstmt():393 global ifbr, q, t, iniflist394 if token[i] == "if":395 next()396 else:397 return398399 if token[i] == "(":400 next()401 f = i402 iffront = ""403 bch = 0404 while token[f] != "<" and token[f] != "<=" and token[f] != ">" and token[f] != ">=" and token[f] != "==" and token[f] != "!=":405 if token[f] == "[" or bch == 1:406 iffront = iffront + token[f]407 bch = 1408 if token[f] == "]":409 bch = 0410 else:411 iffront = iffront + " " + token[f]412 f += 1413414415 comparison = token[f]416 iffront = infixToPostfix(iffront)417 lastif = postfixEval(iffront)418419 f += 1420 bch = 0421 ifback = ""422 while token[f] != ")":423 if token[f] == "[" or bch == 1:424 ifback = ifback + token[f]425 bch = 1426 if token[f] == "]":427 bch = 0428 else:429 ifback = ifback + " " + token[f]430 f += 1431432 ifback = infixToPostfix(ifback)433 lastif1 = postfixEval(ifback)434435 print (str(q).ljust(4) + "\tcomp \t\t" + lastif.ljust(4) + "\t\t" + lastif1.ljust(4) + "\t\tt" + str(t))436 q += 1437 temp = "t" + str(t)438 t += 1439440 if comparison == ">":441 print (str(q).ljust(4) + "\tBRLEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))442 q += 1443 elif comparison == ">=":444 print (str(q).ljust(4) + "\tBGET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))445 q += 1446 elif comparison == "<":447 print (str(q).ljust(4) + "\tBLT \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))448 q += 1449 elif comparison == "<=":450 print (str(q).ljust(4) + "\tBLET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))451 q += 1452 elif comparison == "==":453 print (str(q).ljust(4) + "\tBEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))454 q += 1455 else: # comparison == "!="456 print (str(q).ljust(4) + "\tBNEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))457 q += 1458459 iflist.append(str(q).ljust(4) + "\tBR \t\t\t\t\t\t\t\t")460 q += 1461462463 else:464 reject()465466 exp()467468 eat(")")469470 iniflist = 1471472 statement()473474 if token[i] == "else":475 iflist[ifnum] = iflist[ifnum] + str(q+1)476 else:477 iflist[ifnum] = iflist[ifnum] + str(q)478479 for v in iflist:480 print (v)481 iniflist = 0482483 if token[i] == "else":484 next()485486 iflist.append(str(q).ljust(4) + "\tBR \t\t\t\t\t\t\t\t")487 elsech = len(iflist)488 q += 1489 iniflist = 1490491 statement()492493 iflist[elsech-1] = iflist[elsech-1] + str(q)494495 for v in range(elsech-1, len(iflist)):496 print (iflist[v])497 iniflist = 0498499 else:500 return501502503def itstmt():504 global lastw, t, q, inwlistq, dubcheck, wlistqnum505 if token[i] == "while":506 next()507 else:508 return509510 if token[i] == "(":511 next()512 whileendbr = q513 f = i514 wlistfront = ""515 bch = 0516 while token[f] != "<" and token[f] != "<=" and token[f] != ">" and token[f] != ">=" and token[f] != "==" and token[f] != "!=":517 if token[f] == "[" or bch == 1:518 wlistfront = wlistfront + token[f]519 bch = 1520 if token[f] == "]":521 bch = 0522 else:523 wlistfront = wlistfront + " " + token[f]524 f += 1525526 comparison = token[f]527 wlistfront = infixToPostfix(wlistfront)528 lastw = postfixEval(wlistfront)529530 f += 1531 bch = 0532 wlistback = ""533 while token[f] != ")":534 if token[f] == "[" or bch == 1:535 wlistback = wlistback + token[f]536 bch = 1537 if token[f] == "]":538 bch = 0539 else:540 wlistback = wlistback + " " + token[f]541 f += 1542543 wlistback = infixToPostfix(wlistback)544 lastw1 = postfixEval(wlistback)545546 if inwlistq == 1:547 whilelistq.append(str(q).ljust(4) + "\tcomp \t\t" + lastw.ljust(4) + "\t\t" + lastw1.ljust(4) + "\t\tt" + str(t))548 else:549 print (str(q).ljust(4) + "\tcomp \t\t" + lastw.ljust(4) + "\t\t" + lastw1.ljust(4) + "\t\tt" + str(t))550 q += 1551 temp = "t" + str(t)552 t += 1553554 if comparison == ">":555 if inwlistq == 1:556 whilelistq.append(str(q).ljust(4) + "\tBRLEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))557 else:558 print (str(q).ljust(4) + "\tBRLEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))559 q += 1560 elif comparison == ">=":561 if inwlistq == 1:562 whilelistq.append(str(q).ljust(4) + "\tBGET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))563 else:564 print (str(q).ljust(4) + "\tBGET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))565 q += 1566 elif comparison == "<":567 if inwlistq == 1:568 whilelistq.append(str(q).ljust(4) + "\tBLT \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))569 else:570 print (str(q).ljust(4) + "\tBLT \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))571 q += 1572 elif comparison == "<=":573 if inwlistq == 1:574 whilelistq.append(str(q).ljust(4) + "\tBLET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))575 else:576 print (str(q).ljust(4) + "\tBLET \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))577 q += 1578 elif comparison == "==":579 if inwlistq == 1:580 whilelistq.append(str(q).ljust(4) + "\tBEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))581 else:582 print (str(q).ljust(4) + "\tBEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))583 q += 1584 else:585 if inwlistq == 1:586 whilelistq.append(str(q).ljust(4) + "\tBNEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))587 else:588 print (str(q).ljust(4) + "\tBNEQ \t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(q + 2))589 q += 1590591 else:592 reject()593594 exp()595 eat(")")596 inwlistq = 1597 dubcheck += 1598 statement()599 dubcheck -= 1600 whilelistq[wlistqnum] = whilelistq[wlistqnum] + str(q + 1) +"h"601 inwlistq = 0602603 if dubcheck == 0:604 for v in whilelistq:605 print (v)606607 if inwlistq == 1:608 whilelistq.append(str(q).ljust(4) + "\tBR \t\t\t\t\t\t\t\t" + str(whileendbr))609 else:610 print (str(q).ljust(4) + "\tBR \t\t\t\t\t\t\t\t" + str(whileendbr))611 q += 1612613614def retstmt():615 global q, t616 if token[i] == "return":617 next()618 else:619 return620621 if token[i] == ";":622 next()623 print (str(q).ljust(4) + "\treturn\t\t \t\t ")624 q += 1625 return626627 elif token[i] not in wordarray and token[i].isalpha():628629 if token[i+1] == "[":630 f = i631 retexp = ""632 while token[f] != ";":633 retexp = retexp + token[f]634 f += 1635636 h1 = retexp.partition('[')637 h2 = retexp.partition('[')[-1].rpartition(']')[0]638 if h2.isdigit() == False:639 print (str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))640 q += 1641 temp = "t" + str(t)642 t += 1643 h2 = temp644 else:645 h2 = int(h2) * 4646 print (str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))647 q += 1648 temp = "t" + str(t)649 t += 1650651 print (str(q).ljust(4) + "\treturn\t\t \t\t \t\t" + temp)652 q += 1653654 else:655 print (str(q).ljust(4) + "\treturn\t\t \t\t \t\t" + token[i])656 q += 1657658 exp()659660 eat(";")661662 elif token[i].isnumeric():663664 print (str(q).ljust(4) + "\treturn\t\t \t\t \t\t" + token[i])665 q += 1666667 exp()668669 eat(";")670 elif token[i] == "(":671672 f = i + 1673 bch = 0674 expret = ""675 while token[f] != ")":676 if token[f] == "[" or bch == 1:677 expret = expret + token[f]678 bch = 1679 if token[f] == "]":680 bch = 0681 else:682 expret = expret + " " + token[f]683 f += 1684685 expret = infixToPostfix(expret)686 lastexpret = postfixEval(expret)687688 print (str(q).ljust(4) + "\treturn\t\t \t\t \t\t" + lastexpret)689 q += 1690691 exp()692693 eat(';')694 else:695 reject()696697698def exp():699 global i, q, t, inexp700 if token[i] not in wordarray and token[i].isalpha():701 next()702703 if token[i] == "[" and inexp == 0:704 f = i - 1705 check = ""706 while token[f] != "=":707 check = check + token[f]708 f += 1709 i = f710 assign = check711712 if inwlistq == 1:713 h1 = assign.partition('[')714 h2 = assign.partition('[')[-1].rpartition(']')[0]715 if h2.isdigit() == False:716 whilelistq.append(str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))717 q += 1718 temp = "t" + str(t)719 t += 1720 h2 = temp721 else:722 h2 = int(h2) * 4723 whilelistq.append(str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))724 q += 1725 temp = "t" + str(t)726 t += 1727 assign = temp728729 elif iniflist == 1:730 h1 = assign.partition('[')731 h2 = assign.partition('[')[-1].rpartition(']')[0]732 if h2.isdigit() == False:733 iflist.append(str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))734 q += 1735 temp = "t" + str(t)736 t += 1737 h2 = temp738 else:739 h2 = int(h2) * 4740 iflist.append(str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))741 q += 1742 temp = "t" + str(t)743 t += 1744 assign = temp745746 else:747 h1 = assign.partition('[')748 h2 = assign.partition('[')[-1].rpartition(']')[0]749 if h2.isdigit() == False:750 print (str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))751 q += 1752 temp = "t" + str(t)753 t += 1754 h2 = temp755 else:756 h2 = int(h2) * 4757 print (str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))758 q += 1759 temp = "t" + str(t)760 t += 1761 assign = temp762763 else:764 assign = token[i-1]765766 if token[i] == "(" and inexp == 0:767 f = i768 exquad = token[i-1]769 while token[f] != ";":770 exquad = exquad + token[f]771 f += 1772773 if inwlistq == 1:774 parmcount = 0775 h1 = exquad.partition('(')[-1].rpartition(')')[0]776 h2 = exquad.partition('(')777 if ',' in h1:778 h1 = h1.split(',')779 for v in h1:780 parmcount += 1781 whilelistq.append(str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)782 q += 1783784 whilelistq.append(str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))785 q += 1786 t += 1787788 elif iniflist == 1:789 parmcount = 0790 h1 = exquad.partition('(')[-1].rpartition(')')[0]791 h2 = exquad.partition('(')792 if ',' in h1:793 h1 = h1.split(',')794 for v in h1:795 parmcount += 1796 iflist.append(str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)797 q += 1798799 iflist.append(str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))800 q += 1801 t += 1802803 else:804 parmcount = 0805 h1 = exquad.partition('(')[-1].rpartition(')')[0]806 h2 = exquad.partition('(')807 if ',' in h1:808 h1 = h1.split(',')809 for v in h1:810 parmcount += 1811 print (str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)812 q += 1813814 print (str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))815 q += 1816 t += 1817818 if token[i] == "=":819 f = i + 1820 exquad = ""821 bch = 0822 pch = 0823 while token[f] != ";":824 if token[f] == "[" or bch == 1:825 exquad = exquad + token[f]826 bch = 1827 if token[f] == "]":828 bch = 0829 elif token[f] == "(" or pch == 1:830 if token[f-1] != "*" and token[f-1] != "/" and token[f-1] != "+" and token[f-1] != "-" and token[f-1] != "=":831 exquad = exquad + token[f]832 pch = 1833 if token[f] == ")":834 pch = 0835 else:836 exquad = exquad + " " + token[f]837 else:838 exquad = exquad + " " + token[f]839 f += 1840 exquad = infixToPostfix(exquad)841 lastexp = postfixEval(exquad)842843 if inwlistq == 1:844 if "(" in lastexp:845 parmcount = 0846 h1 = lastexp.partition('(')[-1].rpartition(')')[0]847 h2 = lastexp.partition('(')848 if ',' in h1:849 h1 = h1.split(',')850 for v in h1:851 parmcount += 1852 whilelistq.append(str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)853 q += 1854855 whilelistq.append(str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))856 q += 1857 temp = "t" + str(t)858 t += 1859 whilelistq.append(str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))860 q += 1861 inexp = 1862863 elif "[" in lastexp:864 h1 = lastexp.partition('[')865 h2 = lastexp.partition('[')[-1].rpartition(']')[0]866 if h2.isdigit() == False:867 whilelistq.append(str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))868 q += 1869 temp = "t" + str(t)870 t += 1871 h2 = temp872 else:873 h2 = int(h2) * 4874 whilelistq.append(str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))875 q += 1876 temp = "t" + str(t)877 t += 1878879 whilelistq.append(str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))880 q += 1881 inexp = 1882883 else:884 whilelistq.append(str(q).ljust(4) + "\tassgn\t\t" + lastexp.ljust(4) + "\t\t\t\t\t" + str(assign))885 q += 1886 inexp = 1887888 elif iniflist == 1:889 if "(" in lastexp:890 parmcount = 0891 h1 = lastexp.partition('(')[-1].rpartition(')')[0]892 h2 = lastexp.partition('(')893 if ',' in h1:894 h1 = h1.split(',')895 for v in h1:896 parmcount += 1897 iflist.append(str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)898 q += 1899900 iflist.append(str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))901 q += 1902 temp = "t" + str(t)903 t += 1904 iflist.append(str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))905 q += 1906 inexp = 1907908 elif "[" in lastexp:909 h1 = lastexp.partition('[')910 h2 = lastexp.partition('[')[-1].rpartition(']')[0]911 if h2.isdigit() == False:912 iflist.append(str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))913 q += 1914 temp = "t" + str(t)915 t += 1916 h2 = temp917 else:918 h2 = int(h2) * 4919 iflist.append(str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))920 q += 1921 temp = "t" + str(t)922 t += 1923924 iflist.append(str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))925 q += 1926 inexp = 1927928 else:929 iflist.append(str(q).ljust(4) + "\tassgn\t\t" + lastexp.ljust(4) + "\t\t\t\t\t" + str(assign))930 q += 1931 inexp =1932933 else:934 if "(" in lastexp:935 parmcount = 0936 h1 = lastexp.partition('(')[-1].rpartition(')')[0]937 h2 = lastexp.partition('(')938 if ',' in h1:939 h1 = h1.split(',')940 for v in h1:941 parmcount += 1942 print (str(q).ljust(4) + "\targ \t\t\t\t\t\t\t\t" + v)943 q += 1944945 print (str(q).ljust(4) + "\tcall \t\t" + h2[0].ljust(4) + "\t\t" + str(parmcount).ljust(4) + "\t\tt" + str(t))946 q += 1947 temp = "t" + str(t)948 t += 1949 print (str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))950 q += 1951 inexp =1952953 elif "[" in lastexp:954 h1 = lastexp.partition('[')955 h2 = lastexp.partition('[')[-1].rpartition(']')[0]956 if h2.isdigit() == False:957 print (str(q).ljust(4) + "\tmult \t\t" + h2.ljust(4) + "\t\t4 \t\tt" + str(t))958 q += 1959 temp = "t" + str(t)960 t += 1961 h2 = temp962 else:963 h2 = int(h2) * 4964 print (str(q).ljust(4) + "\tdisp \t\t" + h1[0].ljust(4) + "\t\t" + str(h2).ljust(4) + "\t\tt" + str(t))965 q += 1966 temp = "t" + str(t)967 t += 1968969 print (str(q).ljust(4) + "\tassgn\t\t" + temp.ljust(4) + "\t\t\t\t\t" + str(assign))970 q += 1971 inexp = 1972973 else:974 print (str(q).ljust(4) + "\tassgn\t\t" + lastexp.ljust(4) + "\t\t\t\t\t" + str(assign))975 q += 1976 inexp = 1977978 ex()979 inexp = 0980981 elif token[i] == "(":982 next()983 exp()984 if token[i] == ")":985 next()986 termprime()987 addexpprime()988 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\989 token[i] == ">=" or token[i] == "==" or token[i] == "!=":990 relop()991 addexp()992 elif token[i] == "+" or token[i] == "-":993 addexpprime()994 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\995 token[i] == ">=" or token[i] == "==" or token[i] == "!=":996 relop()997 addexp()998 elif token[i] == "<=" or token[i] == "<" or token[i] == ">" or\999 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1000 relop()1001 addexp()1002 else:1003 return1004 else:1005 reject()1006 elif token[i].isnumeric():1007 next()1008 termprime()1009 addexpprime()1010 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1011 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1012 relop()1013 addexp()1014 elif token[i] == "+" or token[i] == "-":1015 addexpprime()1016 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1017 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1018 relop()1019 addexp()1020 elif token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1021 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1022 relop()1023 addexp()1024 else:1025 return1026 else:1027 reject()102810291030def ex():1031 if token[i] == "=":1032 next()1033 exp()1034 elif token[i] == "[":1035 next()1036 exp()1037 if token[i-1] == "[":1038 reject()1039 if token[i] == "]":1040 next()1041 if token[i] == "=":1042 next()1043 exp()1044 elif token[i] == "*" or token[i] == "/":1045 termprime()1046 addexpprime()1047 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or token[i] == ">=" or token[i] == "==" or token[i] == "!=":1048 relop()1049 addexp()1050 else:1051 return1052 elif token[i] == "+" or token[i] == "-":1053 addexpprime()1054 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or token[i] == ">=" or token[i] == "==" or token[i] == "!=":1055 relop()1056 addexp()1057 elif token[i] == "<=" or token[i] == "<" or token[i] == ">" or token[i] == ">=" or token[i] == "==" or token[i] == "!=":1058 relop()1059 addexp()1060 else:1061 return1062 else:1063 reject()1064 elif token[i] == "(":1065 next()1066 args()1067 if token[i] == ")":1068 next()1069 if token[i] == "*" or token[i] == "/":1070 termprime()1071 addexpprime()1072 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1073 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1074 relop()1075 addexp()1076 else:1077 return1078 elif token[i] == "+" or token[i] == "-":1079 addexpprime()1080 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1081 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1082 relop()1083 addexp()1084 elif token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1085 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1086 relop()1087 addexp()1088 else:1089 return1090 else:1091 reject()1092 elif token[i] == "*" or token[i] == "/":1093 termprime()1094 addexpprime()1095 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1096 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1097 relop()1098 addexp()1099 else:1100 return1101 elif token[i] == "+" or token[i] == "-":1102 addexpprime()1103 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1104 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1105 relop()1106 addexp()1107 else:1108 return1109 elif token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1110 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1111 relop()1112 addexp()1113 else:1114 return111511161117def var():1118 if token[i] not in wordarray and token[i].isalpha():1119 next()1120 else:1121 return1122 if token[i] == "[":1123 next()1124 exp()1125 eat("]")1126 else:1127 return112811291130def simexp():1131 addexp()1132 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1133 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1134 relop()1135 addexp()1136 else:1137 return113811391140def relop():1141 if token[i] == "<=" or token[i] == "<" or token[i] == ">" or\1142 token[i] == ">=" or token[i] == "==" or token[i] == "!=":1143 next()1144 else:1145 return114611471148def addexp():1149 term()1150 addexpprime()115111521153def addexpprime():1154 if token[i] == "+" or token[i] == "-":1155 addop()1156 term()1157 addexpprime()1158 else:1159 return116011611162def addop():1163 if token[i] == "+" or token[i] == "-":1164 next()1165 else:1166 return116711681169def term():1170 factor()1171 termprime()117211731174def termprime():1175 if token[i] == "*" or token[i] == "/":1176 mulop()1177 factor()1178 termprime()1179 else:1180 return118111821183def mulop():1184 if token[i] == "*" or token[i] == "/":1185 next()1186 else:1187 return118811891190def factor():1191 if token[i] not in wordarray and token[i].isalpha():1192 next()1193 if token[i] == "[":1194 next()1195 exp()1196 if token[i] == "]":1197 next()1198 else:1199 return1200 elif token[i] == "(":1201 next()1202 args()1203 if token[i] == ")":1204 next()1205 else:1206 return1207 else:1208 return1209 elif token[i].isnumeric():1210 next()1211 elif token[i] == "(":1212 next()1213 exp()1214 if token[i] == ")":1215 next()1216 else:1217 return1218 else:1219 reject()122012211222def call():1223 if token[i] not in wordarray and token[i].isalpha():1224 next()1225 if token[i] == "(":1226 next()1227 args()1228 if token[i] == ")":1229 next()1230 else:1231 reject()1232 else:1233 reject()1234 else:1235 return123612371238def args():1239 if token[i] not in wordarray and token[i].isalpha:1240 arglist()1241 elif token[i].isnumeric():1242 arglist()1243 elif token[i] == "(":1244 arglist()1245 elif token[i] == ")":1246 return1247 else:1248 return124912501251def arglist():1252 exp()1253 arglistprime()125412551256def arglistprime():1257 if token[i] == ",":1258 next()1259 exp()1260 arglistprime()1261 elif token[i] == ")":1262 return1263 else:1264 return126512661267def infixToPostfix(infixexpr):1268 prec = {"*":3, "/":3, "+":2, "-":2, "(":1}1269 opStack = Stack()1270 postfixList = []1271 tokenList = infixexpr.split()12721273 for token in tokenList:1274 if token.isalnum() or "[" in token or ("(" in token and ")" in token) or (re.search('[a-z]', token) == True and "(" in token) or token in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" or token in "0123456789" or token in "abcdefghijklmnopqrstuvwxyz":1275 postfixList.append(token)1276 elif token == '(':1277 opStack.push(token)1278 elif token == ')':1279 topToken = opStack.pop()1280 while topToken != '(':1281 postfixList.append(topToken)1282 topToken = opStack.pop()1283 else:1284 while (not opStack.isEmpty()) and \1285 (prec[opStack.peek()] >= prec[token]):1286 postfixList.append(opStack.pop())1287 opStack.push(token)12881289 while not opStack.isEmpty():1290 postfixList.append(opStack.pop())1291 return " ".join(postfixList)12921293def postfixEval(postfixExpr):1294 operandStack = Stack()1295 tokenList = postfixExpr.split()12961297 for token in tokenList:1298 if token.isalnum() or "[" in token or ("(" in token and ")" in token) or (re.search('[a-z]', token) == True and "(" in token) or token.isalpha() or token.isnumeric():1299 operandStack.push(token)1300 else:1301 operand2 = operandStack.pop()1302 operand1 = operandStack.pop()1303 result = math(token,operand1,operand2)1304 operandStack.push(result)1305 return operandStack.pop()1306130713081309def math(op, op1, op2):1310 global q, t1311 if op == "*":1312 if inwlistq == 1:1313 whilelistq.append(str(q).ljust(4) + "\tmult \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1314 elif iniflist == 1:1315 iflist.append(str(q).ljust(4) + "\tmult \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1316 else:1317 print (str(q).ljust(4) + "\tmult \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1318 q += 11319 temp = "t" + str(t)1320 t += 11321 return temp13221323 elif op == "/":1324 if inwlistq == 1:1325 whilelistq.append(str(q).ljust(4) + "\tdiv \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1326 elif iniflist == 1:1327 iflist.append(str(q).ljust(4) + "\tdiv \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1328 else:1329 print (str(q).ljust(4) + "\tdiv \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1330 q += 11331 temp = "t" + str(t)1332 t += 11333 return temp13341335 elif op == "+":1336 if inwlistq == 1:1337 whilelistq.append(str(q).ljust(4) + "\tadd \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1338 elif iniflist == 1:1339 iflist.append(str(q).ljust(4) + "\tadd \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1340 else:1341 print (str(q).ljust(4) + "\tadd \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1342 q += 11343 temp = "t" + str(t)1344 t += 11345 return temp13461347 else: # if op == "-"1348 if inwlistq == 1:1349 whilelistq.append(str(q).ljust(4) + "\tsub \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1350 elif iniflist == 1:1351 iflist.append(str(q).ljust(4) + "\tsub \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1352 else:1353 print (str(q).ljust(4) + "\tsub \t\t" + op1.ljust(4) + "\t\t" + op2.ljust(4) + "\t\tt" + str(t))1354 q += 11355 temp = "t" + str(t)1356 t += 11357 return temp13581359class Stack:1360 def __init__(self):1361 self.items = []1362 def isEmpty(self):1363 return self.items == []1364 def push(self, item):1365 self.items.append(item)1366 def pop(self):1367 return self.items.pop()
...
sn
Source:sn
1#! python32from colored import fg3print('', end='\n\t')4print(fg(0) + '0 : '.rjust(6) + 'black'.ljust(20), end='')5print(fg(1) + '1 : '.rjust(6) + 'red'.ljust(20), end='')6print(fg(2) + '2 : '.rjust(6) + 'green'.ljust(20), end='')7print(fg(3) + '3 : '.rjust(6) + 'yellow'.ljust(20), end='\n\t')8print(fg(4) + '4 : '.rjust(6) + 'blue'.ljust(20), end='')9print(fg(5) + '5 : '.rjust(6) + 'magenta'.ljust(20), end='')10print(fg(6) + '6 : '.rjust(6) + 'cyan'.ljust(20), end='')11print(fg(7) + '7 : '.rjust(6) + 'light_gray'.ljust(20), end='\n\t')12print(fg(8) + '8 : '.rjust(6) + 'dark_gray'.ljust(20), end='')13print(fg(9) + '9 : '.rjust(6) + 'light_red'.ljust(20), end='')14print(fg(10) + '10 : '.rjust(6) + 'light_green'.ljust(20), end='')15print(fg(11) + '11 : '.rjust(6) + 'light_yellow'.ljust(20), end='\n\t')16print(fg(12) + '12 : '.rjust(6) + 'light_blue'.ljust(20), end='')17print(fg(13) + '13 : '.rjust(6) + 'light_magenta'.ljust(20), end='')18print(fg(14) + '14 : '.rjust(6) + 'light_cyan'.ljust(20), end='')19print(fg(15) + '15 : '.rjust(6) + 'white'.ljust(20), end='\n\t')20print(fg(16) + '16 : '.rjust(6) + 'grey_0'.ljust(20), end='')21print(fg(17) + '17 : '.rjust(6) + 'navy_blue'.ljust(20), end='')22print(fg(18) + '18 : '.rjust(6) + 'dark_blue'.ljust(20), end='')23print(fg(19) + '19 : '.rjust(6) + 'blue_3a'.ljust(20), end='\n\t')24print(fg(20) + '20 : '.rjust(6) + 'blue_3b'.ljust(20), end='')25print(fg(21) + '21 : '.rjust(6) + 'blue_1'.ljust(20), end='')26print(fg(22) + '22 : '.rjust(6) + 'dark_green'.ljust(20), end='')27print(fg(23) + '23 : '.rjust(6) + 'deep_sky_blue_4a'.ljust(20), end='\n\t') 28print(fg(24) + '24 : '.rjust(6) + 'deep_sky_blue_4b'.ljust(20), end='') 29print(fg(25) + '25 : '.rjust(6) + 'deep_sky_blue_4c'.ljust(20), end='') 30print(fg(26) + '26 : '.rjust(6) + 'dodger_blue_3'.ljust(20), end='') 31print(fg(27) + '27 : '.rjust(6) + 'dodger_blue_2'.ljust(20), end='\n\t') 32print(fg(28) + '28 : '.rjust(6) + 'green_4'.ljust(20), end='') 33print(fg(29) + '29 : '.rjust(6) + 'spring_green_4'.ljust(20), end='') 34print(fg(30) + '30 : '.rjust(6) + 'turquoise_4'.ljust(20), end='') 35print(fg(31) + '31 : '.rjust(6) + 'deep_sky_blue_3a'.ljust(20), end='\n\t') 36print(fg(32) + '32 : '.rjust(6) + 'deep_sky_blue_3b'.ljust(20), end='') 37print(fg(33) + '33 : '.rjust(6) + 'dodger_blue_1'.ljust(20), end='') 38print(fg(34) + '34 : '.rjust(6) + 'green_3a'.ljust(20), end='') 39print(fg(35) + '35 : '.rjust(6) + 'spring_green_3a'.ljust(20), end='\n\t') 40print(fg(36) + '36 : '.rjust(6) + 'dark_cyan'.ljust(20), end='') 41print(fg(37) + '37 : '.rjust(6) + 'light_sea_green'.ljust(20), end='') 42print(fg(38) + '38 : '.rjust(6) + 'deep_sky_blue_2'.ljust(20), end='') 43print(fg(39) + '39 : '.rjust(6) + 'deep_sky_blue_1'.ljust(20), end='\n\t') 44print(fg(40) + '40 : '.rjust(6) + 'green_3b'.ljust(20), end='') 45print(fg(41) + '41 : '.rjust(6) + 'spring_green_3b'.ljust(20), end='') 46print(fg(42) + '42 : '.rjust(6) + 'spring_green_2a'.ljust(20), end='') 47print(fg(43) + '43 : '.rjust(6) + 'cyan_3'.ljust(20), end='\n\t') 48print(fg(44) + '44 : '.rjust(6) + 'dark_turquoise'.ljust(20), end='') 49print(fg(45) + '45 : '.rjust(6) + 'turquoise_2'.ljust(20), end='') 50print(fg(46) + '46 : '.rjust(6) + 'green_1'.ljust(20), end='') 51print(fg(47) + '47 : '.rjust(6) + 'spring_green_2b'.ljust(20), end='\n\t') 52print(fg(48) + '48 : '.rjust(6) + 'spring_green_1'.ljust(20), end='') 53print(fg(49) + '49 : '.rjust(6) + 'medium_spring_green'.ljust(20), end='') 54print(fg(50) + '50 : '.rjust(6) + 'cyan_2'.ljust(20), end='') 55print(fg(51) + '51 : '.rjust(6) + 'cyan_1'.ljust(20), end='\n\t') 56print(fg(52) + '52 : '.rjust(6) + 'dark_red_1'.ljust(20), end='') 57print(fg(53) + '53 : '.rjust(6) + 'deep_pink_4a'.ljust(20), end='') 58print(fg(54) + '54 : '.rjust(6) + 'purple_4a'.ljust(20), end='') 59print(fg(55) + '55 : '.rjust(6) + 'purple_4b'.ljust(20), end='\n\t') 60print(fg(56) + '56 : '.rjust(6) + 'purple_3'.ljust(20), end='') 61print(fg(57) + '57 : '.rjust(6) + 'blue_violet'.ljust(20), end='') 62print(fg(58) + '58 : '.rjust(6) + 'orange_4a'.ljust(20), end='') 63print(fg(59) + '59 : '.rjust(6) + 'grey_37'.ljust(20), end='\n\t') 64print(fg(60) + '60 : '.rjust(6) + 'medium_purple_4'.ljust(20), end='') 65print(fg(61) + '61 : '.rjust(6) + 'slate_blue_3a'.ljust(20), end='') 66print(fg(62) + '62 : '.rjust(6) + 'slate_blue_3b'.ljust(20), end='') 67print(fg(63) + '63 : '.rjust(6) + 'royal_blue_1'.ljust(20), end='\n\t') 68print(fg(64) + '64 : '.rjust(6) + 'chartreuse_4'.ljust(20), end='') 69print(fg(65) + '65 : '.rjust(6) + 'dark_sea_green_4a'.ljust(20), end='') 70print(fg(66) + '66 : '.rjust(6) + 'pale_turquoise_4'.ljust(20), end='') 71print(fg(67) + '67 : '.rjust(6) + 'steel_blue'.ljust(20), end='\n\t') 72print(fg(68) + '68 : '.rjust(6) + 'steel_blue_3'.ljust(20), end='') 73print(fg(69) + '69 : '.rjust(6) + 'cornflower_blue'.ljust(20), end='') 74print(fg(70) + '70 : '.rjust(6) + 'chartreuse_3a'.ljust(20), end='') 75print(fg(71) + '71 : '.rjust(6) + 'dark_sea_green_4b'.ljust(20), end='\n\t') 76print(fg(72) + '72 : '.rjust(6) + 'cadet_blue_2'.ljust(20), end='') 77print(fg(73) + '73 : '.rjust(6) + 'cadet_blue_1'.ljust(20), end='') 78print(fg(74) + '74 : '.rjust(6) + 'sky_blue_3'.ljust(20), end='') 79print(fg(75) + '75 : '.rjust(6) + 'steel_blue_1a'.ljust(20), end='\n\t') 80print(fg(76) + '76 : '.rjust(6) + 'chartreuse_3b'.ljust(20), end='') 81print(fg(77) + '77 : '.rjust(6) + 'pale_green_3a'.ljust(20), end='') 82print(fg(78) + '78 : '.rjust(6) + 'sea_green_3'.ljust(20), end='') 83print(fg(79) + '79 : '.rjust(6) + 'aquamarine_3'.ljust(20), end='\n\t') 84print(fg(80) + '80 : '.rjust(6) + 'medium_turquoise'.ljust(20), end='') 85print(fg(81) + '81 : '.rjust(6) + 'steel_blue_1b'.ljust(20), end='') 86print(fg(82) + '82 : '.rjust(6) + 'chartreuse_2a'.ljust(20), end='') 87print(fg(83) + '83 : '.rjust(6) + 'sea_green_2'.ljust(20), end='\n\t') 88print(fg(84) + '84 : '.rjust(6) + 'sea_green_1a'.ljust(20), end='') 89print(fg(85) + '85 : '.rjust(6) + 'sea_green_1b'.ljust(20), end='') 90print(fg(86) + '86 : '.rjust(6) + 'aquamarine_1a'.ljust(20), end='') 91print(fg(87) + '87 : '.rjust(6) + 'dark_slate_gray_2'.ljust(20), end='\n\t') 92print(fg(88) + '88 : '.rjust(6) + 'dark_red_2'.ljust(20), end='') 93print(fg(89) + '89 : '.rjust(6) + 'deep_pink_4b'.ljust(20), end='') 94print(fg(90) + '90 : '.rjust(6) + 'dark_magenta_1'.ljust(20), end='') 95print(fg(91) + '91 : '.rjust(6) + 'dark_magenta_2'.ljust(20), end='\n\t') 96print(fg(92) + '92 : '.rjust(6) + 'dark_violet_1a'.ljust(20), end='') 97print(fg(93) + '93 : '.rjust(6) + 'purple_1a'.ljust(20), end='') 98print(fg(94) + '94 : '.rjust(6) + 'orange_4b'.ljust(20), end='') 99print(fg(95) + '95 : '.rjust(6) + 'light_pink_4'.ljust(20), end='\n\t') 100print(fg(96) + '96 : '.rjust(6) + 'plum_4'.ljust(20), end='') 101print(fg(97) + '97 : '.rjust(6) + 'medium_purple_3a'.ljust(20), end='') 102print(fg(98) + '98 : '.rjust(6) + 'medium_purple_3b'.ljust(20), end='') 103print(fg(99) + '99 : '.rjust(6) + 'slate_blue_1'.ljust(20), end='\n\t') 104print(fg(100) + '100 : '.rjust(6) + 'yellow_4a'.ljust(20), end='') 105print(fg(101) + '101 : '.rjust(6) + 'wheat_4'.ljust(20), end='') 106print(fg(102) + '102 : '.rjust(6) + 'grey_53'.ljust(20), end='') 107print(fg(103) + '103 : '.rjust(6) + 'light_slate_grey'.ljust(20), end='\n\t') 108print(fg(104) + '104 : '.rjust(6) + 'medium_purple'.ljust(20), end='') 109print(fg(105) + '105 : '.rjust(6) + 'light_slate_blue'.ljust(20), end='') 110print(fg(106) + '106 : '.rjust(6) + 'yellow_4b'.ljust(20), end='') 111print(fg(107) + '107 : '.rjust(6) + 'dark_olive_green_3a'.ljust(20), end='\n\t') 112print(fg(108) + '108 : '.rjust(6) + 'dark_green_sea'.ljust(20), end='') 113print(fg(109) + '109 : '.rjust(6) + 'light_sky_blue_3a'.ljust(20), end='') 114print(fg(110) + '110 : '.rjust(6) + 'light_sky_blue_3b'.ljust(20), end='') 115print(fg(111) + '111 : '.rjust(6) + 'sky_blue_2'.ljust(20), end='\n\t') 116print(fg(112) + '112 : '.rjust(6) + 'chartreuse_2b'.ljust(20), end='') 117print(fg(113) + '113 : '.rjust(6) + 'dark_olive_green_3b'.ljust(20), end='') 118print(fg(114) + '114 : '.rjust(6) + 'pale_green_3b'.ljust(20), end='') 119print(fg(115) + '115 : '.rjust(6) + 'dark_sea_green_3a'.ljust(20), end='\n\t') 120print(fg(116) + '116 : '.rjust(6) + 'dark_slate_gray_3'.ljust(20), end='') 121print(fg(117) + '117 : '.rjust(6) + 'sky_blue_1'.ljust(20), end='') 122print(fg(118) + '118 : '.rjust(6) + 'chartreuse_1'.ljust(20), end='') 123print(fg(119) + '119 : '.rjust(6) + 'light_green_2'.ljust(20), end='\n\t') 124print(fg(120) + '120 : '.rjust(6) + 'light_green_3'.ljust(20), end='') 125print(fg(121) + '121 : '.rjust(6) + 'pale_green_1a'.ljust(20), end='') 126print(fg(122) + '122 : '.rjust(6) + 'aquamarine_1b'.ljust(20), end='') 127print(fg(123) + '123 : '.rjust(6) + 'dark_slate_gray_1'.ljust(20), end='\n\t') 128print(fg(124) + '124 : '.rjust(6) + 'red_3a'.ljust(20), end='') 129print(fg(125) + '125 : '.rjust(6) + 'deep_pink_4c'.ljust(20), end='') 130print(fg(126) + '126 : '.rjust(6) + 'medium_violet_red'.ljust(20), end='') 131print(fg(127) + '127 : '.rjust(6) + 'magenta_3a'.ljust(20), end='\n\t') 132print(fg(128) + '128 : '.rjust(6) + 'dark_violet_1b'.ljust(20), end='') 133print(fg(129) + '129 : '.rjust(6) + 'purple_1b'.ljust(20), end='') 134print(fg(130) + '130 : '.rjust(6) + 'dark_orange_3a'.ljust(20), end='') 135print(fg(131) + '131 : '.rjust(6) + 'indian_red_1a'.ljust(20), end='\n\t') 136print(fg(132) + '132 : '.rjust(6) + 'hot_pink_3a'.ljust(20), end='') 137print(fg(133) + '133 : '.rjust(6) + 'medium_orchid_3'.ljust(20), end='') 138print(fg(134) + '134 : '.rjust(6) + 'medium_orchid'.ljust(20), end='') 139print(fg(135) + '135 : '.rjust(6) + 'medium_purple_2a'.ljust(20), end='\n\t') 140print(fg(136) + '136 : '.rjust(6) + 'dark_goldenrod'.ljust(20), end='') 141print(fg(137) + '137 : '.rjust(6) + 'light_salmon_3a'.ljust(20), end='') 142print(fg(138) + '138 : '.rjust(6) + 'rosy_brown'.ljust(20), end='') 143print(fg(139) + '139 : '.rjust(6) + 'grey_63'.ljust(20), end='\n\t') 144print(fg(140) + '140 : '.rjust(6) + 'medium_purple_2b'.ljust(20), end='') 145print(fg(141) + '141 : '.rjust(6) + 'medium_purple_1'.ljust(20), end='') 146print(fg(142) + '142 : '.rjust(6) + 'gold_3a'.ljust(20), end='') 147print(fg(143) + '143 : '.rjust(6) + 'dark_khaki'.ljust(20), end='\n\t') 148print(fg(144) + '144 : '.rjust(6) + 'navajo_white_3'.ljust(20), end='') 149print(fg(145) + '145 : '.rjust(6) + 'grey_69'.ljust(20), end='') 150print(fg(146) + '146 : '.rjust(6) + 'light_steel_blue_3'.ljust(20), end='') 151print(fg(147) + '147 : '.rjust(6) + 'light_steel_blue'.ljust(20), end='\n\t') 152print(fg(148) + '148 : '.rjust(6) + 'yellow_3a'.ljust(20), end='') 153print(fg(149) + '149 : '.rjust(6) + 'dark_olive_green_3'.ljust(20), end='') 154print(fg(150) + '150 : '.rjust(6) + 'dark_sea_green_3b'.ljust(20), end='') 155print(fg(151) + '151 : '.rjust(6) + 'dark_sea_green_2'.ljust(20), end='\n\t') 156print(fg(152) + '152 : '.rjust(6) + 'light_cyan_3'.ljust(20), end='') 157print(fg(153) + '153 : '.rjust(6) + 'light_sky_blue_1'.ljust(20), end='') 158print(fg(154) + '154 : '.rjust(6) + 'green_yellow'.ljust(20), end='') 159print(fg(155) + '155 : '.rjust(6) + 'dark_olive_green_2'.ljust(20), end='\n\t') 160print(fg(156) + '156 : '.rjust(6) + 'pale_green_1b'.ljust(20), end='') 161print(fg(157) + '157 : '.rjust(6) + 'dark_sea_green_5b'.ljust(20), end='') 162print(fg(158) + '158 : '.rjust(6) + 'dark_sea_green_5a'.ljust(20), end='') 163print(fg(159) + '159 : '.rjust(6) + 'pale_turquoise_1'.ljust(20), end='\n\t') 164print(fg(160) + '160 : '.rjust(6) + 'red_3b'.ljust(20), end='') 165print(fg(161) + '161 : '.rjust(6) + 'deep_pink_3a'.ljust(20), end='') 166print(fg(162) + '162 : '.rjust(6) + 'deep_pink_3b'.ljust(20), end='') 167print(fg(163) + '163 : '.rjust(6) + 'magenta_3b'.ljust(20), end='\n\t') 168print(fg(164) + '164 : '.rjust(6) + 'magenta_3c'.ljust(20), end='') 169print(fg(165) + '165 : '.rjust(6) + 'magenta_2a'.ljust(20), end='') 170print(fg(166) + '166 : '.rjust(6) + 'dark_orange_3b'.ljust(20), end='') 171print(fg(167) + '167 : '.rjust(6) + 'indian_red_1b'.ljust(20), end='\n\t') 172print(fg(168) + '168 : '.rjust(6) + 'hot_pink_3b'.ljust(20), end='') 173print(fg(169) + '169 : '.rjust(6) + 'hot_pink_2'.ljust(20), end='') 174print(fg(170) + '170 : '.rjust(6) + 'orchid'.ljust(20), end='') 175print(fg(171) + '171 : '.rjust(6) + 'medium_orchid_1a'.ljust(20), end='\n\t') 176print(fg(172) + '172 : '.rjust(6) + 'orange_3'.ljust(20), end='') 177print(fg(173) + '173 : '.rjust(6) + 'light_salmon_3b'.ljust(20), end='') 178print(fg(174) + '174 : '.rjust(6) + 'light_pink_3'.ljust(20), end='') 179print(fg(175) + '175 : '.rjust(6) + 'pink_3'.ljust(20), end='\n\t') 180print(fg(176) + '176 : '.rjust(6) + 'plum_3'.ljust(20), end='') 181print(fg(177) + '177 : '.rjust(6) + 'violet'.ljust(20), end='') 182print(fg(178) + '178 : '.rjust(6) + 'gold_3b'.ljust(20), end='') 183print(fg(179) + '179 : '.rjust(6) + 'light_goldenrod_3'.ljust(20), end='\n\t') 184print(fg(180) + '180 : '.rjust(6) + 'tan'.ljust(20), end='') 185print(fg(181) + '181 : '.rjust(6) + 'misty_rose_3'.ljust(20), end='') 186print(fg(182) + '182 : '.rjust(6) + 'thistle_3'.ljust(20), end='') 187print(fg(183) + '183 : '.rjust(6) + 'plum_2'.ljust(20), end='\n\t') 188print(fg(184) + '184 : '.rjust(6) + 'yellow_3b'.ljust(20), end='') 189print(fg(185) + '185 : '.rjust(6) + 'khaki_3'.ljust(20), end='') 190print(fg(186) + '186 : '.rjust(6) + 'light_goldenrod_2a'.ljust(20), end='') 191print(fg(187) + '187 : '.rjust(6) + 'light_yellow_3'.ljust(20), end='\n\t') 192print(fg(188) + '188 : '.rjust(6) + 'grey_84'.ljust(20), end='') 193print(fg(189) + '189 : '.rjust(6) + 'light_steel_blue_1'.ljust(20), end='') 194print(fg(190) + '190 : '.rjust(6) + 'yellow_2'.ljust(20), end='') 195print(fg(191) + '191 : '.rjust(6) + 'dark_olive_green_1a'.ljust(20), end='\n\t') 196print(fg(192) + '192 : '.rjust(6) + 'dark_olive_green_1b'.ljust(20), end='') 197print(fg(193) + '193 : '.rjust(6) + 'dark_sea_green_1'.ljust(20), end='') 198print(fg(194) + '194 : '.rjust(6) + 'honeydew_2'.ljust(20), end='') 199print(fg(195) + '195 : '.rjust(6) + 'light_cyan_1'.ljust(20), end='\n\t') 200print(fg(196) + '196 : '.rjust(6) + 'red_1'.ljust(20), end='') 201print(fg(197) + '197 : '.rjust(6) + 'deep_pink_2'.ljust(20), end='') 202print(fg(198) + '198 : '.rjust(6) + 'deep_pink_1a'.ljust(20), end='') 203print(fg(199) + '199 : '.rjust(6) + 'deep_pink_1b'.ljust(20), end='\n\t') 204print(fg(200) + '200 : '.rjust(6) + 'magenta_2b'.ljust(20), end='') 205print(fg(201) + '201 : '.rjust(6) + 'magenta_1'.ljust(20), end='') 206print(fg(202) + '202 : '.rjust(6) + 'orange_red_1'.ljust(20), end='') 207print(fg(203) + '203 : '.rjust(6) + 'indian_red_1c'.ljust(20), end='\n\t') 208print(fg(204) + '204 : '.rjust(6) + 'indian_red_1d'.ljust(20), end='') 209print(fg(205) + '205 : '.rjust(6) + 'hot_pink_1a'.ljust(20), end='') 210print(fg(206) + '206 : '.rjust(6) + 'hot_pink_1b'.ljust(20), end='') 211print(fg(207) + '207 : '.rjust(6) + 'medium_orchid_1b'.ljust(20), end='\n\t') 212print(fg(208) + '208 : '.rjust(6) + 'dark_orange'.ljust(20), end='') 213print(fg(209) + '209 : '.rjust(6) + 'salmon_1'.ljust(20), end='') 214print(fg(210) + '210 : '.rjust(6) + 'light_coral'.ljust(20), end='') 215print(fg(211) + '211 : '.rjust(6) + 'pale_violet_red_1'.ljust(20), end='\n\t') 216print(fg(212) + '212 : '.rjust(6) + 'orchid_2'.ljust(20), end='') 217print(fg(213) + '213 : '.rjust(6) + 'orchid_1'.ljust(20), end='') 218print(fg(214) + '214 : '.rjust(6) + 'orange_1'.ljust(20), end='') 219print(fg(215) + '215 : '.rjust(6) + 'sandy_brown'.ljust(20), end='\n\t') 220print(fg(216) + '216 : '.rjust(6) + 'light_salmon_1'.ljust(20), end='') 221print(fg(217) + '217 : '.rjust(6) + 'light_pink_1'.ljust(20), end='') 222print(fg(218) + '218 : '.rjust(6) + 'pink_1'.ljust(20), end='') 223print(fg(219) + '219 : '.rjust(6) + 'plum_1'.ljust(20), end='\n\t') 224print(fg(220) + '220 : '.rjust(6) + 'gold_1'.ljust(20), end='') 225print(fg(221) + '221 : '.rjust(6) + 'light_goldenrod_2b'.ljust(20), end='') 226print(fg(222) + '222 : '.rjust(6) + 'light_goldenrod_2c'.ljust(20), end='') 227print(fg(223) + '223 : '.rjust(6) + 'navajo_white_1'.ljust(20), end='\n\t') 228print(fg(224) + '224 : '.rjust(6) + 'misty_rose1'.ljust(20), end='') 229print(fg(225) + '225 : '.rjust(6) + 'thistle_1'.ljust(20), end='') 230print(fg(226) + '226 : '.rjust(6) + 'yellow_1'.ljust(20), end='') 231print(fg(227) + '227 : '.rjust(6) + 'light_goldenrod_1'.ljust(20), end='\n\t') 232print(fg(228) + '228 : '.rjust(6) + 'khaki_1'.ljust(20), end='') 233print(fg(229) + '229 : '.rjust(6) + 'wheat_1'.ljust(20), end='') 234print(fg(230) + '230 : '.rjust(6) + 'cornsilk_1'.ljust(20), end='') 235print(fg(231) + '231 : '.rjust(6) + 'grey_100'.ljust(20), end='\n\t') 236print(fg(232) + '232 : '.rjust(6) + 'grey_3'.ljust(20), end='') 237print(fg(233) + '233 : '.rjust(6) + 'grey_7'.ljust(20), end='') 238print(fg(234) + '234 : '.rjust(6) + 'grey_11'.ljust(20), end='') 239print(fg(235) + '235 : '.rjust(6) + 'grey_15'.ljust(20), end='\n\t') 240print(fg(236) + '236 : '.rjust(6) + 'grey_19'.ljust(20), end='') 241print(fg(237) + '237 : '.rjust(6) + 'grey_23'.ljust(20), end='') 242print(fg(238) + '238 : '.rjust(6) + 'grey_27'.ljust(20), end='') 243print(fg(239) + '239 : '.rjust(6) + 'grey_30'.ljust(20), end='\n\t') 244print(fg(240) + '240 : '.rjust(6) + 'grey_35'.ljust(20), end='') 245print(fg(241) + '241 : '.rjust(6) + 'grey_39'.ljust(20), end='') 246print(fg(242) + '242 : '.rjust(6) + 'grey_42'.ljust(20), end='') 247print(fg(243) + '243 : '.rjust(6) + 'grey_46'.ljust(20), end='\n\t') 248print(fg(244) + '244 : '.rjust(6) + 'grey_50'.ljust(20), end='') 249print(fg(245) + '245 : '.rjust(6) + 'grey_54'.ljust(20), end='') 250print(fg(246) + '246 : '.rjust(6) + 'grey_58'.ljust(20), end='') 251print(fg(247) + '247 : '.rjust(6) + 'grey_62'.ljust(20), end='\n\t') 252print(fg(248) + '248 : '.rjust(6) + 'grey_66'.ljust(20), end='') 253print(fg(249) + '249 : '.rjust(6) + 'grey_70'.ljust(20), end='') 254print(fg(250) + '250 : '.rjust(6) + 'grey_74'.ljust(20), end='') 255print(fg(251) + '251 : '.rjust(6) + 'grey_78'.ljust(20), end='\n\t') 256print(fg(252) + '252 : '.rjust(6) + 'grey_82'.ljust(20), end='') 257print(fg(253) + '253 : '.rjust(6) + 'grey_85'.ljust(20), end='') 258print(fg(254) + '254 : '.rjust(6) + 'grey_89'.ljust(20), end='') ...
tokenization.py
Source:tokenization.py
...4def tokenize(text):5 nlp = spacy.load("en_core_web_sm")6 doc = nlp(text)7 save_figures = False8 print("token".ljust(10), "lemma".ljust(10), "pos".ljust(6), "tag".ljust(6), "dep".ljust(10),9 "shape".ljust(10), "alpha", "stop")10 print("------------------------------------------------------------------------------")11 for token in doc:12 print(token.text.ljust(10), token.lemma_.ljust(10), token.pos_.ljust(6), token.tag_.ljust(6), token.dep_.ljust(10),13 token.shape_.ljust(10), token.is_alpha, token.is_stop)14 15def recognize(text):16 nlp = spacy.load("en_core_web_sm")17 doc = nlp(text)18 for ent in doc.ents:19 print(ent.text.ljust(12), ent.label_.ljust(10), ent.start_char, ent.end_char)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!