'!=': 9,
    '+': 10,
    '-': 10,
    '*': 11,
    '/': 11,
    'UMINUS': 15,
    'POSITIVE': 15
}

assosiation = {  # 结合律
    # '+':'L',
    # '-':'L',
    # '*':'L',
    # '/':'L',
    # 'UMINUS':'R'
}
precs = {'UMINUS': ['E', '-', 'E'], 'POSITIVE': ['E', '+', 'E']}

terminal = ['+', '-', '*', 'id', 'num', '/'
            ]  #,'UMINUS','POSITIVE','>','>=','<','<=','!=','==','||','!','&&']
nonterminal = ['E']

parser = Parser(productions, terminal, nonterminal, precs, precedence,
                assosiation)
# parser.generate(printInfo=True)
parser.generate()
parser.dumpjson('lrtables.json')
parser.htmlparse('testspeed.html')
print(calls)
# tokens = ['-','id','+','id','*','id']
# parser.parse(tokens)
Beispiel #2
0
    '-': 10,
    '*': 11,
    '/': 11,
    'UMINUS': 15
}

assosiation = {  # 结合律
    '+': 'L',
    '-': 'L',
    '*': 'L',
    '/': 'L',
    'UMINUS': 'R',
    '!': 'R'
}
precs = {
    'UMINUS': ['Expression', '-', 'Expression'],
}

parser = Parser(productions, terminal, nonterminal, precs, precedence,
                assosiation)
# parser.generate(printInfo=True)
parser.generate(printInfo=False)
tokens = ['id', '>', 'id']
parser.checkerror()
# parser.parse(tokens)
'''
function hello()
    if 
'''
parser.htmlparse()
print(calls)
    '||':7,
    '&&':7,
    '!':8,
    '>=':9,
    '>':9,
    '<':9,
    '<=':9,
    '==':9,
    '!=':9,
    '+':10,
    '-':10,
    '*':11,
    '/':11,
    'UMINUS':15,
    'POSITIVE':15
}

assosiation = {# 结合律
    # '+':'L',
    # '-':'L',
    # '*':'L',
    # '/':'L',
    # 'UMINUS':'R'
}
precs = {
    'UMINUS':['E','-','E'],
    'POSITIVE':['E','+','E']
}
parser = Parser(productions, terminal, nonterminal, precs, precedence, assosiation)
parser.generate()
print(calls)
Beispiel #4
0
    # '/':11,
    # 'UMINUS':15
}

assosiation = {  # 结合律
    # '+':'L',
    # '-':'L',
    # '*':'L',
    # '/':'L',
    # 'UMINUS':'R'
}
precs = {
    # 'UMINUS':['E','-','E']
}

parser = Parser(productions, terminal, nonterminal, precs, precedence,
                assosiation)
parser.generate(printInfo=True)
parser.checkerror()
# tokens = ['id','=','id','>','id',';','id','=','id','>','id']
# tokens = ['if','(','id','>','id',')','id','=','id',';']
tokens = [
    'if', 'id', '>', 'id', 'id', '=', 'id', ';', 'else', 'id', '=', 'id', ';'
]
# tokens= ['id','=','id',';']
tokens = [
    'while', 'id', '>', 'id', 'id', '=', 'id', ';', 'if', 'id', '>', 'id',
    'id', '=', 'id', ';', 'else', 'id', '=', 'id', ';'
]
tokens = [
    'function', 'id', '(', ')', 'while', 'id', '>', 'id', 'id', '=', 'id', ';',
    'if', 'id', '>', 'id', 'id', '=', 'id', ';', 'else', 'id', '=', 'id', ';'
    '==': 9,
    '!=': 9,
    '+': 10,
    '-': 10,
    '*': 11,
    '/': 11,
    'UMINUS': 15,
    'POSITIVE': 15
}

assosiation = {  # 结合律
    # '+':'L',
    # '-':'L',
    # '*':'L',
    # '/':'L',
    # 'UMINUS':'R'
}
precs = {'UMINUS': ['E', '-', 'E'], 'POSITIVE': ['E', '+', 'E']}

terminal = [
    '+', '-', '*', '/', 'UMINUS', 'POSITIVE', '>', '>=', '<', '<=', '!=', '==',
    '||', '!', '&&', 'id', 'num'
]
nonterminal = ['E']

parser = Parser(productions, terminal, nonterminal, precs, precedence,
                assosiation)
parser.generate(printInfo=True)
parser.dumpjson('lrtables.json')
tokens = ['-', 'id', '+', 'id', '*', 'id']
parser.parse(tokens)