How to use getchild method in pyatom

Best Python code snippet using pyatom_python

PythonVisitor.py

Source:PythonVisitor.py Github

copy

Full Screen

1# Copyright (c) Corporation for National Research Initiatives23from org.python.parser import Visitor, SimpleNode4from org.python.parser.PythonGrammarTreeConstants import *5from org.python.parser import SimpleNode67from org.python.compiler import Future89 10comp_ops = {JJTLESS_CMP : 'lt',11 JJTEQUAL_CMP : 'eq',12 JJTGREATER_CMP : 'gt', 13 JJTGREATER_EQUAL_CMP: 'ge',14 JJTLESS_EQUAL_CMP : 'le',15 JJTNOTEQUAL_CMP : 'ne',16 JJTIS_NOT_CMP : 'isnot',17 JJTIS_CMP : 'is',18 JJTIN_CMP : 'in',19 JJTNOT_IN_CMP : 'notin',20 JJTLEFTDIREDGE : 'lde',21 JJTRIGHTDIREDGE : 'rde',22 JJTBIDIREDGE : 'bde',23 JJTLIKE : 'like'24 }252627 28def nodeToList(node, start=0):29 nodes = []30 for i in range(start, node.numChildren):31 nodes.append(node.getChild(i))32 return nodes3334def nodeToStrings(node, start=0):35 names = []36 for i in range(start, node.numChildren):37 names.append(node.getChild(i).getInfo())38 return names394041 42def getDocString(suite):43 if suite.numChildren > 0:44 n = suite.getChild(0)45 if n.id == JJTEXPR_STMT and n.getChild(0).id == JJTSTRING:46 return n.getChild(0).getInfo()47 return None484950 51class PythonVisitor(Visitor):52 def __init__(self, walker):53 # a SimpleCompiler54 self.walker = walker5556 # The fast_locals arg is supplied when this method is used for57 # names in local scope.58 def getName(self, node, fast_locals=0):59 if not node.id == JJTNAME:60 return None61 s = node.getInfo()62 if fast_locals:63 return s64 if s[:2] == '__' and s[-2:] != '__' and self.walker.className:65 s = "_%s%s" % (self.walker.className, s)66 return s6768 def walk(self, node):69 self.suite(node)7071 def startnode(self, node):72 self.walker.setline(node.beginLine)7374 def suite(self, node):75 return self.walker.suite(nodeToList(node))7677 file_input = suite78 single_input = suite79 eval_input = suite8081 def exec_stmt(self, node):82 self.startnode(node)83 code = node.getChild(0).visit(self)84 globs = locs = None85 if node.numChildren > 1:86 globs = node.getChild(1).visit(self)87 if node.numChildren > 2:88 locs = node.getChild(2).visit(self)89 return self.walker.exec_stmt(code, globs, locs)9091 def assert_stmt(self, node):92 self.startnode(node)93 test = node.getChild(0).visit(self)94 if node.numChildren > 1:95 message = node.getChild(1).visit(self)96 else:97 message = None98 return self.walker.assert_stmt(test, message)99100 def pass_stmt(self, node):101 self.startnode(node)102 return self.walker.pass_stmt()103104 def break_stmt(self, node):105 self.startnode(node) 106 return self.walker.break_stmt()107108 def continue_stmt(self, node):109 self.startnode(node)110 return self.walker.continue_stmt()111112 def return_stmt(self, node):113 self.startnode(node)114 if node.numChildren == 0:115 return self.walker.return_stmt()116 else:117 return self.walker.return_stmt(node.getChild(0))118119 def global_stmt(self, node):120 self.startnode(node)121 return self.walker.global_stmt(nodeToStrings(node))122123 def raise_stmt(self, node):124 self.startnode(node)125 exc_type = exc_value = exc_traceback = None126 n = node.numChildren127 if n > 0:128 exc_type = node.getChild(0).visit(self)129 if n > 1:130 exc_value = node.getChild(1).visit(self)131 if n > 2:132 exc_traceback = node.getChild(2).visit(self)133 return self.walker.raise_stmt(exc_type, exc_value, exc_traceback)134135 def Import(self, node):136 self.startnode(node)137 names = self.import_as_name(node, 0)138 return self.walker.import_stmt(names)139140 def ImportFrom(self, node):141 Future.checkFromFuture(node) # future stmt support142 self.startnode(node)143 if node.numChildren > 1:144 names = self.import_as_name(node, 1)145 return self.walker.importfrom_stmt(node.getChild(0).visit(self), 146 names)147 else:148 return self.walker.importfrom_stmt(149 node.getChild(0).visit(self), "*")150151 def import_as_name(self, node, startnode=0):152 names = []153 for i in range(startnode, node.numChildren):154 n = node.getChild(i)155 if n.id == JJTDOTTED_AS_NAME:156 dotted = n.getChild(0).visit(self)157 asname = n.getChild(1).getInfo()158 elif n.id == JJTIMPORT_AS_NAME:159 dotted = n.getChild(0).getInfo()160 asname = n.getChild(1).getInfo()161 elif n.id == JJTDOTTED_NAME:162 dotted = n.visit(self)163 asname = None164 else:165 dotted = n.getInfo()166 asname = None167 names.append((dotted, asname))168 return names169170 def dotted_name(self, node):171 return nodeToStrings(node)172173 def print_ext(self, node):174 # There better be exactly one subnode175 self.startnode(node)176 return node.getChild(0)177178 def print_stmt(self, node):179 self.startnode(node)180 n = node.numChildren181 rets = []182 printext = 0183 file = None184 start = 0185 nochildren = 0186 # extended print?187 if n > 0 and node.getChild(0).id == JJTPRINT_EXT:188 printext = 1189 file = self.print_ext(node.getChild(0))190 start = 1191 nochildren = 1192 for i in range(start, n-1):193 child = node.getChild(i)194 if printext:195 rets.append(self.walker.print_continued_to(file, child))196 else:197 rets.append(self.walker.print_continued(child))198 if n == nochildren:199 if printext:200 rets.append(self.walker.print_line_to(file))201 else:202 rets.append(self.walker.print_line())203 elif node.getChild(n-1).id != JJTCOMMA:204 child = node.getChild(n-1)205 if printext:206 rets.append(self.walker.print_line_to(file, child))207 else:208 rets.append(self.walker.print_line(child))209 return rets210211 def if_stmt(self, node):212 self.startnode(node)213 tests = []214 else_body = None215 n = node.numChildren216 for i in range(0,n-1,2):217 tests.append( (node.getChild(i), node.getChild(i+1)) )218219 if n % 2 == 1:220 else_body = node.getChild(n-1)221222 return self.walker.if_stmt(tests, else_body)223224 def while_stmt(self, node):225 self.startnode(node)226 test = node.getChild(0)227 suite = node.getChild(1)228 if node.numChildren == 3:229 else_body = node.getChild(2)230 else:231 else_body = None232233 return self.walker.while_stmt(test, suite, else_body)234235 def for_stmt(self, node):236 self.startnode(node)237 index = node.getChild(0)238 sequence = node.getChild(1)239 body = node.getChild(2)240 if node.numChildren == 4:241 else_body = node.getChild(3)242 else:243 else_body = None244245 return self.walker.for_stmt(index, sequence, body, else_body)246247 def expr_stmt(self, node):248 if node.getNumChildren() == 1:249 n = node.getChild(0)250 if n.id >= JJTAUG_PLUS and n.id <= JJTAUG_POWER:251 return self.walker.visit(n)252253 self.startnode(node)254 rhs = node.getChild(node.numChildren-1)255 return self.walker.expr_stmt(nodeToList(node)[:-1], rhs)256257 def del_stmt(self, node):258 self.startnode(node)259 return self.walker.del_stmt(nodeToList(node))260261 def Name(self, node):262 #self.startnode(node)263 return self.walker.name_const(264 self.getName(node, self.walker.frame.fast_locals))265266 def Int(self, node):267 #self.startnode(node)268 i = node.getInfo()269 if isinstance(i, type(0)):270 return self.walker.int_const(int(i))271 else:272 return self.walker.long_const(long(i))273274 def Float(self, node):275 #self.startnode(node)276 return self.walker.float_const(float(node.getInfo()))277278 def Complex(self, node):279 #self.startnode(node)280 return self.walker.complex_const(float(node.getInfo())) 281282 def String(self, node):283 #self.startnode(node)284 return self.walker.string_const(node.getInfo())285286 def Ellipses(self, node):287 return self.walker.ellipsis_const()288289 def getSlice(self, node):290 s = [None, None, None]291 n = node.numChildren292 index = 0293 for i in range(n):294 child = node.getChild(i)295 if child.id == JJTCOLON:296 index = index+1297 else:298 s[index] = child299 return s300301 def Slice(self, node):302 #self.startnode(node)303 s = self.getSlice(node)304 return self.walker.slice_op(s[0], s[1], s[2])305306 def makeSeqArgs(self, node):307 values = nodeToList(node)308 ret = []309 for value in values:310 if value.id == JJTCOMMA:311 continue312 ret.append(value)313 return ret314315 def list(self, node):316 #self.startnode(node)317 if node.numChildren > 1 and node.getChild(1).id == JJTFOR_STMT:318 return self.walker.list_comprehension(node)319 return self.walker.list_op(self.makeSeqArgs(node))320321 def list_iter(self, node):322 return self.walker.list_iter(node)323 324 def tuple(self, node):325 #self.startnode(node)326 return self.walker.tuple_op(self.makeSeqArgs(node))327328 def dictionary(self, node):329 #self.startnode(node)330 items = []331 for i in range(0, node.numChildren, 2):332 items.append( (node.getChild(i), node.getChild(i+1)) )333 return self.walker.dictionary_op(items)334335 def Dot_Op(self, node):336 #self.startnode(node) 337 obj = node.getChild(0)338 name = self.getName(node.getChild(1))339 return self.walker.get_attribute(obj, name)340341 def Index_Op(self, node):342 obj = node.getChild(0)343 index = node.getChild(1)344 return self.walker.get_item(obj, index)345346 def Call_Op(self, node):347 callee = node.getChild(0)348349 args = []350 keyargs = []351352 kwargs = starargs = None353354 if node.numChildren != 1:355 argsNode = node.getChild(1)356357 n = argsNode.numChildren358 lastarg = argsNode.getChild(n-1);359 if lastarg.id == JJTEXTRAKEYWORDVALUELIST:360 n = n - 1361 kwargs = lastarg362 if n > 0:363 lastarg = argsNode.getChild(n-1);364 if lastarg.id == JJTEXTRAARGVALUELIST:365 n = n - 1366 starargs = lastarg;367368 for i in range(n):369 argNode = argsNode.getChild(i)370 if argNode.id != JJTKEYWORD:371 if len(keyargs) > 0:372 raise ValueError, \373 "non-keyword argument following keyword"374 args.append(argNode)375 else:376 keyargs.append((argNode.getChild(0).getInfo(),377 argNode.getChild(1)))378379 # Check for method invocation380 if callee.id == JJTDOT_OP and kwargs is None and starargs is None:381 object = callee.getChild(0)382 name = self.getName(callee.getChild(1))383 return self.walker.invoke(object, name, args, keyargs)384 if kwargs or starargs:385 return self.walker.call_extra(callee, args, 386 keyargs, starargs, kwargs)387388 return self.walker.call(callee, args, keyargs)389390 def binop(self, node, name):391 #self.startnode(node)392 return self.walker.binary_op(name, node.getChild(0), node.getChild(1))393394 def add_2op(self, node): return self.binop(node, 'add') 395 def sub_2op(self, node): return self.binop(node, 'sub') 396 def mul_2op(self, node): return self.binop(node, 'mul') 397 def div_2op(self, node): return self.binop(node, 'div') 398 def mod_2op(self, node): return self.binop(node, 'mod')399 def and_2op(self, node): return self.binop(node, 'and')400 def lshift_2op(self, node): return self.binop(node, 'lshift')401 def rshift_2op(self, node): return self.binop(node, 'rshift')402 def or_2op(self, node): return self.binop(node, 'or')403 def xor_2op(self, node): return self.binop(node, 'xor')404 def pow_2op(self, node): return self.binop(node, 'pow')405406 def unop(self, node, name):407 #self.startnode(node)408 return self.walker.unary_op(name, node.getChild(0))409410 def abs_1op(self, node): return self.unop(node, 'abs')411 def invert_1op(self, node): return self.unop(node, 'invert')412 def neg_1op(self, node): return self.unop(node, 'neg')413 def abs_1op(self, node): return self.unop(node, 'abs')414 def pos_1op(self, node): return self.unop(node, 'pos')415 def not_1op(self, node): return self.unop(node, 'not')416 def str_1op(self, node): return self.unop(node, 'repr')417418 def aug_binaryop(self, node, name):419 #self.startnode(node)420 return self.walker.aug_binary_op(name, 421 node.getChild(0), node.getChild(1))422423 def aug_plus(self, node): return self.aug_binaryop(node, "__iadd__")424 def aug_minus(self, node): return self.aug_binaryop(node, "__isub__")425 def aug_multiply(self, node): return self.aug_binaryop(node, "__imul__")426 def aug_divide(self, node): return self.aug_binaryop(node, "__idiv__")427 def aug_modulo(self, node): return self.aug_binaryop(node, "__imod__")428 def aug_and(self, node): return self.aug_binaryop(node, "__iand__")429 def aug_or(self, node): return self.aug_binaryop(node, "__ior__")430 def aug_xor(self, node): return self.aug_binaryop(node, "__ixor__")431 def aug_lshift(self, node): return self.aug_binaryop(node, "__ilshift__")432 def aug_rshift(self, node): return self.aug_binaryop(node, "__irshift__")433 def aug_power(self, node): return self.aug_binaryop(node, "__ipow__")434435 def getString(self, node):436 if node.id == JJTSTRING:437 return node.getInfo()438 elif node.id == JJTSTRJOIN:439 return self.getString(node.getChild(0)) + \440 self.getString(node.getChild(1))441 else:442 raise ValueError, 'non string!'443444 def strjoin(self, node):445 return self.walker.string_const(self.getString(node))446447 def comparision(self, node):448 #self.startnode(node)449 start = node.getChild(0)450 tests = []451 for i in range(1, node.numChildren, 2):452 op = comp_ops[node.getChild(i).id]453 obj = node.getChild(i+1)454 tests.append( (op, obj) )455 return self.walker.compare_op(start, tests)456457 def and_boolean(self, node):458 return self.walker.and_op(node.getChild(0), node.getChild(1))459460 def or_boolean(self, node):461 return self.walker.or_op(node.getChild(0), node.getChild(1))462463 def try_stmt(self, node):464 self.startnode(node)465466 n = node.numChildren467 if n == 2:468 return self.walker.tryfinally(node.getChild(0), node.getChild(1))469470 body = node.getChild(0)471 exceptions = []472473 for i in range(1, n-1, 2):474 exc = node.getChild(i)475 if exc.numChildren == 0:476 exc = None477 elif exc.numChildren == 1:478 exc = [exc.getChild(0).visit(self)]479 else:480 exc = [exc.getChild(0).visit(self), exc.getChild(1)]481 exceptions.append( (exc, node.getChild(i+1)) )482483 if n%2 == 0:484 elseClause = node.getChild(n-1)485 else:486 elseClause = None487488 return self.walker.tryexcept(body, exceptions, elseClause)489490 def funcdef(self, node):491 self.startnode(node)492493 funcname = self.getName(node.getChild(0))494495 Body = node.getChild(node.numChildren-1)496497 doc = getDocString(Body)498499 return self.walker.funcdef(funcname, node.scope, Body, doc)500501 def lambdef(self, node):502 Body = node.getChild(node.numChildren-1)503504 retBody = SimpleNode(JJTRETURN_STMT)505 retBody.jjtAddChild(Body, 0)506507 return self.walker.lambdef(node.scope, retBody)508509 def classdef(self, node):510 self.startnode(node)511 name = self.getName(node.getChild(0))512513 n = node.numChildren514 suite = node.getChild(n-1)515 doc = getDocString(suite)516 bases = []517 for i in range(1, n-1):518 bases.append(node.getChild(i).visit(self))519 ...

Full Screen

Full Screen

translation.py

Source:translation.py Github

copy

Full Screen

...30 # print('a',count_p)31 break32 trans(c)33 if len(node.getchildren()) == 2:34 if False in [node.getchild(0).getvalue(), node.getchild(1).getvalue()]:35 node.setvalue(False)36 else:37 node.setvalue(node.getchild(0).getvalue())38 elif node.getdata() == '[STATEMENT]':39 for c in node.getchildren():40 trans(c)41 node.setvalue(node.getchild(0).getvalue())42 # Assignment43 elif node.getdata() == '[PROGRAM]':44 for c in node.getchildren():45 trans(c)46 elif node.getdata() == '[ASSIGNMENT]':47 for c in node.getchildren():48 trans(c)49 if len(node.getchildren()) == 3:50 value = node.getchild(2).getvalue()51 node.getchild(0).setvalue(value)52 # update v_table53 update_v_table(node.getchild(0).getdata(), value)54 else:55 value_list = node.getchild(3).getvalue()56 node.getchild(0).setvalue(value_list)57 update_v_table(node.getchild(0).getdata(), value_list)58 elif node.getdata() == '[IF]':59 r'''if : IF '(' condition ')' '{' statements '}'60 | IF '(' condition ')' '{' statements '}' ELIF '(' condition ')' '{' statements '}' ELSE '{' statements '}' '''61 if len(node.getchildren()) == 2:62 children = node.getchildren()63 trans(children[0])64 condition = children[0].getvalue()65 if condition:66 for c in children[1:]:67 trans(c)68 else:69 children = node.getchildren()70 trans(children[0])71 trans(children[2])72 c1 = children[0].getvalue()73 c2 = children[2].getvalue()74 if c1:75 trans(children[1])76 elif c2:77 trans(children[3])78 else:79 trans(children[4])80 if children[4].getchild(0).getdata() == 'break' and children[4].getchild(0).getvalue() == False:81 node.setvalue(False)82 # While83 elif node.getdata() == '[WHILE]':84 r'''while : WHILE '(' condition ')' '{' statements '}' '''85 children = node.getchildren()86 while trans(children[0]):87 trans(children[1])88 if break_flag is False:89 break90 elif node.getdata() == '[BREAK]':91 node.getchild(0).setvalue(False)92 node.setvalue(False)93 break_flag = False94 elif node.getdata() == '[RETURN]':95 node.setvalue(True)96 return_flag = True97 # print('return语句被执行了')98 # For99 elif node.getdata() == '[FOR]':100 '''for : FOR '(' operation ';' condition ';' operation ')' '{' statements '}' '''101 children = node.getchildren()102 trans(children[0])103 # v=v_table[children[0].getchild(0).getdata()]104 while trans(children[1]):105 trans(children[3])106 trans(children[2])107 # Condition108 elif node.getdata() == '[CONDITION]':109 for c in node.getchildren():110 trans(c)111 if len(node.getchildren()) == 3:112 arg0 = v_table[node.getchild(0).getdata()]113 try:114 if (type(eval(node.getchild(2).getdata())) == int) or (type(eval(node.getchild(2).getdata())) == float):115 arg1 = eval(node.getchild(2).getdata())116 except NameError:117 arg1 = v_table[node.getchild(2).getdata()]118 op = node.getchild(1).getdata()119 if op == '>':120 node.setvalue(arg0 > arg1)121 elif op == '<':122 node.setvalue(arg0 < arg1)123 elif len(node.getchildren()) == 4:124 arg0 = v_table[node.getchild(0).getdata()]125 arg1 = v_table[node.getchild(3).getdata()]126 # print(node.getchild(1).getdata())127 if node.getchild(1).getdata() == '<':128 node.setvalue(arg0 <= arg1)129 else:130 # print('比值', arg0 >= arg1)131 node.setvalue(arg0 >= arg1)132 elif len(node.getchildren()) == 6:133 arg0 = v_table[node.getchild(0).getdata()]134 num1 = int(node.getchild(2).getvalue())135 arg1 = v_table[node.getchild(5).getdata()]136 op = node.getchild(4).getdata()137 if op == '>':138 node.setvalue(arg0[num1] > arg1)139 elif op == '<':140 node.setvalue(arg0[num1] < arg1)141 elif node.getdata() == '[CONDITION_COMPLEX1]':142 for c in node.getchildren():143 trans(c)144 arg0 = v_table[node.getchild(0).getdata()]145 arg1 = v_table[node.getchild(1).getdata()]146 arg2 = v_table[node.getchild(2).getdata()]147 num1 = int(node.getchild(3).getvalue())148 arg3 = v_table[node.getchild(4).getdata()]149 node.setvalue((arg0 < arg1) and (arg2[num1] > arg3))150 elif node.getdata() == '[CONDITION_COMPLEX2]':151 for c in node.getchildren():152 trans(c)153 arg0 = v_table[node.getchild(0).getdata()]154 arg1 = v_table[node.getchild(1).getdata()]155 arg2 = v_table[node.getchild(2).getdata()]156 num1 = int(node.getchild(3).getvalue())157 arg3 = v_table[node.getchild(4).getdata()]158 node.setvalue((arg0 < arg1) and (arg2[num1] <= arg3))159 # Modification160 elif node.getdata() == '[MODIFICATION]':161 for c in node.getchildren():162 trans(c)163 if len(node.getchildren()) == 4:164 arg0 = v_table[node.getchild(0).getdata()]165 num1 = int(node.getchild(1).getvalue())166 arg1 = v_table[node.getchild(2).getdata()]167 num2 = int(node.getchild(3).getvalue())168 arg0[num1] = arg1[num2]169 update_v_table(node.getchild(0).getdata(), arg0)170 elif len(node.getchildren()) == 3:171 arg0 = v_table[node.getchild(0).getdata()]172 num1 = int(node.getchild(1).getvalue())173 value = v_table[node.getchild(2).getdata()]174 arg0[num1] = value175 update_v_table(node.getchild(0).getdata(), arg0)176 # Operation177 elif node.getdata() == '[OPERATION]':178 for c in node.getchildren():179 trans(c)180 if len(node.getchildren()) == 3:181 value = node.getchild(2).getvalue()182 node.getchild(0).setvalue(value)183 update_v_table(node.getchild(0).getdata(), value)184 elif len(node.getchildren()) == 2:185 value = v_table[node.getchild(0).getdata()]186 if node.getchild(1).getdata() == '+':187 value += 1188 # print('自加')189 else:190 value -= 1191 # print('自减')192 node.getchild(0).setvalue(value)193 update_v_table(node.getchild(0).getdata(), value)194 # print(v_table)195 elif node.getdata() == '[FACTOR]':196 for c in node.getchildren():197 trans(c)198 if len(node.getchildren()) == 3:199 arg0 = node.getchild(1).getvalue()200 node.setvalue(arg0)201 else:202 if (type(node.getchild(0).getvalue()) == float) or (type(node.getchild(0).getvalue()) == int):203 node.setvalue(node.getchild(0).getvalue())204 else:205 arg0 = v_table[node.getchild(0).getdata()]206 node.setvalue(arg0)207 update_v_table(node.getchild(0).getdata(), arg0)208 elif node.getdata() == '[TERM]':209 for c in node.getchildren():210 trans(c)211 if len(node.getchildren()) == 1:212 arg0 = node.getchild(0).getvalue()213 node.setvalue(arg0)214 else:215 arg0 = node.getchild(0).getvalue()216 arg1 = node.getchild(2).getvalue()217 op = node.getchild(1).getdata()218 if op == '*':219 value = arg0 * arg1220 elif op == '/':221 value = arg0 // arg1222 else:223 value = arg0 // arg1224 node.setvalue(value)225 elif node.getdata() == '[EXPR]':226 for c in node.getchildren():227 trans(c)228 if len(node.getchildren()) == 3:229 if node.getchild(1).getdata() == '+' or node.getchild(1).getdata() == '-':230 arg0 = node.getchild(0).getvalue()231 arg1 = node.getchild(2).getvalue()232 op = node.getchild(1).getdata()233 if op == '+':234 value = arg0 + arg1235 else:236 value = arg0 - arg1237 else:238 arg0 = node.getchild(1).getvalue()239 # len()240 value = len(arg0)241 elif len(node.getchildren()) == 1:242 value = node.getchild(0).getvalue()243 else:244 temp_l = v_table[node.getchild(0).getdata()]245 num = int(node.getchild(2).getvalue())246 value = temp_l[num]247 node.setvalue(value)248 # Print249 elif node.getdata() == '[PRINT]':250 for c in node.getchildren():251 trans(c)252 value = node.getchild(2).getvalue()253 for i in range(len(value)):254 if i != len(value) - 1:255 print(value[i], end=' , ')256 else:257 print(value[i], end='\n')258 elif node.getdata() == '[SENTENCE]':259 for c in node.getchildren():260 trans(c)261 if len(node.getchildren()) == 1:262 value = [node.getchild(0).getvalue()]263 else:264 value = [node.getchild(0).getvalue()] + node.getchild(2).getvalue()265 node.setvalue(value)266 elif node.getdata() == '[WORD]':267 for c in node.getchildren():268 trans(c)269 try:270 if (type(eval(node.getchild(0).getdata())) == int) or (type(eval(node.getchild(0).getdata())) == float):271 # print(node.getchild(0).getvalue(),end='haha\n')272 node.setvalue(node.getchild(0).getvalue())273 except Exception:274 try:275 value = v_table[node.getchild(0).getdata()]276 node.setvalue(value)277 update_v_table(node.getchild(0).getdata(), value)278 except Exception:279 v_table[node.getchild(0).getdata()] = None280 value = node.getchild(0).getdata()281 node.setvalue(value)282 elif node.getdata() == '[FUNCTION]':283 r'''function : DEF VARIABLE '(' sentence ')' '{' statements RETURN VARIABLE '}' '''284 trans(node.getchild(0))285 trans(node.getchild(1))286 fname = node.getchild(0).getdata()287 vnames = node.getchild(1).getvalue()288 f_table1[fname] = (vnames, node.getchild(2))289 elif node.getdata() == '[RUNFUNCTION]':290 for c in node.getchildren():291 trans(c)292 fname = node.getchild(0).getdata()293 vnames1 = node.getchild(1).getvalue()294 vnames0, fnode = f_table1[fname]295 # print('\n')296 for i in range(len(vnames1)):297 try:298 vname1 = vnames1[i]299 vname0 = vnames0[i]300 # print(vname1)301 x = v_table[vname1]302 v_table[vname0] = x303 # print(x)304 # print(x)305 except Exception:306 v_table[vname0] = vname1307 # print(vname1)...

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