def main(filename): lexer = FimRusLexer(FileStream(filename, encoding='utf8')) stream = CommonTokenStream(lexer) parser = FimRusParser(stream) tree = parser.program() listener = Listener() walker = ParseTreeWalker() walker.walk(listener, tree)
def compile(inputFile): input_stream = FileStream(inputFile) lexer = MusicGeneratorLexer(input_stream) stream = CommonTokenStream(lexer) parser = MusicGeneratorParser(stream) tree = parser.statements() printer = Listener() walker = ParseTreeWalker() walker.walk(printer, tree)
def main(filename): with open(filename) as f: text = f.read() text = re.sub(r'\b({})\b'.format(r'|'.join(KEYWORDS)), lambda m: m.group().lower(), text, flags=re.IGNORECASE) text = text.replace('div', '//').replace('mod', '%') lexer = PascalLexer(InputStream(text)) stream = CommonTokenStream(lexer) parser = PascalParser(stream) tree = parser.program() listener = Listener() walker = ParseTreeWalker() walker.walk(listener, tree)
class AbstractFrontend: def __init__(self): self._walker = ParseTreeWalker() def _get_tree(self, in_stream: InputStream): raise NotImplementedError() def _get_converter(self) -> AbstractTableConverter: raise NotImplementedError() def get_ir(self, in_stream: InputStream) -> Table: tree = self._get_tree(in_stream) converter = self._get_converter() self._walker.walk(converter, tree) return converter.get_result()
def parse(value): textStream = InputStream(value) astPathListener = ASTPathListener() errorListener = ErrorListener() lexer = FHIRPathLexer(textStream) lexer.recover = recover lexer.removeErrorListeners() lexer.addErrorListener(errorListener) parser = FHIRPathParser(CommonTokenStream(lexer)) parser.buildParseTrees = True parser.removeErrorListeners() parser.addErrorListener(errorListener) walker = ParseTreeWalker() walker.walk(astPathListener, parser.expression()) return astPathListener.parentStack[0]
def __parse_pattern(self, pattern) -> None: # Implement the reggie parser walker, execution of the compiler # Step 1 - Parse the thing # Step 2 - Save the structural Template # Step 3 - Save the semantic template istream = InputStream(pattern) lexer = reggieLexer(istream) stream = CommonTokenStream(lexer) parser = reggieParser(stream) syntax_errors = parser.getNumberOfSyntaxErrors() if syntax_errors > 0: raise Exception( "Could not parse the match expression, interrupting parsing flow" ) tree = parser.graph() walker = ParseTreeWalker() listener = MatchPatternGenerator() walker.walk(listener, tree) self._structural_template = listener.structural_template self._semantic_template = listener.semantic_template
def __init__(self): self._walker = ParseTreeWalker()