問題描述
我見過一些 javascript 解析器生成器:
I've seen some javascript parser generators:
吉森 (http://zaach.github.com/jison/)
PEG.js (http://pegjs.majda.cz/)
ANTLR (http://www.antlr.org/)
JS/CC (http://jscc.jmksf.com/)
有人有經驗嗎?
有什么好處和壞處?這些庫準備好投入生產了嗎?和性能?
What are the pros and cons? Are these libraries ready for production? And performance?
編輯:
我想在 javascript 中解析和運行不同的語言
EDIT:
I want to parse and run a different language in javascript
推薦答案
我不確定你是想要一個可以生成 JavaScript 編寫的解析器的解析器生成器,還是一個使用 JavaScript 語法來構建 JavaScript 解析器的解析器生成器.
I'm not sure if you want a parser generator that would spit a JavaScript written parser or a parser generator that would use a JavaScript grammar to build a JavaScript parser.
無論如何,我只使用過 ANTLR 和 JavaCC.ANTLR 允許您以不同的語言(C、C#、Java)生成解析器,并且在它們的 GUI 樹狀形式上檢查您的上下文無關語法表達式非常酷.但是從來沒有找到它的 JavaScript 語法.
Anyway, I've only used ANTLR and JavaCC. ANTLR allows you to generate your parser in different languages (C, C#, Java) and it's pretty cool checking your Context-free grammar expressions on their GUI tree-like form. Never found a JavaScript grammar for it though.
JavaCC 有一個缺點.僅在 Java 中生成解析器.另一方面,我發現學習和從構建解析器的部分開始更容易 - 我發現這是最好的部分 - 圍繞它構建你想要的任何東西,例如代碼翻譯器、改寫器等.
JavaCC has a downside. Only generates the parser in Java. On the other hand, I found it easier to learn and to step from the part where you build the parser to - what I found to be the best part - building whatever you want around it e.g., code translator, rephraser, etc, etc.
這篇關于Javascript 解析器生成器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!