What is the best lexing algorithm for a macro preprocessor?

I came upon Pratt lexers recently, which could enable more dynamicity in my language. That lead me to think that I should also rework the lexer. For now, I use a flex/bison generated grammar, with pieces of the preprocessor in both .l and .y files. I think it would be better to have a separate preproccessor, a hand-rolled lexer and a Pratt parser. Is there an algorithm that would best suit the preprocessing task?

Posted Aug 21, 2019, 9:57 PM UTC

33
RobertJacobson•

I personally would do it the way you are doing it. C style preprocessors are bad. Macro systems are good. Whatever you are including as preprocessing, my advice is to make it a part of the language rather than some distinct and bolted on to the front of the compiler.

6
fennecdjayOP•

Thanks for your advice. I'll investigate TDOP with it in mind.

1
WikiTextBot•

Pratt parser

In computer science, a Pratt parser is an improved recursive descent parser that associates semantics with tokens instead of grammar rules. It was first described by Vaughan Pratt in the 1973 paper "Top down operator precedence", and was treated in much more depth in a Masters Thesis under his supervision. Pratt designed the parser originally to implement the CGOL programming language. Douglas Crockford used the technique to build JSLint.


^[ ^PM ^| ^Exclude ^me ^| ^Exclude ^from ^subreddit ^| ^FAQ ^/ ^Information ^| ^Source ^] ^Downvote ^to ^remove ^| ^v0.28

1