简体   繁体   English

Bison 语法/解析器的多个起点

[英]Multiple start points for Bison grammar/parser

OK, so I have a complete (and working) Bison grammar.好的,所以我有一个完整的(和有效的)Bison 语法。

The thing is I want to be able to set another starting point ( %start ) if I wish.如果我愿意,我希望能够设置另一个起点( %start )。

How is this doable, without having to create a separate grammar/parser?这是如何可行的,而不必创建单独的语法/解析器?

I'm going to try to put together a version of yacc that does this.我将尝试组合一个执行此操作的 yacc 版本。 There is one complication that makes this not as trivial as it seems: the question of what constitutes an "end" symbol.有一个复杂因素使这一切并不像看起来那么简单:什么构成“结束”符号的问题。 The kind of place where this is of greatest use is in processing chunks in mid-stream (Knuth's TeX processor for [c]Web does this, for instance).这种方法最有用的地方是在中游处理块(例如,Knuth 的 [c]Web 的 TeX 处理器就是这样做的)。 Along these lines, another example where this can be used is in providing a unified parser for both the pre-processing layer and language layer and in processing individual macros themselves as entire parsing units (as well as being able to account for which macro bodies are common syntactic units like "expression" or "statement" and which are not).沿着这些思路,另一个可以使用它的示例是为预处理层和语言层提供统一的解析器,并将单个宏本身作为整个解析单元进行处理(以及能够说明哪些宏主体是常见的句法单元,如“表达式”或“语句”,而哪些不是)。

In those kinds of applications, there is no natural "end" symbol to mark off the boundary of a segment for parsing.在这些类型的应用程序中,没有自然的“结束”符号来标记要解析的段的边界。 Normally, the LR method requires this in order to recognize when to take the "accept" action.通常,LR 方法需要这样做,以便识别何时采取“接受”操作。 Otherwise, you have accept-reduce (and even accept-shift) conflicts to contend with!否则,您将面临接受减少(甚至接受转移)冲突!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM