about summary refs log tree commit diff stats
path: root/cparse.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'cparse.lisp')
-rw-r--r--cparse.lisp44
1 files changed, 44 insertions, 0 deletions
diff --git a/cparse.lisp b/cparse.lisp
new file mode 100644
index 0000000..5c8c6bb
--- /dev/null
+++ b/cparse.lisp
@@ -0,0 +1,44 @@
+(defpackage #:cparse
+  (:use #:common-lisp #:cutil #:clex #:cabs-syn)
+  (:export
+   #:parse))
+(in-package #:cparse)
+
+(defclass <exp-elem> () () (:metaclass <abstract-class>))
+(defclass <elem-exp> (<exp-elem>) ((exp :accessor exp)))
+(defclass <elem-bin> (<exp-elem>) ((bin-op :accessor bin-op)))
+(defclass <elem-unr> (<exp-elem>) ((unr-op :accessor unr-op)))
+(defclass <elem-lp> (<exp-elem) ())
+
+(defun unr-symb (s)
+  (cond ((string= s "!") 'not)
+	((string= s "-") 'uminus)
+	(t (error "Parse error"))))
+
+(defun bin-symb (s)
+  (cond ((string= s "+") 'plus)
+	((string= s "-") 'minus)
+	((string= s "*") 'mult)
+	((string= s "/") 'div)
+	((string= s "%") 'mod)
+	((string= s "=") 'equal)
+	((string= s "<") 'less)
+	((string= s "<=") 'lesseq)
+	((string= s ">") 'great)))
+
+(defun parse (str)
+  (let* ((cl (init-lex str))
+	 (tok (lexer cl)))
+    (cond ((instancep tok (find-class '<lint>))
+	   (make-instance (find-class '<line>) 'n n 'c (parse-cmd cl)))
+	  ((instancep tok (find-class '<lident>))
+	   (cond ((string= (ident tok) "LIST")
+		  (make-instance (find-class '<phrase-list>)))
+		 ((string= (ident tok) "RUN")
+		  (make-instance (find-class '<phrase-run>)))
+		 ((string= (ident tok) "END")
+		  (make-instance (find-class '<phrase-p-end>)))
+		 (t (error "Parse error"))))
+	  (t (error "Parse error")))))
+
+