예제 #1
0
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())
예제 #2
0
def parser_test():
    text = open(FILE_EXAMPLE, 'r').read()
    lexer = Lexer(text)
    parser = Parser(lexer)
    program = parser.program('example')
    print(repr(program))
예제 #3
0
    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())