Update method names for parser and add 2 docstrings.

This commit is contained in:
cfreksen 2017-10-29 13:58:59 +01:00
parent abebb940f6
commit 8128f72264
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

View File

@ -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))