Lisp Program to Recognize Comments in C++ Code Shane Zentz
; Shane Zentz
; C-311
; homework # 10
; Ex.1.a-> A regular grammer to recoginse multi-line comments in C++...
; Rules:
; S => / T
; T => * R
; R => (character other than / or *) R
; R => * U
; U => (character other than /) R
; U => /
; see hw10.jpg for drawing of finite state machine.......
; Ex.1.b. -> see hw10.jpg for the table..................
;;;; Ex.2 ->
;; Simulation of a regular expression grammer....
; Rules of the grammer
; S => a T
; T => b VW
; VW => b, a T
; VW => simple character other than a or b
(setq L '(a b) N '(S T VW))
(S T VW)
(setq rules '((S . (a T)) (T . (b VW)) (VW . (b T)) (VW . (a T)) (VW . nil)))
((S a T) (T b VW) (VW b T) (VW a T) (VW))
(defun check-S (Lst)
(if (equal (car Lst) 'a)
(check-T (cdr Lst)) nil))
check-S
(defun check-T (Lst)
(if (equal (car Lst) 'b)
(or (check-T (cdr Lst))
(check-VW (cdr Lst)))nil))
check-T
(defun check-VW (Lst)
(and (or (equal (car Lst) ('a )) (equal (car Lst)('b)))
(not (cdr Lst))))
check-VW
(check-S '(ab))
nil
(check-S '(bab))
nil
(check-S '(abb))
nil
(check-S '(abbababat))
nil