Esempio n. 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())
Esempio n. 2
0
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())
Esempio n. 3
0
    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()
 def __init__(self):
     self.url_manager = UrlManager()
     self.downloader = Downloader()
     self.parser = Parser()
     self.data_output = DadaOutput()
Esempio n. 5
0
def parser_test():
    text = open(FILE_EXAMPLE, 'r').read()
    lexer = Lexer(text)
    parser = Parser(lexer)
    program = parser.program('example')
    print(repr(program))
Esempio n. 6
0
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()])))
 
Esempio n. 7
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())
Esempio n. 8
0
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")