javascript - 为什么 ECMAScript RegExp 语法的替代符号是左递归的?

标签 javascript regex grammar ecma262

我一生都无法弄清楚为什么Alternative 是递归的。它确实给我的解析器带来了麻烦。

Alternative :: 
    [empty] 
    Alternative Term 

这是规范语义部分中的一个注释,但并不完全清楚。也许一旦我明白了这一点,推理就会揭晓?

NOTE Consecutive Terms try to simultaneously match consecutive portions of the input String. If the left Alternative, the right Term, and the sequel of the regular expression all have choice points, all choices in the sequel are tried before moving on to the next choice in the right Term, and all choices in the right Term are tried before moving on to the next choice in the left Alternative.

什么样的解析器可以正确处理左递归语法?

最佳答案

因为对于某些类型的解析器,左递归要好得多(例如,对于 yacc - 请参阅第 6.2 节 here 以获得解释)。

如果它给您的特定解析器带来麻烦,那么请务必将其交换 - 它不会以任何方式影响语言的定义。

关于javascript - 为什么 ECMAScript RegExp 语法的替代符号是左递归的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3118802/

相关文章:

javascript - 在 PaperJS 中,当鼠标离开项目时,如何将 onMouseUp 事件链接到 onMouseDown 事件的起源

javascript - 使用 React.js 和 Material-UI 简化样式组件媒体查询

java - 在Java中使用正则表达式抓取文本标题

javascript - 用正则表达式替换单词

python - 我的语法或解析器生成工具是否存在错误?

algorithm - 语法推理 : How can the algorithm Alignment Based Learning help us infering a grammar

javascript - AngularJS 中的表单验证和动态控件

javascript - 使用正则表达式选择 HTML 文本元素?

c - 如何定义排除某组词的文法?

javascript - 如何在 MVC Razor View 中显示颜色选择器