示例#1
0
def main():
    a_parser = argparse.ArgumentParser(
        description='Compile noggin language to SPIM assembly'
    )
    args = a_parser.parse_args()

    myLexer = lexer_code.Lexer

    lexedTokens = []
    newToken = myLexer.lex()
    while newToken is not None:
        if printVerbose:
            print("Lexed new token: " + str(newToken))
        lexedTokens.append(newToken)
        newToken = myLexer.lex()
    if printVerbose:
        print("Reached end of tokens")
        for t in lexedTokens:
            print(t.get_info())

    Parser.set_tokens(lexedTokens)

    try:
        p = Program.parse()
        if printVerbose:
            print(p.info_str())
            print(p)
    except ParserException as e:
        print(e)
示例#2
0
def test_parse_prog():
    emptyProg = []
    Parser.set_tokens(emptyProg)
    pe = Program.parse()

    prog1 = [
        FunctionToken(),
        IdentToken("hello"),
        LeftParenToken(),
        RightParenToken(),
        LeftBraceToken(),
        RightBraceToken()
        ]
    Parser.set_tokens(prog1)
    p1 = Program.parse()