A compiler and VM for a simple language, in 150 lines of code
Languages and libraries
toy compiler
SHOW HN2022
A compiler and VM for a simple language, in 150 lines of code
A compiler and VM for a simple language, in 150 lines of code
gist.github.com#compiler#bytecode vm#ocaml#compiler course#boolean expressions
How HN took it
4 positive, 7 neutral or asking, 2 mixed, 3 critical, out of 16 comments about the project. Thread score +0.06.
Idea: 2 for, 0 againstExecution: 0 for, 2 againstDesign: 1 for, 0 againstDocs: 0 for, 1 against
The thread, comment by comment
Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.
positive neutral or mixed critical about another commenter or something else the maker
What HN said
What people liked
Good educational tool for exploring compiler and programming language theory
From 2 comments
As another comment also alludes, there's probably quite a lot more work required before this could be called a complete compiler (without heavy qualification as to what it…
denotational on HNI think people are getting hung up on the word "complete." This is a complete compiler in the sense that "hello world" is a complete (but minimal) program.
skybrian on HN
Looks nice and is a clever small project
From 2 comments
Sooo nice :-) It looks like small cute kitten to me, sorry.
blacklion on HNfair enough. regardless i think it's a work of art and meets the definition of compiler in my mind. i hope that the author chooses to publish the rest of their course materials…
a-dub on HN
Objections
Language is just boolean expressions, not a real programming language
From 3 comments
For those wondering what language this is for before clicking on it: it's not much more than what I think would traditionally be called an expression evaluator, and very simple…
userbinator on HNI want to preface this comment with the fact that I'm terrible at teaching and know nothing about it, so it's entirely possible that your example compiler is much better for…
kragen on HNk. so this is an OCaml parser for a toy language? I mean, cool, but... I don't know OCaml and this doesn't do a lot to sell the language over AntLR or whatever lex/yacc is called…
scrame on HN
Line count excludes the parser generator output, which seems like cheating
From 1 comment
B has no type checking either. On the other hand, using a parser generator and not counting its output in the line count does seem like cheating.
userbinator on HN
No type checking or semantic analysis
From 2 comments
there's no type checking, which i'd say is a fairly integral part of a compiler... but it does use a parser generator to generate a parser that constructs an ast and it then…
a-dub on HNType checking is a part of semantic analysis, which the author explicitly says isn’t present. Even so, the language it is compiling has only one type, so it isn’t possible for a…
compiler-guy on HN
Calling it a complete compiler is overselling it
From 2 comments
For those wondering what language this is for before clicking on it: it's not much more than what I think would traditionally be called an expression evaluator, and very simple…
userbinator on HNThe only way it is not complete — and that's written in the README — is that it has absolutely no semantics analysis I was referring to the complete lack of flow control. Could…
userbinator on HN
Requests
Support flow control so the compiler could compile itself
From 1 comment
The only way it is not complete — and that's written in the README — is that it has absolutely no semantics analysis I was referring to the complete lack of flow control. Could…
userbinator on HN
Publish the rest of the course materials
From 2 comments
fair enough. regardless i think it's a work of art and meets the definition of compiler in my mind. i hope that the author chooses to publish the rest of their course materials…
a-dub on HNI'd love to!
kragen on HN
Explain binary size of the compiler
From 1 comment
One question: what is the binary size of the compiler?
shadowofneptune on HN
Questions
What is the binary size of the compiler?
From 1 comment
One question: what is the binary size of the compiler?
shadowofneptune on HN
Where can I learn about mll and mly files?
From 1 comment
Where can I learn more about mll and mly files? I've hand-rolled parsers and it's always my least favorite part of toy languages.
prezjordan on HN
Can the compiler compile itself?
From 1 comment
The only way it is not complete — and that's written in the README — is that it has absolutely no semantics analysis I was referring to the complete lack of flow control. Could…
userbinator on HN
Alternatives named
C4 and C4x86 tiny self-compiling compilers
From 1 comment
The only way it is not complete — and that's written in the README — is that it has absolutely no semantics analysis I was referring to the complete lack of flow control. Could…
userbinator on HN
Lex and yacc, ocamllex/ocamlyacc, Menhir, ANTLR
From 2 comments
Search for ocamllex and ocamlyacc. Also Menhir.
tekknolagi on HNk. so this is an OCaml parser for a toy language? I mean, cool, but... I don't know OCaml and this doesn't do a lot to sell the language over AntLR or whatever lex/yacc is called…
scrame on HN
PLY and Racket parser tools
From 1 comment
Yes, they do. Lex and yacc equivalent tools are available for many languages. Examples : - Python: https://ply.readthedocs.io/ (I already used it in a very small project, again…
p4bl0 on HN