English 中文(简体)
LISP - 将制图学投入改为方言(语言理论)
原标题:LISP - converting grammar inputs to strings (language theory)

我已实施了一个问题,确定格拉玛(Vn;Vt;P;S)的无生产性或无法进入的元素,其中Vn——一套变量;Vt-一套终端和P——生产规则,以及S——开始符号。

; Defining a grammar
(defvar *VN*  (A B C D S)) ; non-terminal variables
(defvar *VT*  (k m n)) ; terminal
(defvar *P*  ((S A B) ; set of production rules
    (S C D)
    (S A k)
    (A k)
    (B m)
    (B D m D)
    (C n)
    )
)

;;; FINDING PRODUCTIVE ELEMENTS
(defun PROD-STEP (VT P PRODS)
    ;(format t "P = ~S~%" P)
    ;(format t "PRODS = ~S~%" PRODS)
    (if (null P) PRODS
        (if (subsetp (rest (first P)) (union VT PRODS))
            (PROD-STEP VT (rest P) (union (cons (first (first P)) nil) PRODS))
            (PROD-STEP VT (rest P) PRODS)
        )
    )
)
(defun PROD-AUX (VT P PRODS oldLength)
    (if (= (length PRODS) oldLength)
        PRODS
        (PROD-AUX VT P (PROD-STEP VT P PRODS) (length PRODS))
    )
)

(defun PROD (VT P)
    (PROD-AUX VT P nil -1)
)
;;; END OF FINDING PROD ELEMENTS

(trace PROD-STEP)
(trace PROD-AUX)
(trace PROD)
(PROD *VT* *P*)


;;; FINDING ACCESSIBLE ELEMENTS
(defun ACCESS-STEP (P ACC)
    ;(format t "Pacc = ~S~%" P)
    ;(format t "ACC = ~S~%" ACC)
    (if (null P) ACC
        (if (member (first (first P)) ACC)
            (ACCESS-STEP (rest P) (union (rest (first P)) ACC))
            (ACCESS-STEP (rest P) ACC)
        )
    )
)

(defun ACCESS-AUX (P ACC oldLength)
    (if (= (length ACC) oldLength)
        ACC
        (ACCESS-AUX P (ACCESS-STEP P ACC) (length ACC))
    )
)
(defun ACCESS (P S)
    ;(format t "Paccess = ~S~%" P)
    (ACCESS-AUX P (cons S nil) 0)
)
 ;;; END OF FINDING ACCESSIBLE ELEMENTS

(trace ACCESS-STEP)
(trace ACCESS-AUX)
(trace ACCESS)
(ACCESS *P*  S)

;;; REMOVING INACCESSIBLE AND NOT PRODUCTIVE ELEMENTS
(defun BuildRules-AUX (VT ACCS PRODS P newP)
    ;(format t "newP = ~S~%" newP)
    (if (null P) newP
        ; VN  = (ACCESS(G) INTERSECT PROD(G))
        ; VT  = (VT INTERSECT ACCESS(G))
        ; DACA REGULA ESTE A->X, A = (first (first P)) SI X = (rest (first P))
        ; VERIFICAM DACA A APARTINE VN  SI X APARTINE (VT  UNION VN )
        (if (and (member (first (first P)) (intersection PRODS ACCS)) (subsetp (rest (first P)) (union (intersection ACCS PRODS) (intersection VT ACCS)) ))
            (BuildRules-AUX VT ACCS PRODS (rest P) (union newP (cons (first P) nil)))
            (BuildRules-AUX VT ACCS PRODS (rest P) newP)
        )
    )   
)

(defun BuildRules (VT ACCS PRODS P)
    (BuildRules-AUX VT ACCS PRODS P nil)
)
(trace BuildRules-AUX)
(trace BuildRules)

(BuildRules *VT* (ACCESS *P*  S) (PROD *VT* *P*)*P*)

(defun SIMPL-AUX (VN VT P S ACCS PRODS)
    (setq ACCS (ACCESS P S))
    (setq PRODS (PROD VT P))
    (if (and (null (set-difference (union VN VT) ACCS)) (null (set-difference VN PRODS)))
        (cons VN (cons VT (cons P S)))
        (SIMPL-AUX 
                    (intersection ACCS PRODS)
                    (intersection VT ACCS)
                    (BuildRules VT ACCS PRODS P)
                    S
                    ACCS
                    PRODS
        )
    )
)
(defun SIMPL (VN VT P S)
    (SIMPL-AUX *VN* *VT* *P*  S nil nil)
)
;;; END OF REMOVING INACCESSIBLE AND NOT PRODUCTIVE ELEMENTS

;;; GETTING THE RESULTS
  (SIMPL *VN* *VT* *P*  S)

该方案是按预期运作的,唯一的问题就是要问,如何将投入数据转换成图象,以便区分“a”终端和“A”非终点。

我建议使用“a”、“k”、“*”、“begin”等投入。

事先感谢你......

最佳回答

您可以使用符号:<> > 仍为一纸空文,保留其编号。

|m| and M are both symbols. Different symbols.

问题回答

暂无回答




相关问题
Lisp code called from Java

Long story: I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition. I was looking over frameworks/libraries/ways of ...

Emacs, Zen-Coding mode, and Putty

I use emacs via Putty and since Putty doesn t send certain key combinations to the remote console I generally need to re-bind them to other key combinations. After installing the amazing Zen-Coding ...

In Which Cases Is Better To Use Clojure? [closed]

I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks

lambda-gtk negative pointer

I was trying to write my own put-pixel on (Gdk) pixbuf in Lisp. When I finally realized how I can operate on C pointers in CL, new obstacle came along - (gdk:pixbuf-get-pixels pb) returns me negative ...

Is there a common lisp package naming convention?

I have created some of my own user packages and have run into a name clash. In Java, the naming convention is to use your domain name in the package name: e.g. import com.example.somepackage;. Are ...

SOAP request from within an AutoLISP/AutoCAD macro

We have built a webservice for a client that uses AutoCAD. They have a macro that runs in AutoCAD that builds a SOAP request. But they have not figured out how to actually send() the soap request to ...

热门标签