2 ms·
And here's the lexer for a Python-ish language I'm working on: http://github.com/nostrademons/eve-language/blob/master/bootstrap_compiler/Lexer.x http://github
by nostrademons 17y ago
And here's the lexer for a Python-ish language I'm working on:
http://github.com/nostrademons/eve-language/blob/master/bootstrap_compiler/Lexer.x http://github.com/nostrademons/eve-language/blob/master/boot...
That's 52 lines of rules. 68 lines of boilerplate code that was copied verbatim out of the Alex manual and changed a bit to work in a different monad. About 70 lines of code to add the indent/dedent/newline tokens for whitespace sensitivity. Note that that's with whitespace rules that are more permissive than just about any language out there (you can break lines without a continuation character between any pair of matched delimiters, as well as before or after any infix operator).
Yes, hand-writing a lexer is easy. Writing one with a lexer generator is even easier (and would be easier still if Alex had an easier API to work with).