Ejemplo n.º 1
0
def convertRange(token, line, t,v,i,understood, variables):
    iOrig = i
    i += 1
    if v!= 'range':
        print 'error'
        return
    t,v,_,_,_ = token[i]
    number1 = ''
    number2 = ''
    number3 = ''
    maxCount = 0
    if t == tokenize.OP and v == '(':
        maxCount = 1
        i += 1
        number1, i, understood,variables =  getFunctionExpression(token, number1,t,v,i,understood,variables, '')
        if token[i-1][1] == ',':
            maxCount = 2
            number2, i, understood,variables =  getFunctionExpression(token, number2,t,v,i,understood,variables, '')
        if token[i-1][1] == ',':
            maxCount = 3
            number3, i, understood,variables =  getFunctionExpression(token, number3,t,v,i,understood,variables, '')
    if maxCount == 1:
        line += '(0 .. '+ number1 + '+ 1 ) '
        i -= 1
    elif maxCount == 2:
        line += '(' + number1 + '.. ' + number2 + '- 1 )'
        i -= 1
    else:
        understood = False
        i = iOrig
    return line,i,understood,variables
Ejemplo n.º 2
0
def convertSys(token, line, t,v,i,understood, variables, oldIdent):
    if token[i+1][0] == tokenize.OP   and token[i+1][1] == '.'      and \
       token[i+2][0] == tokenize.NAME and token[i+2][1] == 'stdout' and\
       token[i+3][0] == tokenize.OP   and token[i+3][1] == '.'      and\
       token[i+4][0] == tokenize.NAME and token[i+4][1] == 'write'  and \
       token[i+5][0] == tokenize.OP   and token[i+5][1] == '(':
        toWrite = ''
        i+= 6
        toWrite, i, understood,variables = getFunctionExpression(token, toWrite,t,v,i,understood,variables, oldIdent)
        line += 'print( '+toWrite + ')'
        i -= 1
    elif token[i+1][0] == tokenize.OP   and token[i+1][1] == '.'      and\
         token[i+2][0] == tokenize.NAME and token[i+2][1] == 'stdin'    and\
         token[i+3][0] == tokenize.OP   and token[i+3][1] == '.'        and\
         token[i+4][0] == tokenize.NAME and token[i+4][1] == 'readline' and\
         token[i+5][0] == tokenize.OP   and token[i+5][1] == '('        and\
         token[i+6][0] == tokenize.OP   and token[i+6][1] == ')':
        line += '<STDIN>'
        i += 6
    elif token[i+1][0] == tokenize.OP   and token[i+1][1] == '.'        and\
         token[i+2][0] == tokenize.NAME and token[i+2][1] == 'stdin'    and\
         token[i+3][0] == tokenize.OP   and token[i+3][1] == '.'        and\
         token[i+4][0] == tokenize.NAME and token[i+4][1] == 'readlines' and\
         token[i+5][0] == tokenize.OP   and token[i+5][1] == '('        and\
         token[i+6][0] == tokenize.OP   and token[i+6][1] == ')':
        line += '<STDIN>'
        i += 6
    elif token[i-1][0] == tokenize.NAME and token[i-1][1] == 'import':
        line += ''
    return line,i,understood,variables