Beispiel #1
0
def p_FunMark1(p):
    ''' FunMark1 : epsilon
    '''
    #if p[-2][1] in ST.SymbolTable[ST.currScope]["function"].keys():
    #     error("Error: function with same name and same number of arguments already defined.")
    #  else:
    if (len(p[-2]) > 2):
        ST.addFunc(p[-2][1], p[-2][2:])
    else:
        ST.addFunc(p[-2][1])
    ST.setRType(p[-1])
    for l in range(2, len(p[-2])):
        ST.addParamVar(p[-2][l][0], p[-2][l][0], p[-2][l][1])
        if p[-2][l][1] is 'Array':
            ST.addAttribute(p[-2][l][0], 'typeArray', 'Int')
            ST.addAttribute(p[-2][l][0], 'isparam', True)

    printp(p)
Beispiel #2
0
import sys
import ply.yacc as yacc
import lexer
#from globalvar import *
import pickle
from globalOther import ST
#ST=SymbolTable()
#global ST
#ST.newScope()
ST.addFunc('println')
ST.endFunc()
ST.addFunc('readInt')
ST.endFunc()
#ST.endScope()
x = 1


def newLabel():
    global x
    x = x + 1
    return "label" + str(x)


def is_number(var):
    try:
        int(var)
        return True
    except Exception:
        return False