Search code examples
schemelispracketformal-languages

Writing a formal language parser with Lisp


My company is designing a new domain specific scripting language; I have to implement a parser that translates our brand new programming language into a common scripting language so as to be able to enact it.

The usual way I do this is by means of Bison and Flex tools that generate the C/C++ code of the translator.

I found other tools, for most of the mainstream programming languages, but none for Lisp.

Hasn't Lisp ever been used for that? What is the usual way to write a parser with Lisp?

Note: to me, any Lisp implementation / dialect that could help is ok, I do not have any preference.


Solution

  • To cover the Racket part of it:

    People often write parsers and there are many ways to do so:

    • Write a recursive descent parser manually.
    • Use the parser-tools library in Racket, which is lex/yacc style.
    • Use Ragg, an AST generator generator letting you write BNF.
    • Use Parsack, a monadic parser combinator library similar to Haskell's Parsec.
    • I'm probably overlooking at least a half-dozen other options (e.g. I know there's at least one PEG style lib for Racket).