用 Javascript 编写的词法分析器? [英] Lexer written in Javascript?

查看:55
本文介绍了用 Javascript 编写的词法分析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中用户需要为完全用 JavaScript 编写的 ui 定义一组指令.我需要能够解析一串指令,然后将它们翻译成指令.是否有任何用于解析 100% javascript 的库?或将在 javascript 中生成的生成器?谢谢!

I have a project where a user needs to define a set of instructions for a ui that is completely written in javascript. I need to have the ability to parse a string of instructions and then translate them into instructions. Is there any libraries out there for parsing that are 100% javascript? Or a generator that will generate in javascript? Thanks!

推荐答案

Something like http://jscc.phorward-software.com/,也许?

Something like http://jscc.phorward-software.com/, maybe?

JS/CC 是第一个适用于 JavaScript 和 ECMAScript 衍生物.它的开发目的是为了构建一个高效的编译器开发系统,以及为那些对解析表生成在一般情况下如何完成感兴趣的人创建一个易于使用的学术环境.自底向上解析.

JS/CC is the first available parser development system for JavaScript and ECMAScript-derivates. It has been developed, both, with the intention of building a productive compiler development system and with the intention of creating an easy-to-use academic environment for people interested in how parse table generation is done general in bottom-up parsing.

独立于平台的软件结合了两者:基于正则表达式的词法分析器生成器匹配来自输入字符流的单个标记和a LALR(1) 解析器生成器,计算给定 上下文无关语法 规范并构建独立的工作解析器.提供给 JS/CC 的上下文无关语法定义在 Backus-Naur-Form-based 元语言,并允许根据规则的约简评估单个语义代码的插入.

The platform-independent software unions both: A regular expression-based lexical analyzer generator matching individual tokens from the input character stream and a LALR(1) parser generator, computing the parse tables for a given context-free grammar specification and building a stand-alone, working parser. The context-free grammar fed to JS/CC is defined in a Backus-Naur-Form-based meta language, and allows the insertion of individual semantic code to be evaluated on a rule's reduction.

JS/CC 本身完全用 ECMAScript 编写,因此它可以以多种不同的方式执行:作为嵌入在网站上的独立于平台、基于浏览器的 JavaScript,作为 Windows 脚本宿主应用程序,作为编译的 JScript.NET 可执行文件,作为 Mozilla/Rhino 或 Mozilla/Spidermonkey 解释的应用程序,或 Windows、*nix、Linux 和 Mac OSX 上的 V8 shell 脚本.但是,为了高效执行,建议使用命令行版本.这些版本能够根据 JS/CC 解析器规范组装一个完整的编译器,然后将其存储到 .js JavaScript 源文件中.

JS/CC itself has been entirely written in ECMAScript so it can be executed in many different ways: as platform-independent, browser-based JavaScript embedded on a Website, as a Windows Script Host Application, as a compiled JScript.NET executable, as a Mozilla/Rhino or Mozilla/Spidermonkey interpreted application, or a V8 shell script on Windows, *nix, Linux and Mac OSX. However, for productive execution, it is recommended to use the command-line versions. These versions are capable of assembling a complete compiler from a JS/CC parser specification, which is then stored to a .js JavaScript source file.

这篇关于用 Javascript 编写的词法分析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆