def setUp(self): with open('tests/input/file', 'w') as file: file.write("program{int x;};") self.s: Scanner = Scanner('tests/input/file') tokens: list = self.s.scan_file() self.p: Parser = Parser(tokens)
def __init__(self): self.lexer = Lexer() self.parser = Parser() self.typechecker = Typechecker()
def __init__(self): self.lexer_instance = Lexer() self.parser_instance = Parser()
import unittest from rply import Token from compiler.parser.parser import Parser import compiler.parser.ast as ast parser = Parser() class TestExpr(unittest.TestCase): def test_add(self): '''Can parse a simple addition: `1 + 1;`''' given = iter([ Token('INTEGER', '1'), Token('PLUS', '+'), Token('INTEGER', '1'), Token('SEMI', ';') ]) expected = ast.Block([ ast.Statement(ast.BinOp('+', ast.Integer(1), ast.Integer(1))) ]) result = parser.parse(given) assert expected == result def test_op_order(self): '''Enforces the right op. precedence: `1 + 5 * 20;`''' given = iter([
from compiler.scanner.scanner import Scanner from compiler.parser.parser import Parser DEBUG_TEST_FILE = "compiler/samples/sample_2" args_len: int = len(sys.argv) if args_len >= 2: s = Scanner(sys.argv[1]) else: s = Scanner(DEBUG_TEST_FILE) token_sequence: list = s.scan_file() print("----------\nScanner\n----------") if args_len >= 3: s.log(sys.argv[2]) else: s.log() print("----------\nParser\n----------") p: Parser = Parser(token_sequence) result: bool = p.parse() if args_len >= 3: p.log_results(sys.argv[2]) print('----------\n'+str(result)) else: p.log_results() print('----------\nResult: ' + str(result))