TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ohm – A library and language for building parsers, interpreters, compilers, etc.

348 pointsby testing_1_2_3_4about 4 years ago

20 comments

gklittabout 4 years ago
Ohm’s key selling point for me is the visual editor environment, which shows how the parser is executing on various sample inputs as you modify the grammar. It makes writing parsers fun rather than tedious. One of the best applications of “live programming” I’ve seen.<p><a href="https:&#x2F;&#x2F;ohmlang.github.io&#x2F;editor&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ohmlang.github.io&#x2F;editor&#x2F;</a>
评论 #26606269 未加载
评论 #26610001 未加载
joshmarinacciabout 4 years ago
I&#x27;m so happy to see this on HN. I&#x27;ve used Ohm for several projects. If you want a tutorial for building a simple programming language using Ohm, check out this series I put on GitHub.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;joshmarinacci&#x2F;meowlang" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;joshmarinacci&#x2F;meowlang</a>
tovejabout 4 years ago
Compiler compilers are great, I love writing DSLs for my projects. I usually use yacc&#x2F;lex, or write my own compiler (typically in go these days).<p>However (and this is just me talking), I don&#x27;t see the point in a javascript-based compiler. Surely any file format&#x2F;DSL&#x2F;programming language you write will be parsed server-side?
评论 #26604134 未加载
评论 #26604692 未加载
评论 #26605569 未加载
评论 #26603978 未加载
评论 #26605628 未加载
评论 #26604017 未加载
评论 #26604294 未加载
评论 #26606109 未加载
评论 #26604032 未加载
评论 #26606274 未加载
评论 #26604008 未加载
j0e1about 4 years ago
This is an example of a library we built using Ohm: <a href="https:&#x2F;&#x2F;github.com&#x2F;Bridgeconn&#x2F;usfm-grammar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Bridgeconn&#x2F;usfm-grammar</a> [1]<p>It works great for our use-case though I have been eyeing tree-sitter[2] for its ability to do partial parses.<p>[1] USFM: <a href="https:&#x2F;&#x2F;ubsicap.github.io&#x2F;usfm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ubsicap.github.io&#x2F;usfm&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;</a>
corysamaabout 4 years ago
This is a follow-up to a major component of the <a href="http:&#x2F;&#x2F;vpri.org&#x2F;writings.php" rel="nofollow">http:&#x2F;&#x2F;vpri.org&#x2F;writings.php</a> project that created an self-contained office suite, OS and compiler suite in something like 100-200k lines of code without external dependencies.
评论 #26614631 未加载
评论 #26604813 未加载
PaulHouleabout 4 years ago
Each PEG generator promises a revolution but only burns a car.<p>I was disappointed with how they do operator precedence; they use the usual trick to make a PEG do operator precedence which looks cool when you apply it to two levels of precedence but if tried to implement C or Python in it it gets unwieldy. Most of your AST winds up being nodes that exist just to force precedence in your grammar, working with the AST is a mess.<p>For all the horrors of the Bell C compilers, having an explicit numeric precedence for operators was a feature in yacc that newer parser gens often don&#x27;t have.<p>I worked out the math and it is totally possible to add a stage that adds the nodes to a PEG to make numeric precedence work and also delete the fake nodes from the parsed AST. Unparsing I&#x27;m not so sure of, since if someone wrote<p><pre><code> int a = (b + c); </code></pre> how badly you want to keep the parens is up to you; a system like that MUST have an unparse-parse identity in terms of &#x27;value of the expression&#x27;, but for sw eng automation you want to keep the text of the source code as stable as you can.
crazypythonabout 4 years ago
This title is misleading. It&#x27;s a library and language for building parsers. Full stop. Parsing toolkit, as they say themselves.
评论 #26605399 未加载
hardwaregeekabout 4 years ago
I&#x27;ve used PEGs in the past. They&#x27;re nice since they combine the mental model of LL grammars with the automation of LALR parser generators. However, it is quite easy to accidentally write rules where you never parse the second rule due to the ordering priority for rules. For instance:<p><pre><code> ident ::= name | name (&quot;.&quot; name)+ </code></pre> Because with PEGs, the parser tries the first rule, then the second, and because whenever the second rule matches, the first one will also match, we will never parse the second rule. That&#x27;s kinda annoying.<p>Of course with PEG tools you could probably solve this by computing the first sets for both rules and noticing that they&#x27;re the same. Hopefully that&#x27;s what this tool does.
评论 #26605283 未加载
fjfaaseabout 4 years ago
I recently wrote a similar parser, maybe less fancy, for a workshop on parsing. It does display the the abstract syntax tree with d3.js and also has a build evaluator for a limited set of language constructs. <a href="https:&#x2F;&#x2F;fransfaase.github.io&#x2F;ParserWorkshop&#x2F;Online_inter_parser.html" rel="nofollow">https:&#x2F;&#x2F;fransfaase.github.io&#x2F;ParserWorkshop&#x2F;Online_inter_par...</a> It is based on a parser I implemented in C++.
jweissmanabout 4 years ago
I’ve built a number of toy language projects with Ohm and it’s really wonderful. Just a joy to use the visual tooling also. All around really beautiful machinery
recursivedoubtsabout 4 years ago
Always fun to find the first commit:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;harc&#x2F;ohm&#x2F;commit&#x2F;4611bf63c5ecb90d782112d68f73a2277f87ca7d" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;harc&#x2F;ohm&#x2F;commit&#x2F;4611bf63c5ecb90d782112d68...</a><p>2014<p>Neat tool. I write parsers by hand though. More fun, and you can be a lot sleazier.
brannemanabout 4 years ago
When should one use Ohm over Racket?
评论 #26605680 未加载
scrootabout 4 years ago
We are using Ohmjs on a project at work and it is fantastic. I&#x27;m hoping one day that Ohmjs and Ohm&#x2F;s (Squeak) can be compatible again -- would love to have the Smalltalk version of our interpreter and environment we built using this
tobrabout 4 years ago
Speaking of - what’s the status of HARC? Is it defunct?
评论 #26604109 未加载
评论 #26603923 未加载
pjmlpabout 4 years ago
Love it, this is great for teaching purposes.
codr7about 4 years ago
I recently created a library for the other part of an interpreter.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;liblg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;liblg</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;liblgpp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;liblgpp</a>
TheRealPomaxabout 4 years ago
It&#x27;d be cool if the online editor dispensed with the need to &quot;write the grammar&quot; entirely. A node based parser-generator in addition to Ohm being yet another grammar based parser-generator would be pretty great.
评论 #26604012 未加载
f430about 4 years ago
If I want to modify GraphQL to support custom syntax, would Ohm work? Or does a solution exist already for my needs?
dw-im-hereabout 4 years ago
I&#x27;d rather put my hand in boiling water than develop a compiler in a dynamic weak typed language.
评论 #26629538 未加载
评论 #26606115 未加载
评论 #26606049 未加载
评论 #26612345 未加载
评论 #26605611 未加载
rkagererabout 4 years ago
OHM is also the acronym for Open Hardware Monitor, a great open-source project for monitoring computer temperatures, fan speeds, voltages, etc: <a href="https:&#x2F;&#x2F;openhardwaremonitor.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;openhardwaremonitor.org&#x2F;</a>