def p_foreach_loop(p): '''loop : FOR LPAREN letVar SYMBOL OF expression RPAREN statement | FOR LPAREN SYMBOL OF expression RPAREN statement | FOR LPAREN expression RPAREN statement ''' if len(p) > 8: p[0] = node.ForEach(p[6], p[8], key=p[4]) elif len(p) > 7: p[0] = node.ForEach(p[5], p[7], key=p[3]) else: p[0] = node.ForEach(p[3], p[5])
def p_for_loop(p): '''statement : FOR LPAREN assign testExpression STOP assign RPAREN statement ''' initAssign = p[3] testExpression = p[4] statementBlock = node.Block(node.If(node.Not(testExpression), node.Break())) statementBlock.statements.append(p[8]) statementBlock.statements.append(p[6]) p[0] = node.Block(initAssign) p[0].statements.append( node.Assign( '_loop', node.List(node.Range(initAssign.value, testExpression.args[1])))) p[0].statements.append(node.ForEach(node.Variable('_loop'), statementBlock))
def p_loop_item1(p): 'loop : sFOREACH aCOLLECTION expression aITEM SYMBOL xEND statements cFOREACH' p[0] = node.ForEach(p[3], p[7], key=p[5])
def p_loop_noitem(p): 'loop : sFOREACH aCOLLECTION expression xEND statements cFOREACH' p[0] = node.ForEach(p[3], p[5])