def generate_test(): text = open(FILE_EXAMPLE, 'r').read() lexer = Lexer(text) parser = Parser(lexer) program = parser.program('example') generator = Generator(program) print(generator.generate())
def main(): print('Calculator v0.0.1\nWelcome! Type any expression below then press ENTER to evaluate.\n' 'Press ENTER on empty input to exit.') while True: _input = input('>> ') if _input == '': break parser = Parser(_input) print(parser.parse())
def _create(self, expression): parser = Parser(Scanner().scan(expression)) self.var = self.variables.copy() var_len = len(self.var) values = [] for i in range(var_len): values.append(0) for i in range(0, int(math.pow(2, var_len))): for j in range(0, var_len): values[var_len - j - 1] = int((i // math.pow(2, j)) % 2) result = parser.parse(values) tmp = values.copy() tmp.append(result) self.table.append(tmp) self._reset_static_var()
class Scheduler(object): def __init__(self): self.url_manager = UrlManager() self.downloader = Downloader() self.parser = Parser() self.data_output = DadaOutput() def crawl(self, start_url, max_page): self.url_manager.add_new_url(start_url) while self.url_manager.has_url( ) and self.url_manager.old_url_size() < max_page: page_url = self.url_manager.get_new_url() page_html = self.downloader.down(page_url) new_urls, new_data = self.parser.parse(start_url, page_html) self.url_manager.add_new_urls(new_urls) self.data_output.store_data(new_data) self.data_output.output_html() print('第%s条数据写入' % (self.url_manager.old_url_size()))
def __init__(self): self.url_manager = UrlManager() self.downloader = Downloader() self.parser = Parser() self.data_output = DadaOutput()
def parser_test(): text = open(FILE_EXAMPLE, 'r').read() lexer = Lexer(text) parser = Parser(lexer) program = parser.program('example') print(repr(program))
import parser from lexer import Lexer from _parser import Parser from _interpreter import Interpreter from colorama import Fore, Style print('\nType "quit" to quit the program') while True: print(Fore.GREEN + ">>>" + Style.RESET_ALL, end=" ") expression = input() if "quit" in expression: break lexer = Lexer(expression) tokens = lexer.lexer() results = Parser(tokens) results = results.parse() interpreter = Interpreter(results) print("\n".join(map(str, [*interpreter.run()])))
def gen_arglist(self, fun): args = fun.arglist ret = '' for type, name in args: ret += type + ' ' + name + ',' ret = ret[:-1] return ret def generate_statement(self, call): result = '' name = call.fun if call.fun == FUN_PRINTIN: name = 'System.out.println' result += '\t\t' + name + '(' if call.args: result += '"' + call.args[0].value + '"' result += ');\n' return result if __name__ == '__main__': from _lexer import Lexer from _parser import Parser text = open('example.ding', 'r').read() lexer = Lexer(text) parser = Parser(lexer) program = parser.program('example') generator = Generator(program) print(generator.generate())
from lexer import Lexer from _parser import Parser from codegen import CodeGen fname = "example.edge" with open(fname) as f: text_input = f.read() lexer = Lexer().get_lexer() tokens = lexer.lex(text_input) codegen = CodeGen() module = codegen.module builder = codegen.builder printf = codegen.printf pg = Parser(module, builder, printf) pg.parse() parser = pg.get_parser() parser.parse(tokens).eval() codegen.create_ir() codegen.save_ir("output.ll")