gpt4 book ai didi

c - 我的 C 语法存在许多多重选择错误

转载 作者:行者123 更新时间:2023-11-30 15:51:17 25 4
gpt4 key购买 nike

我正在尝试使用 Antlwork 编写 C 语法,为此我使用了这个 http://stuff.mit.edu/afs/athena/software/antlr_v3.2/examples-v3/java/C/C.g我试图通过删除许多我不使用的 block 和回溯来使其变得更简单。这就是我所拥有的:http://www.archive-host.com/files/1956778/24fe084677d7655eb57ba66e1864081450017dd9/CNew.txt

然后,当我执行 ctrl+D 时,我收到很多警告和错误,如下所示:

[21:20:54] warning(200): C:\CNew.g:188:2:  Decision can match input such as "'{' '}'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[21:20:54] warning(200): C:\CNew.g:210:2: Decision can match input such as "'for' '('" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
[21:20:54] error(201): C:\CNew.g:210:2: The following alternatives can never be matched: 3

[21:20:54] error(208): C:\CNew.g:250:1: The following token definitions can never be matched because prior tokens match the same input: CHAR

我真的不明白为什么我会收到所有这些警告,不应该有冲突。

最佳答案

but I still have this error

[22:02:55] error(208): C:\Users\Seiya\Desktop\projets\TRAD\Gram\CNew.g:238:1: The following token definitions can never be matched because prior tokens match the same input: CONSTANT [22:17:18] error(208): CNew.g:251:1: The following token definitions can never be matched because prior tokens match the same input: CHAR [22:17:18] error(208): C:\Users\Seiya\Desktop\projets\TRAD\Gram\CNew.g:251:1: The following token definitions can never be matched because prior tokens match the same input: CHAR

这意味着词法分析器永远无法创建标记 CHARINT,因为其他一些词法分析器规则 CONSTANT 与相同的输入匹配。您需要做的是将 CONSTANT 更改为解析器规则。

换句话说,改变这两条规则:

primary_expression
: ID
| CONSTANT
| '(' expression ')'
;

CONSTANT
: INT
| CHAR
;

分为以下内容:

primary_expression
: ID
| constant
| '(' expression ')'
;

constant
: INT
| CHAR
;

关于c - 我的 C 语法存在许多多重选择错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15257319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com