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

Refactor string parser and lexer: mainly for webapp usage #25

Open ryukinix opened 5 years ago

ryukinix commented 5 years ago

Example:

In: "p^q=>r" 
Out: (=> (^ p q) r)
leonardohn commented 5 years ago

Well, you could use an LL(1) parser to read the expression precedence and give you a polish notation expression. Try using this website to test this grammar:


D' -> v C D'
D' -> ''
C -> I C'
C' -> ^ I C'
C' -> ''
I -> E I'
I' -> => E I'
I' -> ''
E -> N E'
E' -> <=> N E'
E' -> ''
N -> ~ A
N -> A
A -> ( P )
A -> id
ryukinix commented 5 years ago

Thank you for this contribution! A formal parser will be really useful!

ryukinix commented 5 years ago

The parsing table it is:

image

ryukinix commented 5 years ago

image

Runtime parsing steps.

ryukinix commented 5 years ago

Maybe can be useful: https://github.com/vy/meta-sexp