Beispiel #1
0
    def test_file_source(self):
        from lexer.source_read import TextSource
        textSource = TextSource(
            '../test_files/test_parser_simple_function.txt')

        parser = Parser(64, 256, textSource)

        program = parser.parse()

        program_repr = program.__repr__()

        expected_repr = "Program:\nFunction:\nName:pow\nType:TokenType.K_VOID\nParameters:\nParameter:\nName:x\nType" \
                        ":TokenType.K_DOUBLE\nRefer:True\nInstructions:\nAssign:\nLeft assign " \
                        "operand:\nVariable:\nx\nRight assign operand:\nMul:\nLeft mul operand:\nVariable:\nx\nRight " \
                        "mul operand:\nVariable:\nx"

        self.assertEqual(program_repr, expected_repr)
    def test_init_operation(self):
        textSource = TextSource(TEST_SOURCE_1_LINE)

        parser = Parser(64, 256, textSource)

        tree = parser.parse()

        visitor = Visitor(tree)

        program = Interpreter(visitor, lib)

        program.interpret()

        printable = f'Returned {program.return_val}.'

        print(printable)

        self.assertEqual(printable, 'Returned 1296.')
 def setUp(self) -> None:
     self.parser = Parser(64, 256, TextSource(TEST_SOURCE_1_LINE))
Beispiel #4
0
# Parses runtime arguments, like type of file input and file path
# (if text input is selected to be a file) and runs appropiate
# Lexer text input handlers to run the process of tokenization.

from argparse import ArgumentParser

from my_parser.parser import Parser
from objbrowser import browse

from lexer.source_read import TextSource

if __name__ == '__main__':
    arg_parser = ArgumentParser()

    arg_parser.add_argument('--file_path',
                            type=str,
                            default='../test_files/test_interpreter_code.txt')
    arg_parser.add_argument('--ident_length', type=int, default=64)
    arg_parser.add_argument('--string_length', type=int, default=256)

    args = arg_parser.parse_args()

    textSource = TextSource(args.file_path)

    parser = Parser(args.ident_length, args.string_length, textSource)

    program = parser.parse()

    browse(program)
#! python 3
import csv

from evaluator import Evaluator
from my_parser.parser import Parser

text = open('botify_rules.txt', encoding='utf-8').read()
p = Parser(text)
ast = p.parse()
ev = Evaluator(ast)

with open('urls_croisierenet.csv', encoding='utf-8') as f:
    f_csv = csv.reader(f)
    for line in f_csv:
        ev.evaluate_url(line[0])