Пример #1
0
def p_value_parameter(p):
    '''value_parameter : identifiers COLON type_identifier
                       | IDENTIFIER COLON type_identifier
                       | identifiers COLON KEYWORD_ARRAY KEYWORD_OF type_identifier
                       | IDENTIFIER COLON KEYWORD_ARRAY KEYWORD_OF type_identifier'''
    p[0] = IG.Node()
    if len(p) == 4:
        if type(p[1]) == IG.Node:
            p[0].items = p[1].items
            for item in p[1].items:
                ST.currSymTab.addVar(item, p[3].type, isParameter=True)
        else:
            p[0].items.append(p[1])
            ST.currSymTab.addVar(p[1], p[3].type, isParameter=True)
    elif len(p) == 5:
        if type(p[1]) == IG.Node:
            p[0].items = p[1].items
            for item in p[1].items:
                ST.currSymTab.addVar(item,
                                     ST.Type('array',
                                             ST.Type.ARRAY,
                                             arrayBaseType=p[5].type),
                                     isParameter=True)
        else:
            p[0].items.append(p[1])
            ST.currSymTab.addVar(p[1],
                                 ST.Type('array',
                                         ST.Type.ARRAY,
                                         arrayBaseType=p[5].type),
                                 isParameter=True)
Пример #2
0
def p_type_statement(p):
    '''type_statement : identifiers EQUAL type SEMICOLON
                      | IDENTIFIER EQUAL type SEMICOLON'''
    if type(p[1]) == IG.Node:
        for item in p[1].items:
            ST.currSymTab.addVar(
                item, ST.Type(item, ST.Type.TYPE, baseType=p[3].type))
    else:
        ST.currSymTab.addVar(p[1],
                             ST.Type(p[1], ST.Type.TYPE, baseType=p[3].type))
Пример #3
0
def p_program_statement(p):
    '''program_statement : KEYWORD_PROGRAM IDENTIFIER SEMICOLON
                         | empty'''
    if len(p) == 4:
        ST.currSymTab.addVar(p[2], ST.Type('program', ST.Type.PROGRAM))
    else:
        pass
Пример #4
0
def newTempArray():
    global tempCount
    tempVar = ST.currSymTab.addVar('.t' + str(tempCount),
                                   ST.Type('array', ST.Type.ARRAY),
                                   isTemp=True)
    tempCount += 1
    return tempVar
Пример #5
0
def newTempString():
    global tempCount
    tempVar = ST.currSymTab.addVar('.t' + str(tempCount),
                                   ST.Type('string', ST.Type.STRING),
                                   isTemp=True)
    tempCount += 1
    return tempVar
Пример #6
0
def newTempChar():
    global tempCount
    tempVar = ST.currSymTab.addVar('.t' + str(tempCount),
                                   ST.Type('char', ST.Type.CHAR),
                                   isTemp=True)
    tempCount += 1
    return tempVar
Пример #7
0
def newTempBool():
    global tempCount
    tempVar = ST.currSymTab.addVar('.t' + str(tempCount),
                                   ST.Type('boolean', ST.Type.BOOL),
                                   isTemp=True)
    tempCount += 1
    return tempVar
Пример #8
0
def newTempInt():
    global tempCount
    tempVar = ST.currSymTab.addVar('.t' + str(tempCount),
                                   ST.Type('integer', ST.Type.INT),
                                   isTemp=True)
    tempCount += 1
    return tempVar
Пример #9
0
def p_array_declaration(p):
    '''array_declaration : KEYWORD_ARRAY LEFT_SQUARE_BRACKETS array_ranges RIGHT_SQUARE_BRACKETS KEYWORD_OF type'''
    p[0] = IG.Node()
    p[0].type = ST.Type('array',
                        ST.Type.ARRAY,
                        arrayBeginList=p[3].arrayBeginList,
                        arrayEndList=p[3].arrayEndList,
                        arrayBaseType=p[6].type)
Пример #10
0
def p_unsigned_constant(p):
    '''unsigned_constant : CONSTANT_INTEGER
                         | CONSTANT_HEX
                         | CONSTANT_BINARY
                         | CONSTANT_OCTAL
                         | CONSTANT_NIL
                         | CONSTANT_BOOLEAN_TRUE
                         | CONSTANT_BOOLEAN_FALSE
                         | string'''
    p[0] = IG.Node()
    p[0].place = p[1]
    if type(p[1]) == int:
        p[0].type = ST.Type('integer', ST.Type.INT)
    elif type(p[1]) == str:
        if p[1] == 'true' or p[1] == 'false':
            p[0].type = ST.Type('boolean', ST.Type.BOOL)
        else:  # TODO Nil is string FIXME
            p[0].type = ST.Type('string', ST.Type.STRING)
Пример #11
0
def p_string_declaration(p):
    '''string_declaration : KEYWORD_STRING LEFT_SQUARE_BRACKETS CONSTANT_INTEGER RIGHT_SQUARE_BRACKETS'''
    p[0] = IG.Node()
    p[0].type = ST.Type('string', ST.Type.TYPE, strLen=p[3])
Пример #12
0
def p_type_identifier(p):
    '''type_identifier : IDENTIFIER
                       | KEYWORD_STRING'''
    p[0] = IG.Node()
    p[0].type = ST.Type(p[1], ST.Type.TYPE)