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 parser_test(): text = open(FILE_EXAMPLE, 'r').read() lexer = Lexer(text) parser = Parser(lexer) program = parser.program('example') print(repr(program))
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())