4 ms·
I didn't take this course. I have taken compiler classes. Short answer, yes. Longer answer, compilers of any sort are hard, because there's both a lot of spec
by jfoutz 9y ago
I didn't take this course. I have taken compiler classes.
Short answer, yes.
Longer answer, compilers of any sort are hard, because there's both a lot of special cases and also pressure to be algorithmically efficient.
Writing any kind of compiler is going to force you to do stuff with the parse tree. It's up to you to decide if
float a = 1
is an error or not. doing things like constant value evaluation
int a = 1 + 2 + 3
=>
int a = 6
will get you a feel for all the different ways you can transform the parse tree. It's going to feel frustrating, because it's not the language you want to work on. But building up the skills to shuffle ast nodes is really really helpful.
Making your own language is hard. if your goal is a working language, i'd suggest building an interpreter first, so you can really nail down the semantics. at the end of that you're going to have a call that looks like eval(ast, context). you can do a simple compiler by just reimplementing eval, rather than doing the work, spit out the code that would do the work.
also, if you have an adequate interpreter, you can you can write your compiler in your own language.