4 ms·
Put that flex & bison book away. Don't think about compilers. Design your own litte interpreted language. Write a lexer by hand (not that hard). Write a recursi
by laxd 8y ago
Put that flex & bison book away. Don't think about compilers. Design your own litte interpreted language. Write a lexer by hand (not that hard). Write a recursive descent parser by hand. It's a bit tricky to get infix operator parsing stuff right, but an important learning experience. Once you got the basic parsing algorithm right you can probably add lot's of fun stuff to your language just with general programming skills. When you feel ready to move on. Read the flex & bison book, and explore more advanced topics knowing you don't need to write lexers and parsers by hand again.
- StillBored 8y agoThere is a really simple algorithm to convert infix to prefix or postfix. The pre/postfix is then interpreted/compiled easily. This was one of the first things my comp-sci teacher in HS made us do after teaching linked list/stacks/fifos. Of course if you pick a language like forth (mentioned below) the whole problem is sort of moot.
- cgag 8y agoThe first couple chapters of crafting interpreters (free) cover lexing and parsing and precedence well and it's very readable and practical rather than theoretical.
- bootsz 8y ago+1. This is the approach I'm currently taking. I tried starting with books and tutorials but felt I wasn't learning much just being spoon-fed code and copy+pasting. I think it's much more illuminating to attack the problem with a beginner's mindset and work it out for yourself, at least up to a point (to start I'm working on implementing a small subset of Scheme). If I occasionally get stuck I'll peek at a book just enough to get un-stuck. I'm having a blast with it and learning a ton. Once I get tired of implementing language features I'll probably start from scratch and follow a book the second time through. For me it's often easier to absorb problem-solving concepts if I've attempted the problem myself before.