Sly解析器,递归定义的类型是如何实现的?

问题描述 投票:0回答:1

我对编译器技术不熟悉,并开始将下面的代码转换为 Matlab。

https://github.com/jol-jol/pymatlabparser/blob/master/pymatlabparser/matlab_parser.py

分词器完成了,我开始了一个简单的移位/归约解析器。 但似乎没有规则可以产生“expr”而不需要它在其模式中。

通过内置的 Python 函数和类型,这种魔力在哪里发生? 知道如何在 Matlab 中实现它吗?

parsing compiler-construction sly
1个回答
0
投票

谢谢sepp2k

@_('NAME', 'NUMBER', 'STRING')                  # e.g. x, 56, 3e-2, "example"
def expr(self, p):
    return (p[0],)      # creates a tuple for the token to avoid strings getting concatenated later on

我错过了 def expr 部分。因此 expr 不是作为令牌类型创建的,而是作为函数创建的。

© www.soinside.com 2019 - 2024. All rights reserved.