3 ms·
>term rewriting In uni we had to make a spreadsheet software. I volunteered to do the formula parser, thinking it sounded like a fun challenge. I was stumped
by andai 7mo ago
>term rewriting
In uni we had to make a spreadsheet software.
I volunteered to do the formula parser, thinking it sounded like a fun challenge.
I was stumped for a week, until I realized I could rewrite the formulas into a form I knew how to parse. So it would rewrite 1+1 into ADD(1,1) and so on.
I also refused to learn regex, so the parsing code was "interesting" ;)
I recall a comment from a colleague. "Okay, Andy says it works. Don't touch it." XD
Guy from another group used regex and his solution was 20x shorter than mine.
- gf000 7mo agoRegular expressions are probably not enough for parsing formulas (depending of course on the exact task given), they usually are at least a context free language.
- codebje 7mo agoRegular expressions are definitely enough for turning characters into tokens, after which a simple recursive descent parser is vastly more straightforward to write. Lexing is optional, but generally advised.