[{"data":1,"prerenderedAt":335},["ShallowReactive",2],{"project-32121846":3},{"id":4,"name":5,"line":5,"line_source":6,"title":7,"url":8,"domain":9,"maker":10,"posted_at":11,"year":12,"points":13,"comments":14,"rank_in_year":15,"shown_in_year":16,"top":17,"tier":18,"category":19,"subcategory":20,"format":21,"keywords":22,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":44,"post_text":46,"what":47,"said":77,"maker_in_thread":195,"shape":205,"grid":209,"attempts":293,"same_week":298,"maker_shows":42,"maker_hidden":327,"reader_version":328,"card":329},"32121846","A compiler and VM for a simple language, in 150 lines of code","title","Show HN: A compiler and VM for a simple language, in 150 lines of code","https:\u002F\u002Fgist.github.com\u002Fp4bl0-\u002F9f4e950e6c06fbba7e168097d89b0e46","gist.github.com","p4bl0",1658004708,2022,200,45,287,2570,12,"notable","languages","toy compiler","cli",[23,24,25,26,27],"compiler","bytecode vm","ocaml","compiler course","boolean expressions","mixed",0.064,{"positive":31,"neutral":32,"mixed":33,"critical":34},4,7,2,3,16,{"idea":37,"execution":39,"performance":40,"design":41,"docs":43},{"positive":33,"critical":38},0,{"positive":38,"critical":33},{"positive":38,"critical":38},{"positive":42,"critical":38},1,{"positive":38,"critical":42},[34,38,42,38,38,38,38,38,45,38,38,42,38,38,34,38,34,38,34,34,45,38,34,38,34,34,45,45,38,38,34,38,38,38,38,42,38],5,null,{"problem":48,"audience":55,"pricing":46,"motivation":59,"time_to_build":46,"stack":63,"openness":75,"stage":76,"team_size":75},{"value":49,"source":50,"evidence":51},"Teaching the fundamental steps of building a compiler to beginner students","maker",[52],{"id":53,"by":10,"text":54},"32122288","Hey there, author here :). The language is intentionally very simple indeed, because the goal is to showcase all indispensable steps of a complete compiler. I initially wrote it…",{"value":56,"source":50,"evidence":57},"Beginner computer science students taking a compiler class",[58],{"id":53,"by":10,"text":54},{"value":60,"source":50,"evidence":61},"Introduction for the first session of the maker's compiler class",[62],{"id":53,"by":10,"text":54},[64,71],{"value":65,"source":50,"evidence":66},"OCaml",[67,70],{"id":68,"by":10,"text":69},"32123516","The native binary produced by ocamlopt is 917KB, the bytecode produced by ocamlc is 156KB. I must admit I didn't expect such \"big\" files. Out of curiosity I tested to compile a…",{"id":53,"by":10,"text":54},{"value":72,"source":50,"evidence":73},"ocamllex\u002Focamlyacc (lexer and parser generators)",[74],{"id":53,"by":10,"text":54},"unknown","launched",{"praise":78,"objections":102,"requests":141,"questions":160,"alternatives":176},[79,91],{"value":80,"source":81,"evidence":82},"Good educational tool for exploring compiler and programming language theory","commenter",[83,87],{"id":84,"by":85,"text":86},"32122279","denotational","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…",{"id":88,"by":89,"text":90},"32122603","skybrian","I 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.",{"value":92,"source":81,"evidence":93},"Looks nice and is a clever small project",[94,98],{"id":95,"by":96,"text":97},"32122216","blacklion","Sooo nice :-) It looks like small cute kitten to me, sorry.",{"id":99,"by":100,"text":101},"32127906","a-dub","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…",[103,118,124,134],{"value":104,"source":81,"evidence":105},"Language is just boolean expressions, not a real programming language",[106,110,114],{"id":107,"by":108,"text":109},"32122131","userbinator","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…",{"id":111,"by":112,"text":113},"32123325","kragen","I 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…",{"id":115,"by":116,"text":117},"32124099","scrame","k. 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\u002Fyacc is called…",{"value":119,"source":81,"evidence":120},"Line count excludes the parser generator output, which seems like cheating",[121],{"id":122,"by":108,"text":123},"32122425","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.",{"value":125,"source":81,"evidence":126},"No type checking or semantic analysis",[127,130],{"id":128,"by":100,"text":129},"32122226","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…",{"id":131,"by":132,"text":133},"32124026","compiler-guy","Type 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…",{"value":135,"source":81,"evidence":136},"Calling it a complete compiler is overselling it",[137,138],{"id":107,"by":108,"text":109},{"id":139,"by":108,"text":140},"32122409","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…",[142,146,153],{"value":143,"source":81,"evidence":144},"Support flow control so the compiler could compile itself",[145],{"id":139,"by":108,"text":140},{"value":147,"source":81,"evidence":148},"Publish the rest of the course materials",[149,150],{"id":99,"by":100,"text":101},{"id":151,"by":112,"text":152},"32132658","I'd love to!",{"value":154,"source":81,"evidence":155},"Explain binary size of the compiler",[156],{"id":157,"by":158,"text":159},"32123004","shadowofneptune","One question: what is the binary size of the compiler?",[161,165,172],{"value":162,"source":81,"evidence":163},"What is the binary size of the compiler?",[164],{"id":157,"by":158,"text":159},{"value":166,"source":81,"evidence":167},"Where can I learn about mll and mly files?",[168],{"id":169,"by":170,"text":171},"32122089","prezjordan","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.",{"value":173,"source":81,"evidence":174},"Can the compiler compile itself?",[175],{"id":139,"by":108,"text":140},[177,181,189],{"value":178,"source":81,"evidence":179},"C4 and C4x86 tiny self-compiling compilers",[180],{"id":139,"by":108,"text":140},{"value":182,"source":81,"evidence":183},"Lex and yacc, ocamllex\u002Focamlyacc, Menhir, ANTLR",[184,188],{"id":185,"by":186,"text":187},"32122242","tekknolagi","Search for ocamllex and ocamlyacc. Also Menhir.",{"id":115,"by":116,"text":117},{"value":190,"source":50,"evidence":191},"PLY and Racket parser tools",[192],{"id":193,"by":10,"text":194},"32122371","Yes, they do. Lex and yacc equivalent tools are available for many languages. Examples : - Python: https:\u002F\u002Fply.readthedocs.io\u002F (I already used it in a very small project, again…",{"comments":196,"answered":31,"key":197},9,[198,201,202],{"id":199,"text":200},"32122476","> using a parser generator and not counting its output in the line count does seem like cheating Yeah maybe I should count OCaml's standard library lines of code too. Maybe also…",{"id":53,"text":54},{"id":203,"text":204},"32122433","> Could you compile the compiler with itself, for example? That's only possible if you write the compiler in the language it compiles. By this account writing a Python compiler…",{"commenters":206,"max_depth":32,"maker_replies":196,"first_comment_mins":207,"lifespan_hours":208},22,29,27,[210,212,216,218,220,222,224,227,228,230,232,233,234,235,238,241,244,246,248,251,254,255,258,260,262,264,268,270,272,274,277,279,282,283,286,288,290],[84,38,34,211,85,38],"project\u002Fneutral\u002Fidea",[213,38,38,214,215,38],"32123851","other\u002Fneutral\u002Fnone","stepchowfun",[107,42,42,217,108,38],"project\u002Fcritical\u002Fexecution",[128,42,38,219,100,38],"commenter\u002Fneutral\u002Fexecution",[122,42,38,221,108,38],"commenter\u002Fcritical\u002Fexecution",[199,42,38,223,10,42],"commenter\u002Fcritical\u002Fnone",[225,42,38,223,226,38],"32132086","wtetzner",[131,42,38,219,132,38],[99,42,45,229,100,38],"project\u002Fpositive\u002Fidea",[231,42,38,219,226,38],"32132078",[53,42,38,211,10,42],[139,42,42,217,108,38],[203,42,38,223,10,42],[236,42,38,223,237,38],"32122444","tiagoleifert",[239,42,34,211,240,38],"32126454","jhgb",[242,42,38,214,243,38],"32129485","abecedarius",[157,42,34,245,158,38],"project\u002Fneutral\u002Fperformance",[68,42,38,247,10,42],"maker\u002Fneutral\u002Fperformance",[249,42,34,247,250,38],"32124321","l33t2328",[252,42,34,247,253,38],"32125463","chrisseaton",[88,33,45,229,89,38],[256,33,38,257,10,42],"32122646","maker\u002Fneutral\u002Fidea",[111,33,34,259,112,38],"project\u002Fmixed\u002Fidea",[261,33,38,257,10,42],"32123419",[263,33,34,259,112,38],"32124048",[265,33,34,266,267,38],"32126688","maker\u002Fneutral\u002Fnone","supportlocal4h",[151,33,45,269,112,38],"maker\u002Fpositive\u002Fnone",[95,34,45,271,96,38],"project\u002Fpositive\u002Fdesign",[273,34,38,266,10,42],"32122733",[275,34,38,214,276,38],"32125342","mdp2021",[169,31,34,278,170,38],"project\u002Fneutral\u002Fnone",[280,31,38,281,100,38],"32122124","other\u002Fneutral\u002Fdocs",[185,31,38,281,186,38],[284,31,38,214,285,38],"32122304","mftb",[193,31,38,287,10,42],"maker\u002Fneutral\u002Fdocs",[115,45,42,289,116,38],"project\u002Fcritical\u002Fdocs",[291,45,38,292,10,42],"32125393","commenter\u002Fneutral\u002Fnone",[294,297],{"id":295,"t":296,"points":32,"comments":38},"28278407",1629736432,{"id":4,"t":11,"points":13,"comments":14},[299,304,309,313,318,323],{"id":300,"name":301,"points":302,"category":303},"32096801","pledge.com",571,"dev_tools",{"id":305,"name":306,"points":307,"category":308},"32095592","Unblah",451,"productivity",{"id":310,"name":311,"points":312,"category":303},"32106126","tere",378,{"id":314,"name":315,"points":316,"category":317},"32149989","Flowful",299,"creative",{"id":319,"name":320,"points":321,"category":322},"32167704","This Food Does Not Exist",248,"ai",{"id":324,"name":325,"points":326,"category":308},"32152600","algorithm",214,false,"v2",{"id":330,"name":5,"line":5,"ai":327,"cat":19,"year":12,"points":13,"comments":14,"rec":28,"s":331,"top":17,"kw":332,"maker":10,"domain":9,"tier":18,"attempts":33,"strip":333,"url":8,"mix":334,"praise":80,"objection":104,"sub":20},32121846,0.06,[23,24,25,26,27],"3010000050010030303350303355003000010",[31,32,33,34],1793991048937]