lisp-inference icon indicating copy to clipboard operation
lisp-inference copied to clipboard

Refactor string parser and lexer: mainly for webapp usage

Open ryukinix opened this issue 5 years ago • 5 comments

  • It should tokenize tokens first based on operations, supporting concatenated (without whitespaces) exps like this: p^q.
  • It should use a LL(1) parser
  • It should supports parenthesis without any problem
  • It should fail early instead of trying be clever.

Example:

In: "p^q=>r" 
Out: (=> (^ p q) r)

ryukinix avatar Mar 04 '19 18:03 ryukinix

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

leonardohn avatar Mar 04 '19 21:03 leonardohn

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

ryukinix avatar Mar 04 '19 21:03 ryukinix

The parsing table it is:

image

ryukinix avatar Mar 04 '19 21:03 ryukinix

image

Runtime parsing steps.

ryukinix avatar Mar 04 '19 21:03 ryukinix

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

ryukinix avatar Mar 05 '19 00:03 ryukinix