如何定义ε当我用解析代码编写语法规则时?

发布于 2025-01-31 06:41:40 字数 457 浏览 2 评论 0原文

我正在尝试为我定义的特定语法编写编译器程序。

语法中有一些ε,因为一些迭代和递归规则。我试图通过创建一个空的令牌来定义ε

tokens = (
    'EMPTY'
) 

t_EMPTY = r'\ ' 

这引起了一些解析问题,因此我在Lexer代码中早些时候忽略了空间:

t_ignore  = ' \t' 

描述定义ε的其他方法是什么?

单击在这里查看项目文件

I'm trying to write a compiler program for a specific grammar I defined.

There are a few ε in the grammar because of some iterative and recursive rules. I tried to define ε by creating an empty token:

tokens = (
    'EMPTY'
) 

t_EMPTY = r'\ ' 

That caused some parsing problems, therefore I ignored spaces earlier in the lexer code:

t_ignore  = ' \t' 

What are other ways to describe define ε?

Click here to see the project files

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2025-02-07 06:41:40

已解决的。这是代码的语法部分中的空定义:

def p_empty(p):
    'empty :'
    pass

def p_option(p):
    '''option : start 
              | empty '''

Solved.The yacc.py module I used includes a special <empty> value for ε. Here is empty defining in the grammar part of the code:

def p_empty(p):
    'empty :'
    pass

def p_option(p):
    '''option : start 
              | empty '''
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文