Exemple #1
0
def parse_model(lexer, model=None):
    if model is None:
        model = Model()
    while lexer.get_type() != lex.TOKEN_EOF:
        lexer.match(lex.TOKEN_OPEN)
        name = lexer.get_value()
        lexer.match(lex.TOKEN_LITERAL)
        if name == 'machine':
            model.machine = machine.parse_machine(lexer)
        elif name == 'memory':
            model.memory = memory.parse_memory_list(lexer)
        elif name == 'benchmarks':
            model.benchmarks = _parse_benchmarks(lexer)
        elif name == 'label':
            model.label = _parse_str(lexer)
        elif name == 'include':
            value = lexer.get_value()
            lexer.match(lex.TOKEN_LITERAL)
            parse_model(lex.Lexer(open(value, 'r')), model)
        else:
            lex.ParseError(lexer, 'invalid top-level component: ' + name)
        lexer.match(lex.TOKEN_CLOSE)
    return model
Exemple #2
0
 def test_parse1(self):
     s = "(target simple)(frequency 1.0)"
     s += "(addr_bits 16)(max_path 10)(max_cost 9)"
     l = lex.Lexer(mocks.MockFile(s))
     result = machine.parse_machine(l)
     self.assertEqual(str(result), s)