本文整理汇总了Python中parsing.parser.Parser.get_ast方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.get_ast方法的具体用法?Python Parser.get_ast怎么用?Python Parser.get_ast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parsing.parser.Parser
的用法示例。
在下文中一共展示了Parser.get_ast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import get_ast [as 别名]
def main():
"""
Main entry point into the program. Parse the command line arguments of the
form [lexicon_file grammar_file source_file].
Calls lexer to obtain a sequence L of annotated lexemes from the source file
and lexicon file. Calls parser to obtain an abstract syntax tree from L and
grammar file and print it.
"""
# read arguments
(options, args) = parse_arguments()
(lexicon_file, grammar_file, input_file) = args
# create lexer instance
lexer_instance = Lexer(lexicon_file, options.use_builtin_lexemes)
# obtain lexing sequence from the input file
lexing_sequence = lexer_instance.get_lexing_sequence_from_file(input_file)
# create parser instance
parser_instance = Parser(grammar_file, lexer_instance.lexicon_dict.keys())
# obtain abstract syntax tree from the lexing sequence
print(parser_instance.get_ast(lexing_sequence, options.ignore_spaces))