⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 an_dfa.lisp

📁 this code define the deterministic finite automata using genetic programming
💻 LISP
字号:
(defconstant +dfa1+'((ALPHABET       (man tall the))  (STATES         (1 2 3 4))  (INITIAL-STATE  1)  (FINAL-STATES   (3))  (TRANSITIONS    ((1 man 4) (1 tall 4) (1 the 2)		   (2 man 3) (2 tall 2) (2 the 4)		   (3 man 4) (3 tall 4) (3 the 4)		   (4 man 4) (4 tall 4) (4 the 4)))))(defun finalp (state dfa)  "Returns non-null value if state is among the final states of the dfa."  (member state (second (assoc 'FINAL-STATES dfa))))(defun transition (current-state symbol dfa)  "Returns the state you get to when you take a transition on symbol   starting from current-state in the dfa.  Because this is a DETERMINISTIC   finite-state automaton, it is guaranteed that there is exactly one such   value for every pairing of current-state and symbol, i.e. the find-if   will never return nil.  "  (let ((all-transitions (second (assoc 'TRANSITIONS dfa))))    (third (find-if #'(lambda (triple)  			(and (equal (first triple)  current-state)			     (equal (second triple) symbol)))		    all-transitions))))(defun accepts (input dfa)  "Input is a list of symbols from the alphabet of the automaton.   This function returns true if the dfa winds up in a final    state after going through the entire input, nil otherwise.   "  (let ((initial-state (second (assoc 'INITIAL-STATE dfa))))    (and (accepts-from-current input initial-state dfa) t)))   (defun okprint(input dfa)     (if (accepts input  dfa)          (format t  "~%~D is Accept" input)         (format t "~%~D is NotAccept" input)))(defun accepts-from-current (input current-state dfa)  "If input has been exhausted, return true if current state is a final state.   Otherwise, take the transition from current-state based on the first    symbol in the input, and see whether the automaton accepts the    new input (which is one symbol shorter) starting from the state    you end up in.  "	(if (null input)(finalp current-state dfa)         (accepts-from-current (rest input)			       (transition current-state (first input) dfa)			       dfa)))(okprint '(the tall man)  +dfa1+)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -