TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Join the Compiler Creation Club

93 点作者 skiskilo超过 11 年前

10 条评论

cjh_超过 11 年前
I have been writing a scheme interpreter in c, and for me the most interesting aspect so far has been the level at which I am programming.<p>At the beginning it was very traditional c; symbol and AST manipulation were a PITA (at that point it was a malloc&#x27;d arrays of `expressions`). After I had a base language working I started to use the language I had implemented so far to further the implementation, this finally peaked where this weekend I did a large refactor to remove most of my c arrays and instead replace them with scheme pairs and lists.<p>For example, here [1] I implement define function form in terms of lambda, specifically new_lambda(env, cons(args, cons(body, null))).<p>In hindsight this seems so obvious, but I have found the whole process extremely interesting, specifically looking at how the implemented languages starts to influence the implementation language.<p>I really cannot stress enough how enjoyable the process of writing my interpreter has been, I thoroughly recommend it to anyone who is interesting in programming languages.<p>[1] <a href="https://github.com/mkfifo/plot/commit/07272bd69e51979ab71fa08f6415978f46a3b4ee#diff-e2f93fafd9051a63d4bd310620ebd261R105" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mkfifo&#x2F;plot&#x2F;commit&#x2F;07272bd69e51979ab71fa0...</a>
pjmlp超过 11 年前
Advice to anyone jumping into writing compilers, just pick a functional language, specially ML family.<p>Symbolic manipulation of data structures is plain joy, compared to what is required in C or Pascal family of languages.
评论 #6795494 未加载
评论 #6795770 未加载
评论 #6800401 未加载
评论 #6796999 未加载
评论 #6798605 未加载
chrisdotcode超过 11 年前
Most &quot;tutorials&quot; I&#x27;ve seen as of late (including this one) seem to walk through creating the grammar, and then just hand wave the actual creation of the AST (and the rest of the steps) to &quot;yacc magic&quot; or some other friends.<p>I would not call that building a compiler.<p>Are there any modern tutorials&#x2F;references of hand-generating the grammar, hand-coding the parser, and hand-coding whatever comes next (because I have no idea, thanks to these new-age tutorials) - without a toolchain, so that the entire process can be seen from start to finish?
评论 #6796371 未加载
评论 #6798754 未加载
评论 #6798081 未加载
评论 #6800432 未加载
评论 #6797732 未加载
评论 #6798654 未加载
评论 #6796644 未加载
computer超过 11 年前
For an advanced version: The C++ Grandmaster Certification MOOC where participants build their own complete C++11 compiler in C++11 is still going strong: <a href="http://cppgm.org/" rel="nofollow">http:&#x2F;&#x2F;cppgm.org&#x2F;</a>
评论 #6795370 未加载
评论 #6795312 未加载
lennel超过 11 年前
Nitpicking certainly but I would say use something like antlr rather than peg.js<p>antlr &quot;schemas&quot; are extremely close to ebnf&#x27;s (some exceptions obviously) and the compiler creation club could benefit from that. Antlr 3 is usable in a variaty of languages (although 4 is a hellavalot simpler and solves a fair bit around left recursive grammers, but non jvm support is non existent still I suspect)
cocoflunchy超过 11 年前
I started writing my own compile-to-JS language a while back after reading this book: <a href="http://createyourproglang.com/" rel="nofollow">http:&#x2F;&#x2F;createyourproglang.com&#x2F;</a> and I&#x27;m loving it!<p>However I&#x27;m having a bit of trouble right now with my grammar, I&#x27;m using Jison (<a href="http://jison.org" rel="nofollow">http:&#x2F;&#x2F;jison.org</a>) and the error messages are kind of confusing (I didn&#x27;t even know they were error messages at first, I thought they were some kind of logging). I apparently have shift-reduce conflicts just about everywhere, but I didn&#x27;t bother solving them as I was building the rest of the language since everything is working fine! (well I&#x27;m sure there are edge cases that I haven&#x27;t ran into yet)<p>So if anyone here has a good link on the basics of parsing, grammars, LR(1) and whatnot, I&#x27;d like to understand what I&#x27;m doing ;)
评论 #6800216 未加载
chewxy超过 11 年前
Ugh, Hacker News you are better than this. THIS was posted yesterday: <a href="http://news.ycombinator.com/item?id=6792225" rel="nofollow">http:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6792225</a>.<p>It links to the original source. Why are we not giving the original author credit, instead of linking to blog spam on tech.pro?
评论 #6797609 未加载
caissy超过 11 年前
I am currently following a compiler class, and I must say that I am really amazed and impressed. For an assignment, we of course had to write an interpreter for our own mini language. The fealing you have after creating this interpreter was overwhelming.<p>For the lexer and parser, we used SableCC, an object oriented framework that generates a compiler in Java. I&#x27;ve never used anything else (yacc, lex, etc), so I can&#x27;t compare the tool, but it provides a rich, useful and easy interface to use.
评论 #6795581 未加载
评论 #6796964 未加载
j_baker超过 11 年前
Nit: Not all languages have a separation between statements and expressions. Most lisps just have expressions.
评论 #6795808 未加载
评论 #6798594 未加载
edtechdev超过 11 年前
You can also learn a lot by studying (and even contributing to) other open source compilers. Here are about 100 javascript-based compilers, including tools for compiler writers at the bottom: <a href="https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jashkenas&#x2F;coffee-script&#x2F;wiki&#x2F;List-of-lang...</a>