Honest question: why do tutorials in this topic seem to always use functional languages/syntax as examples? Our compilers class at MST had us re-implement a lisp compiler, but didn't touch on why we used lisp specifically (other than the professor liking it; we were a largely C++ school). Do they think functional languages are simpler / less complex / easier to understand? Is there something inherently easier to impl…
Writing Your Own Programming Language
51–60 of 95 posts
Re: Writing Your Own Programming Language
#52Earlier quoted context omitted.
Why is it so often stated, that Scheme doesn't need a parser? I mean the AST is simpler then in other languages, but at the end of the day, you have to parse SEXPs, don't you? I mean let's say you evaluate > (+ 2 3) You have to parse the string "(+ 2 3)" and will then evaluate it to 5?
... reading sexp's is technically parsing but it is so far removed from something like a C parser that it's really not the same animal. I mean, you can write a function to build a list from a sexp in a few minutes, while even a basic hand-written C parser will take days/weeks/months depending on your familiarity. So, that's a reason why it is said. (edit: also, if the course implements scheme IN scheme, then you don'…
Yeah it is obviously a lot easier to parse than traditional, imperative languages like C. I just do not like the phrase, as it gives this "magic" vibe to Scheme. I mean its syntax is beautiful and simple, but there is definitely no magic there.
Re: Writing Your Own Programming Language
#53Honest question: why do tutorials in this topic seem to always use functional languages/syntax as examples? Our compilers class at MST had us re-implement a lisp compiler, but didn't touch on why we used lisp specifically (other than the professor liking it; we were a largely C++ school). Do they think functional languages are simpler / less complex / easier to understand? Is there something inherently easier to impl…
x := y + z
or f(y + z)
or g(f(x, y))
you'd need to be able to evaluate expressions first. Maybe it's just simpler to illustrate a smaller language first?Re: Writing Your Own Programming Language
#54Are there any resources on the code generation side of things? Even getting from a high level language down to SSA seems like a big leap (nevermind going from SSA to assembly).
Re: Writing Your Own Programming Language
#55Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.
Re: Writing Your Own Programming Language
#56Earlier quoted context omitted.
I hesitated on using BNF. It seemed overkill Presumably because there's no real nesting of terms in assembly code? Personally, I find BNF so simple that I'd probably still use it for describing the grammar, but lots of parser generator technology is heavier machinery than required (though a recursive descent parser built from a regular grammar is essentially a DFA if your language/compiler offers tail call eliminatio…
Is regular grammar same as context-free grammar?
Re: Writing Your Own Programming Language
#57Earlier quoted context omitted.
I'm writing an assembler for a virtual 16 bit CPU I built, and I hesitated on using BNF. It seemed overkill so I ended up hand-rolling a parser; for an assembler it's straightforward enough, but I can easily see how it could get ridiculous to implement a compiler this way.
Is your codebase public? I would like to take a look.
Keep in mind it's a personal project, the assembler is written in not the prettiest idiosyncratic Python.
Re: Writing Your Own Programming Language
#58Jeremy Ashkenas created CoffeeScript after reading that book. I can't recommend it enough for someone going down this road.
Re: Writing Your Own Programming Language
#59Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.