cc icon indicating copy to clipboard operation
cc copied to clipboard

Refactor lexer

Open andrewchambers opened this issue 9 years ago • 3 comments

I feel like the lexer could be simplified by dumbing the code down a bit then using a regex to validate floats and numbers.

andrewchambers avatar Mar 20 '15 04:03 andrewchambers

Hey!

I just skimmed the lexer code; it doesn't look too complicated. There is a talk by Rob Pike about writing lexers in Go, which details how the lexer for text/template is implemented. Maybe that proves useful.

dhamidi avatar Mar 20 '15 08:03 dhamidi

Thanks, I'll check out the code there. It's probably pretty good to compare a few techniques for implementing this.

Compared with https://github.com/rui314/8cc/blob/master/lex.c , The state machines in the number/float/string lexing take up a bunch of space, even if it is fairly simple.

andrewchambers avatar Mar 20 '15 08:03 andrewchambers

I think the performance of the lexer is fairly critical, currently i think most of the time is spent allocating new objects. I want to emphasize clean code over performance for now though.

andrewchambers avatar Mar 20 '15 08:03 andrewchambers