How to use gotoT method in avocado

Best Python code snippet using avocado_python

sbc.py

Source:sbc.py Github

copy

Full Screen

1from contextfree import *2import copy3class Item(object):4 def __init__(self, rule, dot):5 self.rule = rule6 self.dot = dot7 def dotV(self):8 if self.dot == len(self.rule.rhs):9 return None10 else:11 return self.rule.rhs[self.dot]12 def __eq__(self, i2):13 return type(self) == type(i2) and self.rule == i2.rule and self.dot == i2.dot14 def __ne__(self, i2):15 return not self.__eq__(self,i2)16 def __cmp__(self, i2):17 if type(self) != type(i2):18 return cmp(type(self), type(i2))19 if self.rule != i2.rule:20 return cmp(self.rule, i2.rule)21 return cmp(self.dot, i2.dot)22 def __hash__(self):23 return hash(type(self))^hash(self.rule) ^ hash(self.dot)24 def __repr__(self):25 s = str(self.rule.lhs) + ' ::= '26 for i in range(len(self.rule.rhs)):27 if self.dot == i:28 s += '.'29 s += str(self.rule.rhs[i])30 if self.dot == len(self.rule.rhs):31 s += '.'32 return s33class SuffItem(Item):34 def __repr__(self):35 s = str(self.rule.lhs) + ' ::= ...'36 for i in range(len(self.rule.rhs)):37 if self.dot == i:38 s += '.'39 if i >= self.dot:40 s += str(self.rule.rhs[i])41 if self.dot == len(self.rule.rhs):42 s += '.'43 return s44def closure(I, G):45 Q = list(I)46 J = set(I)47 while len(Q) > 0:48 i = Q.pop(0)49 B = i.dotV()50 for r in G.rules:51 if r.lhs == B:52 j = Item(r,0)53 if j not in J:54 Q.append(j)55 J.add(j)56 elif isinstance(i, SuffItem) and B == None:57 A = i.rule.lhs58 for dot in range(len(r.rhs)):59 if A == r.rhs[dot]:60 j = SuffItem(r, dot+1)61 if j not in J:62 Q.append(j)63 J.add(j)64 65 return frozenset(J)66def goto(I, X, G):67 J = set()68 for i in I:69 if i.dotV() != X:70 continue71 j = copy.copy(i)72 j.dot += 173 J.add(j)74 return closure(J, G)75def items(G):76 inititems = set()77 for r in G.rules:78 for dot in range(len(r.rhs)):79 if r.rhs[dot] in G.T:80 inititems.add(SuffItem(r, dot))81 print inititems82 inititems = closure(inititems, G)83 print inititems84 acceptitems = closure(set([SuffItem(G.rules[0],3)]), G)85 C = set([inititems])86 Q = list(C)87 while len(Q) > 0:88 I = Q.pop(0)89 for X in G.V:90 J = goto(I, X, G)91 if J == set() or J in C:92 continue93 Q.append(J)94 C.add(J)95 return (inititems, acceptitems, C)96# this isn't working yet...problem, have to number item sets....97def tables(G):98 (Iinit,Iaccept,C) = items(G)99 action = {}100 gotot = {}101 for I in C:102 for i in I:103 if i.dotV() in G.T:104 a = i.dotV()105 J = goto(I,a,G)106 if J not in C:107 continue108 act = ('shift', J)109 if (I,a) in action and action[I,a] != act:110 print 'conflict: ' + str(I) + ' '+ str (a) + '\n' + str(act) + '\n' + str(action[I,a]) + '\n'111 return112 action[I,a] = act113 elif not isinstance(i, SuffItem) and i.dotV() == None: # A -> alpha . ugly, but meh114 for b in G.follow[i.rule.lhs]:115 act = ('reduce', i.rule)116 if (I,b) in action and action[I,b] != act:117 print I118 print 'conflict: ' + str(I) + ' ' + str(b) + '\n' + str(act) + '\n' + str(action[I,b]) + '\n'119 return120 action[I,b] = act121# if iaccpet in I: # accept122# print 'got accept'123# eof = iaccpet.dotV()124# act = ('accept', None)125# if (I,eof) in action:126# print 'conflict: \n' + str(act) + '\n' + str(action[I,eof]) + '\n'127# return128# action[I,eof] = act129 for A in G.NT:130 J = goto(I,A,G)131 if J not in C:132 continue133 gotot[I,A] = J134 return (Iinit, Iaccept, action, gotot)135def sbc(w, s0, f, actiont, gotot):136 xs=[]137 x = []138 e=[]139 S=[s0]140 pos = 0141 while True:142 if pos >= len(w):143 break144 a = w[pos]145 s = S[len(S)-1]146 if (s,a) not in actiont: # error147 e.append(pos)148 xs.append(x)149 x = []150 S.append(s0)151 pos +=1152 continue153 (act, arg) = actiont[s,a]154 if act == 'shift':155 S.append(arg)156 x.append(a)157 pos +=1158 elif act == 'reduce':159 x.append(arg)160 A = arg.lhs161 beta = arg.rhs162 del S[len(S)-len(beta):len(S)] # pop |beta| states163 s = S[len(S)-1]164 S.append(gotot[s,A])165 xs.append(x)166 return (xs,e)167def slr(w, s0, f, actiont, gotot):168 x = []169 S = [s0]170 pos = 0171 while True:172 if pos >= len(w):173 break;174 a = w[pos]175 ta = type(a)176 s = S[len(S)-1]177 if (s,ta) not in actiont: # error178 return False, None179 (act, arg) = actiont[s,ta]180 if act == 'shift':181 S.append(arg)182 x.append(a)183 pos += 1184 elif act == 'reduce': # A -> beta185 x.append(arg)186 A = arg.lhs187 beta = arg.rhs188 del S[len(S)-len(beta):len(S)] # pop |beta| states189 s = S[len(S)-1]190 S.append(gotot[s,A])191 if S[len(S)-1] == f:192 return True, x193 else:194 return False, None195class SBC(object):196 def __init__(self, G):197 self.G = G198 self.Grev = G.rev()199 (self.init, self.accept, self.action, self.goto) = tables(self.G)200 (self.rinit, self.raccept, self.raction, self.rgoto) = tables(self.Grev)201 def parse(self, w):202 xs=[]203 x = []204 e=[]205 S=[self.init]206 pos = 0207 while True:208 if pos >= len(w):209 break210 a = w[pos]211 ta = type(a)212 s = S[len(S)-1]213 if (s,ta) not in self.action: # error214 pos0 = self.pback(w, pos)215 e.append((pos0,pos))216 xs.append(x)217 x = []218 S.append(self.init)219 if pos0 == pos: # not sure if this is right...could be non-terminating220 pos += 1221 #pos +=1222 continue223 (act, arg) = self.action[s,ta]224 if act == 'shift':225 S.append(arg)226 x.append(a)227 pos +=1228 elif act == 'reduce':229 x.append(arg)230 A = arg.lhs231 beta = arg.rhs232 del S[len(S)-len(beta):len(S)] # pop |beta| states233 s = S[len(S)-1]234 S.append(self.goto[s,A])235 xs.append(x)236 return (xs,e)237 def pback(self, w, pos):238 S=[self.rinit]239 while True:240 if pos < 0:241 break242 a = w[pos]243 ta = type(a)244 s = S[len(S)-1]245 if (s,ta) not in self.raction: # error246 return pos247 (act, arg) = self.raction[s,ta]248 if act == 'shift':249 S.append(arg)250 pos -= 1251 elif act == 'reduce':252 A = arg.lhs253 beta = arg.rhs254 del S[len(S)-len(beta):len(S)] # pop |beta| states255 s = S[len(S)-1]256 S.append(self.rgoto[s,A])257 return pos258G = Grammar([259 Rule('S', ('bof', 'E', 'eof')),260 Rule('E', ('E', '+', 'T')),261 Rule('E', ('T',)),262 Rule('T', ('T', '*', 'F')),263 Rule('T', ('F',)),264 Rule('F', ('(', 'E', ')')),265 Rule('F', ('c',))...

Full Screen

Full Screen

enums.py

Source:enums.py Github

copy

Full Screen

1from enum import Enum, auto2# For functions and variables3class Types(Enum):4 BOOL = "bool"5 FLOAT = "float"6 INT = "int"7 STRING = "string"8 VOID = "void"9 PTR = "ptr"10# For quadruples and VM's switch execution11class Operations(Enum):12 AND = "&&"13 ASSIGNOP = "="14 DIFF = "!="15 DIVIDES = "/"16 ENDSUB = "ENDSUB"17 EQ = "=="18 EQGT = ">="19 EQLT = "<="20 ERA = "ERA"21 GOSUB = "GOSUB"22 GOTO = "GOTO"23 GOTOF = "GOTOF"24 GOTOT = "GOTOT"25 GT = ">"26 LT = "<"27 MINUS = "-"28 OPT_ASSIGN = "OPT_ASSIGN"29 OPT_PARAM = "OPT_PARAM"30 OR = "||"31 PARAM = "PARAM"32 PLUS = "+"33 PRINT = "PRINT"34 READ = "READ"35 SAVEPTR = "SAVEPTR"36 TIMES = "*"37 VER = "VER"38# To check keywords and types of actions permitted39class ScopeTypes(Enum):40 CLASS = auto()41 CLASS_FUNCTION = auto()42 FUNCTION = auto()43 GENERIC = auto()44 GLOBAL = auto()45 LOOP = auto()46# For better readability in VM's output47class Segments(Enum):48 FUNCTIONS = "%%functions"49 GLOBAL_MEMORY = "%%global_memory"50 GLOBAL_RESOURCES = "%%global_resources"...

Full Screen

Full Screen

quadruple.py

Source:quadruple.py Github

copy

Full Screen

1from dataclasses import dataclass2from enum import Enum3class Operator(Enum):4 """5 Operadores disponibles para la clase Cuadruple.6 """7 PLUS = '+'8 MINUS = '-'9 TIMES = '*'10 DIVIDE = '/'11 ASSIGN = '='12 AND = '&&'13 OR = '||'14 LESSTHAN = '<'15 GREATERTHAN = '>'16 LESSTHANOREQ = '<='17 GREATERTHANOREQ = '>='18 EQUAL = '=='19 NOTEQUAL = '!='20 READ = 'read'21 WRITE = 'write'22 GOTO = 'goto'23 GOTOF = 'gotof'24 GOTOT = 'gotot'25 GOSUB = 'gosub'26 PARAMETER = 'parameter'27 ENDFUN = 'endfun'28 ERA = 'era'29 VERIFY = 'verify'30 ASSIGNPTR = 'ASSIGNPTR'31@dataclass32class Quadruple:33 operator: Operator34 left_operand: any35 right_operand: any...

Full Screen

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 avocado 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