about summary refs log tree commit diff stats
path: root/parsing.lsp
diff options
context:
space:
mode:
authorDarren Bane <darren.bane@gmail.com>2020-11-19 23:50:27 +0000
committerDarren Bane <darren.bane@gmail.com>2020-11-19 23:50:27 +0000
commit8b8ca0515fe6f68b774f766f7e4f49ec26ba6590 (patch)
tree56a5c98a61169b9af67fb9ae530c23a845125149 /parsing.lsp
parent6e7cdcd4280f5330229ec9c943b9caf090846452 (diff)
downloadlsp-8b8ca0515fe6f68b774f766f7e4f49ec26ba6590.tar.gz
Try fix loading error
Diffstat (limited to 'parsing.lsp')
-rw-r--r--parsing.lsp43
1 files changed, 43 insertions, 0 deletions
diff --git a/parsing.lsp b/parsing.lsp
new file mode 100644
index 0000000..e79451a
--- /dev/null
+++ b/parsing.lsp
@@ -0,0 +1,43 @@
+(defpackage #:parsing
+  (:use #:openlisp #:lex #:abs-syn)
+  (:export
+   #:parse))
+(in-package #:parsing)
+
+(defclass <exp-elem> () () (:abstractp t))
+(defclass <elem-exp> (<exp-elem>) ((expr :accessor expr)))
+(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 (class <lint>))
+	   (create (class <line>) 'n n 'c (parse-cmd cl)))
+	  ((instancep tok (class <lident>))
+	   (cond ((string= (ident tok) "LIST")
+		  (create (class <phrase-list>)))
+		 ((string= (ident tok) "RUN")
+		  (create (class <phrase-run>)))
+		 ((string= (ident tok) "END")
+		  (create (class <phrase-p-end>)))
+		 (t (error "Parse error"))))
+	  (t (error "Parse error")))))
+(provide "parse")