示例#1
0
def test_semantic_analysis(input_string):
    errors = ErrorReport()
    asmlexer = asmutil.create_lexer(errors)
    asmparser = asmutil.create_parser(errors, debug=True)

    ast = asmparser.parse(input_string, lexer=asmlexer)
    asmsemantic.analyse(ast, asmparser.const_table, asmparser.data_table, asmparser.inst_table, errors)

    return (ast, asmparser.const_table, asmparser.data_table, asmparser.inst_table)
示例#2
0
def test_parser(input_string):
    errors = ErrorReport()
    asmlexer = asmutil.create_lexer(errors)
    asmparser = asmutil.create_parser(errors, debug=True)

    ast = asmparser.parse(input_string, lexer=asmlexer)

    errors.report_errors()
    return ast, asmparser
示例#3
0
def test_lexer(input_string):
    errors = ErrorReport()
    asmlexer = asmutil.create_lexer(errors)
    asmlexer.input(input_string)

    result = []
    while True:
        token = asmlexer.token()
        if not token: break
        result = result + [(token.type, token.value)]

    errors.report_errors()
    return result