recursive descent parser and functional programming

后端 未结 5 552
一生所求
一生所求 2021-01-30 11:12

So lately I have been working on writing a simple compiler to better understand compiler concepts. Being a diligent reader of stackoverfolow, it seems there is a consensus that

5条回答
  •  感动是毒
    2021-01-30 11:40

    A simpler answer than the other good answers:

    A parser in a function language takes a token stream into a parse tree and the rest of the token stream. That is, it has type

     token list -> ast * token list
    

    A recursive decent parser usually have a large number of functions that of this type which eats the token stream and then builds a little part of the parse tree. By calling these recursively (recursive decent) -- you get what you want.

    The next step up is to use higher order parsers: parsers operating on other parsers. This is what parser combinator libraries do. Perhaps you could start with a simple recursion scheme and then upgrade it to parser combinators.

提交回复
热议问题