示例#1
0
        add_asm('%s_START:' %inst_id)
        traverse_instruction(block)

        cmp_op = traverse_condition(pred)
        add_asm('%s %s_END' %(op_to_cmd[cmp_op], inst_id))
        add_asm('jmp %s_START' %inst_id)
        add_asm('%s_END:' %inst_id)

    leave_block()

def traverse_condition(pred):
    cmp_op, e1, e2 = pred
    traverse_expression(e1)
    traverse_expression(e2)
    add_cmp_asm('cmpq')
    return cmp_op

if __name__ == '__main__':
    parser = cparse.parser
    s = remove_blank(remove_comment(sys.stdin.read()))
    asts = parser.parse(s)

    enter_block('global')
    map(traverse_ast, asts)
    if_call_cat()
    if_exist_string()
    add_str_literal_asm()
    leave_block()

    print '\n'.join(instructions)
示例#2
0
def p_argument_expression_list_2(t):
    '''argument_expression_list : argument_expression_list COMMA expression'''
    t[0] = t[1] + [t[3]]

# constant:
def p_constant(t): 
   '''constant : ICONST'''
   t[0] = 'ICONST',t[1]

def p_constant_1(t):
    '''constant : FCONST'''
    t[0] = 'FCONST',t[1]

def p_error(t):
    if t:
         print("Syntax error at token", t)
         # Just discard the token and tell the parser it's okay.
         parser.errok()
    else:
         print("Syntax error at EOF")



parser = yacc.yacc(method='LALR')

if __name__ == '__main__':
    s = sys.stdin.read()
    s = remove_blank(remove_comment(s))
    print s
    pp.pprint(parser.parse(s))
示例#3
0
    '''constant : ICONST'''
    t[0] = 'ICONST', t[1]


def p_constant_1(t):
    '''constant : FCONST'''
    t[0] = 'FCONST', t[1]


# def p_empty(t):
#     'empty : '
#     t[0] = None


def p_error(t):
    # print "Whoa, We're hosed"
    if t:
        print("Syntax error at token", t[0])
        # Just discard the token and tell the parser it's okay.
        parser.errok()
    else:
        print("Syntax error at EOF")


parser = yacc.yacc(method='LALR')

if __name__ == '__main__':
    s = sys.stdin.read()
    s = remove_blank(remove_comment(s))
    pp.pprint(parser.parse(s))