- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的野牛语法有问题,它给我转移/减少错误,我已经为运算符定义了优先级。
我知道这是由 expr 规则的“expr binop expr”位引起的。这是我的野牛文件,以及我得到的输出。任何帮助将不胜感激。
%token ID KEYWORD INTCON FLOATCON TYPE STRING
%token IF WHILE FOR VOID RETURN
%token AND_OP OR_OP EQ_OP NEQ_OP LEQ_OP GEQ_OP
%left OR_OP
%left AND_OP
%nonassoc '<' LEQ_OP '>' GEQ_OP EQ_OP NEQ_OP
%left '+' '-'
%left '/' '*'
%right '!'
%%
expr : unop expr
| expr binop expr
| ID
| ID '[' expr ']'
| ID '(' expr_list ')'
| ID '(' ')'
| '(' expr ')'
| INTCON
| FLOATCON
;
expr_list : expr
| expr_list ',' expr
;
unop : '!' ;
binop : AND_OP | OR_OP | EQ_OP | NEQ_OP | '+' | '-' | '*' | '/' | LEQ_OP | '<' | GEQ_OP | '>' ;
Terminals unused in grammar
KEYWORD
TYPE
STRING
IF
WHILE
FOR
VOID
RETURN
State 25 conflicts: 12 shift/reduce
State 31 conflicts: 12 shift/reduce
Grammar
0 $accept: expr $end
1 expr: unop expr
2 | expr binop expr
3 | ID
4 | ID '[' expr ']'
5 | ID '(' expr_list ')'
6 | ID '(' ')'
7 | '(' expr ')'
8 | INTCON
9 | FLOATCON
10 expr_list: expr
11 | expr_list ',' expr
12 unop: '!'
13 binop: AND_OP
14 | OR_OP
15 | EQ_OP
16 | NEQ_OP
17 | '+'
18 | '-'
19 | '*'
20 | '/'
21 | LEQ_OP
22 | '<'
23 | GEQ_OP
24 | '>'
Terminals, with rules where they appear
$end (0) 0
'!' (33) 12
'(' (40) 5 6 7
')' (41) 5 6 7
'*' (42) 19
'+' (43) 17
',' (44) 11
'-' (45) 18
'/' (47) 20
'<' (60) 22
'>' (62) 24
'[' (91) 4
']' (93) 4
error (256)
ID (258) 3 4 5 6
KEYWORD (259)
INTCON (260) 8
FLOATCON (261) 9
TYPE (262)
STRING (263)
IF (264)
WHILE (265)
FOR (266)
VOID (267)
RETURN (268)
AND_OP (269) 13
OR_OP (270) 14
EQ_OP (271) 15
NEQ_OP (272) 16
LEQ_OP (273) 21
GEQ_OP (274) 23
Nonterminals, with rules where they appear
$accept (32)
on left: 0
expr (33)
on left: 1 2 3 4 5 6 7 8 9, on right: 0 1 2 4 7 10 11
expr_list (34)
on left: 10 11, on right: 5 11
unop (35)
on left: 12, on right: 1
binop (36)
on left: 13 14 15 16 17 18 19 20 21 22 23 24, on right: 2
state 0
0 $accept: . expr $end
1 expr: . unop expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 6
unop go to state 7
state 1
3 expr: ID . [$end, AND_OP, OR_OP, EQ_OP, NEQ_OP, LEQ_OP, GEQ_OP, '<', '>', '+', '-', '/', '*', ']', ')', ',']
4 | ID . '[' expr ']'
5 | ID . '(' expr_list ')'
6 | ID . '(' ')'
'(' shift, and go to state 8
'[' shift, and go to state 9
$default reduce using rule 3 (expr)
state 2
8 expr: INTCON .
$default reduce using rule 8 (expr)
state 3
9 expr: FLOATCON .
$default reduce using rule 9 (expr)
state 4
12 unop: '!' .
$default reduce using rule 12 (unop)
state 5
1 expr: . unop expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
7 | '(' . expr ')'
8 | . INTCON
9 | . FLOATCON
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 10
unop go to state 7
state 6
0 $accept: expr . $end
2 expr: expr . binop expr
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
$end shift, and go to state 11
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
binop go to state 24
state 7
1 expr: . unop expr
1 | unop . expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 25
unop go to state 7
state 8
1 expr: . unop expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
5 | ID '(' . expr_list ')'
6 | . ID '(' ')'
6 | ID '(' . ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
10 expr_list: . expr
11 | . expr_list ',' expr
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
')' shift, and go to state 26
expr go to state 27
expr_list go to state 28
unop go to state 7
state 9
1 expr: . unop expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
4 | ID '[' . expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 29
unop go to state 7
state 10
2 expr: expr . binop expr
7 | '(' expr . ')'
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
')' shift, and go to state 30
binop go to state 24
state 11
0 $accept: expr $end .
$default accept
state 12
13 binop: AND_OP .
$default reduce using rule 13 (binop)
state 13
14 binop: OR_OP .
$default reduce using rule 14 (binop)
state 14
15 binop: EQ_OP .
$default reduce using rule 15 (binop)
state 15
16 binop: NEQ_OP .
$default reduce using rule 16 (binop)
state 16
21 binop: LEQ_OP .
$default reduce using rule 21 (binop)
state 17
23 binop: GEQ_OP .
$default reduce using rule 23 (binop)
state 18
22 binop: '<' .
$default reduce using rule 22 (binop)
state 19
24 binop: '>' .
$default reduce using rule 24 (binop)
state 20
17 binop: '+' .
$default reduce using rule 17 (binop)
state 21
18 binop: '-' .
$default reduce using rule 18 (binop)
state 22
20 binop: '/' .
$default reduce using rule 20 (binop)
state 23
19 binop: '*' .
$default reduce using rule 19 (binop)
state 24
1 expr: . unop expr
2 | . expr binop expr
2 | expr binop . expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 31
unop go to state 7
state 25
1 expr: unop expr . [$end, AND_OP, OR_OP, EQ_OP, NEQ_OP, LEQ_OP, GEQ_OP, '<', '>', '+', '-', '/', '*', ']', ')', ',']
2 | expr . binop expr
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
AND_OP [reduce using rule 1 (expr)]
OR_OP [reduce using rule 1 (expr)]
EQ_OP [reduce using rule 1 (expr)]
NEQ_OP [reduce using rule 1 (expr)]
LEQ_OP [reduce using rule 1 (expr)]
GEQ_OP [reduce using rule 1 (expr)]
'<' [reduce using rule 1 (expr)]
'>' [reduce using rule 1 (expr)]
'+' [reduce using rule 1 (expr)]
'-' [reduce using rule 1 (expr)]
'/' [reduce using rule 1 (expr)]
'*' [reduce using rule 1 (expr)]
$default reduce using rule 1 (expr)
binop go to state 24
state 26
6 expr: ID '(' ')' .
$default reduce using rule 6 (expr)
state 27
2 expr: expr . binop expr
10 expr_list: expr . [')', ',']
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
$default reduce using rule 10 (expr_list)
binop go to state 24
state 28
5 expr: ID '(' expr_list . ')'
11 expr_list: expr_list . ',' expr
')' shift, and go to state 32
',' shift, and go to state 33
state 29
2 expr: expr . binop expr
4 | ID '[' expr . ']'
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
']' shift, and go to state 34
binop go to state 24
state 30
7 expr: '(' expr ')' .
$default reduce using rule 7 (expr)
state 31
2 expr: expr . binop expr
2 | expr binop expr . [$end, AND_OP, OR_OP, EQ_OP, NEQ_OP, LEQ_OP, GEQ_OP, '<', '>', '+', '-', '/', '*', ']', ')', ',']
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
AND_OP [reduce using rule 2 (expr)]
OR_OP [reduce using rule 2 (expr)]
EQ_OP [reduce using rule 2 (expr)]
NEQ_OP [reduce using rule 2 (expr)]
LEQ_OP [reduce using rule 2 (expr)]
GEQ_OP [reduce using rule 2 (expr)]
'<' [reduce using rule 2 (expr)]
'>' [reduce using rule 2 (expr)]
'+' [reduce using rule 2 (expr)]
'-' [reduce using rule 2 (expr)]
'/' [reduce using rule 2 (expr)]
'*' [reduce using rule 2 (expr)]
$default reduce using rule 2 (expr)
binop go to state 24
state 32
5 expr: ID '(' expr_list ')' .
5 expr: ID '(' expr_list ')' .
$default reduce using rule 5 (expr)
state 33
1 expr: . unop expr
2 | . expr binop expr
3 | . ID
4 | . ID '[' expr ']'
5 | . ID '(' expr_list ')'
6 | . ID '(' ')'
7 | . '(' expr ')'
8 | . INTCON
9 | . FLOATCON
11 expr_list: expr_list ',' . expr
12 unop: . '!'
ID shift, and go to state 1
INTCON shift, and go to state 2
FLOATCON shift, and go to state 3
'!' shift, and go to state 4
'(' shift, and go to state 5
expr go to state 35
unop go to state 7
state 34
4 expr: ID '[' expr ']' .
$default reduce using rule 4 (expr)
state 35
2 expr: expr . binop expr
11 expr_list: expr_list ',' expr . [')', ',']
13 binop: . AND_OP
14 | . OR_OP
15 | . EQ_OP
16 | . NEQ_OP
17 | . '+'
18 | . '-'
19 | . '*'
20 | . '/'
21 | . LEQ_OP
22 | . '<'
23 | . GEQ_OP
24 | . '>'
AND_OP shift, and go to state 12
OR_OP shift, and go to state 13
EQ_OP shift, and go to state 14
NEQ_OP shift, and go to state 15
LEQ_OP shift, and go to state 16
GEQ_OP shift, and go to state 17
'<' shift, and go to state 18
'>' shift, and go to state 19
'+' shift, and go to state 20
'-' shift, and go to state 21
'/' shift, and go to state 22
'*' shift, and go to state 23
$default reduce using rule 11 (expr_list)
binop go to state 24
%token ID KEYWORD INTCON FLOATCON TYPE STRING
%token IF WHILE FOR VOID RETURN
%token AND_OP OR_OP EQ_OP NEQ_OP LEQ_OP GEQ_OP
%left "||"
%left "&&"
%nonassoc '<' "<=" '>' ">=" "==" "!="
%left '+' '-'
%left '/' '*'
%right '!'
%%
expr : ID
| ID '[' expr ']'
| ID '(' expr_list ')'
| ID '(' ')'
| '(' expr ')'
| INTCON
| FLOATCON
| '!' expr
| '-' expr
| expr '+' expr
| expr '-' expr
| expr '/' expr
| expr '*' expr
| expr '<' expr
| expr '>' expr
| expr "<=" expr
| expr ">=" expr
| expr "==" expr
| expr "!=" expr
| expr "&&" expr
| expr "||" expr
;
expr_list : expr
| expr_list ',' expr
;
%%
最佳答案
仅当产生式直接包含在优先级声明中指定的终结符时,优先级才有效。
换句话说,您不能使用 expr: expr binop expr
因为优先关系不能帮助野牛决定是否移动减少的binop
非终端或减少expr
在解析堆栈的顶部。 Bison 要知道里面的终端是什么binop
是,但它不再知道了。 (这就是为什么减少被称为“减少”。)
为了使它工作,你必须完整地写出产品:
expr: expr '+' expr
| expr '-' expr
| expr '*' expr
|...
关于类 C 语言的 Bison Shift/减少错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085340/
我正在尝试实现 Intellij 之类的双类导航。我发现它被称为“快速打开文件”的“序列键绑定(bind)”。 因此,我在 .sublime-keymap --- USER 中添加了这一行 { "
this.x = (Math.random()*canvasWidth); this.y = (Math.random()*canvasHeight); (1) this.shift = {x: th
我目前正在研究编译器,据我了解,在 LR(0) 中,有时会出现“shift/reduce”或“reduce/reduce”冲突,但不可能出现“shift/shift”冲突!为什么我们不能发生“转变/转
我希望使用 AutoHotKey 来修改我的 shift 键的功能。 Steve Losh 的博客条目 here 中描述了该功能。 .具体来说,我希望我的 shift 键执行以下操作: 如果 LShi
在我的Redis数据库中,我有一个以prefix:格式保存的键列表,所以示例数据库看起来像这样:。问题是,当我尝试删除前缀:1时,因为无论出于什么原因,我都需要删除IPSUM,在索引之间留下了一个间隙
在我的Redis DB中,我有一个以prefix:格式保存的键列表,因此示例数据库如下所示:。问题是,当我尝试删除前缀:1时,因为无论出于什么原因,我都需要删除IPSUM,在索引之间留下了一个间隙--
Listview 控件中是否有可以上下移动项目的功能? 最佳答案 我没有太多使用 TListView(我主要使用数据库网格),我把你的问题作为学习一些东西的机会。下面的代码是结果,它比大卫的答案更直观
我有点难以发现这两种操作的不同之处。所以我读到算术移位与逻辑移位基本相同,唯一的区别是它以某种方式保持最高位或有符号位。 所以当我在 101110 上做 LSL #2 时假设这个二进制是一个无符号的,
我正在尝试使用 shift+shift 配置键映射,这可能吗? 我试过: But this maps shift + S and this that maps to unknown 最佳答案 您不
我正在努力在 vim 中绑定(bind) Shift+- 组合。我已经尝试了以下两种选项,但都没有可用的选项,并且谷歌搜索没有带来任何相关信息。 nnoremap - nnoremap - 我正在
我正在使用基于Gallery 的Cover-flow,正如建议的那样here . 是否有可以捕获的事件表明在我的画廊/封面流中进行了一次移位(向左或向右)? 需要明确的是,如果我给画廊一个像样的滑动并
这个问题在这里已经有了答案: Cocoa - NSEvent Respond to the SHIFT key? (5 个答案) 关闭 3 年前。 我正在制作这个应用程序,我想检测是否检测到 shi
我不允许在我的 C 代码中使用浮点变量(出于性能原因)。我想进行整数除法运算,同时我想尽可能地防止除法损失。 我的理解是,如果分子很大,除法运算会产生很好的结果。目前我正在对分子进行左移操作以使其成为
我有一个文本输入,当用户按下 shift(keydown)并绑定(bind)一个监听器以监听 shift 键时,它现在变得透明 即。 $('#foo').keydown(function(){
我有一个包含 shift 命令的 bash 脚本。 它在 bash 中运行正常,但在 zsh 环境中,shift 命令似乎不同。 zsh $ shift shift: shift count must
我正在使用 Fedora 29 中包含的 vim: VIM - Vi IMproved 8.1(2018 年 5 月 18 日,2019 年 2 月 4 日 14:19:12 编译) 我刚刚注意到按
我有一个包含 shift 命令的 bash 脚本。 它在 bash 中运行正常,但在 zsh 环境中,shift 命令似乎不同。 zsh $ shift shift: shift count must
我正在使用 Fedora 29 中包含的 vim: VIM - Vi IMproved 8.1(2018 年 5 月 18 日,2019 年 2 月 4 日 14:19:12 编译) 我刚刚注意到按
我可以使用 UITextViewDelegate 或 NSNotificationCenter 来检测用户何时点击 Keyboard 上的字符键将文本输入到 UITextView. 但我的应用程序需要
当我尝试单击 shift + tab 组合时, Shiftkey 被触发 $("#buttonZZ").on("keydown",function (eve) { if (eve.keyCod
我是一名优秀的程序员,十分优秀!