From 8128f72264ef96862f0622d6ce1a15606884f2e9 Mon Sep 17 00:00:00 2001 From: cfreksen Date: Sun, 29 Oct 2017 13:58:59 +0100 Subject: [PATCH] Update method names for parser and add 2 docstrings. --- parser.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/parser.py b/parser.py index b255b04..342c97a 100644 --- a/parser.py +++ b/parser.py @@ -466,12 +466,25 @@ class LLVMParser(object): self.tokens += self.reserved.values() def build(self, **kwargs): + """ + Build the parser. + + This method builds the parsing tables and initializes the + internal lexer and parser variables. This method must be + called prior to parsing. + + """ self.lexer = lex.lex(module=self, **kwargs) self.parser = yacc.yacc(module=self, **kwargs) - def test(self, data): - result = self.parser.parse(data, lexer=self.lexer) - print(result) + def parse(self, text): + """ + Generate AST from text. + + Return a AST representation of the llvm program from text. + + """ + return self.parser.parse(text, lexer=self.lexer) if __name__ == '__main__': @@ -483,4 +496,4 @@ define void @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) { ret i64 %a } ''' - p.test(data) + print(p.parse(data))