ryukinix / lisp-inference

An Inference Engine based on Propositional Calculus written in Common Lisp
https://logic.manoel.dev
BSD 3-Clause "New" or "Revised" License
40 stars 1 forks source link

Webapp doesn't handle parenthesis correctly #18

Open ryukinix opened 5 years ago

ryukinix commented 5 years ago

image

This occurs because my lexer it's just a split by whitespace. I need to fix that.

https://github.com/ryukinix/lisp-inference/blob/3a51c46ff39af6d1ab44597b5a1d81825dadf187/web/webapp.lisp#L37-L41

weslleymberg commented 5 years ago

As we talked in Telegram, I think this can be solved by enclosing the expression in parenthesis (if it's not already) and let the interpreter load it with "read-from-string". Like in the example bellow:

(defun string-parse (str)
  (if (and (str:starts-with-p "(" str)
           (str:ends-with-p ")" str))
      (read-from-string str)
      (read-from-string (str:concat "(" str ")"))))

PS.: thanks for the help with cl-str

ryukinix commented 5 years ago

Interesting! I'll test it.

ryukinix commented 5 years ago

image

This expression doesn't works because it should have wrapped parenthesis. In the expression

(and (str:starts-with-p "(" str)
     (str:ends-with-p ")" str))

Will return true, but it should not.

ryukinix commented 5 years ago

image

But the other cases works, like this one above! Thanks

weslleymberg commented 5 years ago

That's good. You're welcome. I'll keep thinking about it. Maybe we can find a solution for this corner case.

ryukinix commented 5 years ago

On reddit thread for lisp-inference I read that:

My lexer doesn't works very well for parenthesis.

Your lexer is doing too much work then. Lex the string into a list of symbols and use the shunting-yard algorithm modified to handle unary operators.

ryukinix commented 5 years ago

The author saw this issue and change his opinion to: the lexer is doing too litle.

ryukinix commented 5 years ago

We should write proper tests and maybe remove this parse-string function to webapp. I think makes more sense on lisp-inference engine? There is already a src/parser.lisp file.

ryukinix commented 5 years ago

Discussion related to lexer rewrite: #25