def update_state(self, symstring): statesymbol = Symbol.getERE(symstring) if statesymbol not in self.fsm.contents[self.currstate]: self.violated = True else: self.currstate = self.fsm.contents[self.currstate][statesymbol] self.set_state_string()
def makeERE(erlist, symbols): if type(erlist) is list: negflag = False orflag = False catflag = False andflag = False #need some initial ERE to make sure this works correctly currentERE = Empty() for ind, obj in enumerate(erlist): if obj == "*": if ind == 0: raise SyntaxError("Kleene closure must be after stuff") currentERE = Kleene.getERE(currentERE) elif obj == "~": negflag = True continue elif obj == "|": orflag = True continue elif obj == "+": catflag = True continue elif obj == "&": andflag = True continue else: if ind == 0 | negflag: currentERE = EREMachine.makeERE(obj, symbols) elif orflag: currentERE = Or.getERE( [currentERE, EREMachine.makeERE(obj, symbols)]) orflag = False elif catflag: currentERE = Concat.getERE( currentERE, EREMachine.makeERE(obj, symbols)) catflag = False elif andflag: currentERE = Negation.getERE( Concat.getERE( Negation.getERE(currentERE), Negation.getERE( EREMachine.makeERE(obj, symbols)))) andflag = False else: currentERE = Concat.getERE( currentERE, EREMachine.makeERE(obj, symbols)) if negflag: currentERE = Negation.getERE(currentERE) negflag = False return currentERE else: if erlist == 'empty': return Empty.getERE() elif erlist == 'epsilon': return Epsilon.getERE() elif erlist in symbols: return Symbol.getERE(erlist) elif not erlist: return else: raise ValueError( 'Either you have used a symbol not tied to event, or epsilon/empty is misspelled' )