示例#1
0
def p_formaldehyde(p):
    'formaldehyde : ID COLON type'
    # rule.append(32)
    p[0] = TREE.Formal(code=[])
    current_symbol_table[0].enter(name=p[1],
                                  datatype=p[3].place,
                                  size=4,
                                  isArray=False)
    if p[3].place in ClassDict or p[3].place in ['Int', 'String']:
        pass
        # print ClassDict[p[3].place].scope_name
    else:
        sys.exit('No object found named ' + p[3].place)
示例#2
0
def p_formal_arr(p):
    'formal : ID COLON type LSQRBRACKET expression RSQRBRACKET'
    rule.append(33)

    p[0] = TREE.Formal(code=[])
    if p[3].place in ClassDict or p[3].place in ['Int', 'String']:
        pass
        # print ClassDict[p[3].place].scope_name
    else:
        sys.exit('No object found named ' + p[3].place)
    current_symbol_table[0].enter(name=p[1],
                                  datatype='Array',
                                  size=4 * int(p[5].place),
                                  isArray=False)
示例#3
0
def p_formaldehyde_arr_many(p):
    'formaldehyde : formaldehyde COMMA ID COLON type LSQRBRACKET expression RSQRBRACKET'
    # rule.append(33)

    p[0] = TREE.Formal(code=[])
    if p[5].place in ClassDict or p[5].place in ['Int', 'String']:
        pass
        # print ClassDict[p[3].place].scope_name
    else:
        sys.exit('No object found named ' + p[3].place)

    current_symbol_table[0].enter(name=p[3],
                                  datatype='Array',
                                  size=4000,
                                  isArray=True)
示例#4
0
def p_formal_with_assign(p):
    'formal : ID COLON type GETS expression'
    rule.append(31)

    code = ['ASSIGN,%s,%s' % (p[1], p[5].place)]
    p[0] = TREE.Formal(code=code)

    if p[3].place in ClassDict or p[3].place in ['Int', 'String']:
        pass
        # print ClassDict[p[3].place].scope_name
    else:
        sys.exit('No object found named ' + p[3].place)

    current_symbol_table[0].enter(name=p[1],
                                  datatype=p[3].place,
                                  size=4,
                                  isArray=False)