# Path: pif_ir/bir/utils/exceptions.py
# class BIRParsingError(BIRError):
#     """ something went wrong while parsing an instruction or control state
#     """
#     def __init__(self, msg):
#         super(BIRParsingError, self).__init__()
#         self.value = msg


from ply import lex
from ply.lex import TOKEN
from ply import yacc
from pif_ir.bir.utils.exceptions import BIRParsingError

    def t_error(self, t):
        print "Illegal BIR character '{0}'".format(t.value[0])
        t.lexer.skip(1)

class BIRParser(object):
    def __init__(self):
        self.lexer = BIRLexer()
        self.tokens = self.lexer.tokens
        self.inst_parser = yacc.yacc(module=self, write_tables=0, 
                                     debug=False, start='arith_exp',
                                    errorlog=yacc.NullLogger())
        self.cond_parser = yacc.yacc(module=self, write_tables=0, 
                                     debug=False, start='bool_exp')

    def eval_inst(self, expression, header, packet, bit_offset=0):
        self.header = header
        self.packet = packet
        self.bit_offset = bit_offset
        self.exp = str(expression)
        return self.inst_parser.parse(self.exp, lexer=self.lexer)

    def eval_cond(self, expression, header, packet, bit_offset=0):
        self.header = header
        self.packet = packet
        self.bit_offset = bit_offset
        self.exp = str(expression)
        return self.cond_parser.parse(self.exp, lexer=self.lexer)

    precedence = (

# Path: pif_ir/bir/utils/exceptions.py
# class BIRParsingError(BIRError):
#     """ something went wrong while parsing an instruction or control state
#     """
#     def __init__(self, msg):
#         super(BIRParsingError, self).__init__()
#         self.value = msg


# Path: pif_ir/bir/utils/bir_parser.py
from ply import lex
from ply.lex import TOKEN
from ply import yacc
from pif_ir.bir.utils.exceptions import BIRParsingError


    def t_error(self, t):
        print "Illegal BIR character '{0}'".format(t.value[0])
        t.lexer.skip(1)

class BIRParser(object):
    def __init__(self):
        self.lexer = BIRLexer()
        self.tokens = self.lexer.tokens
        self.inst_parser = yacc.yacc(module=self, write_tables=0, 
                                     debug=False, start='arith_exp',
                                    errorlog=yacc.NullLogger())
        self.cond_parser = yacc.yacc(module=self, write_tables=0, 
                                     debug=False, start='bool_exp')

    def eval_inst(self, expression, header, packet, bit_offset=0):
        self.header = header
        self.packet = packet
        self.bit_offset = bit_offset
        self.exp = str(expression)
        return self.inst_parser.parse(self.exp, lexer=self.lexer)

    def eval_cond(self, expression, header, packet, bit_offset=0):
        self.header = header
        self.packet = packet
        self.bit_offset = bit_offset
        self.exp = str(expression)
        return self.cond_parser.parse(self.exp, lexer=self.lexer)

    precedence = (

        ('left', 'LOR'),