On Sat, Mar 09, 2019 at 06:59:38PM +0000, sylvain.bertr...@gmail.com wrote: > Hi, > > I am coding a little/simple custom language parser, and I was wondering if > there > are "suckless" grade alternatives to flex and bison, anyone? But wait... > > That said and as of today, I still don't agree with myself on the usefullness > of lex/yacc in the first place. For instance, I am puzzled by line/column > tracking, which can be tricky (for instance C preprocessor/compiler accurate > line/column tracking with line-return escaping with lex/yacc??) > > Maybe it's not an implementation issue of lex and yacc... they may actually > be _not_ suckless at all. Any thoughts on this? > > -- > Sylvain >
Well, other people have made that point before: Why use a regex to identify a token when a simple loop will do? So for lexing, usually a simple token parser in C will do the job better. And for parsing, you get the problem that yacc will create an LALR parser, which is a bottom-up parser. Which may be faster but doesn't allow for good error messages on faulty input ("error: expected this, that, or the other token before this one"). That's why top-down recursive-descent parsers (or LL(1) parsers) are superior. Maybe supplemented with a shunting-yard algorithm to get the binary expressions right without having to call layer after layer of functions. Ciao, Markus