我是Bison的新人。 我已经制作了我的.y文件但是在编译中我收到了这个错误:
警告:42次/减少冲突[-Wconflicts-sr]
我已经打开了生成的.output文件,我已经看到了以下内容,但无法理解,无法找出问题所在。
以下是我的.output文件的一部分:
State 63
56 expr_decl: KW_NOT expr_decl . [KW_END, KW_OR, OP_OR, KW_AND, OP_AND, '>', OP_LESSOREQUAL, OP_GREATEROREQUAL, '=', OP_NOTEQUAL, '<', '*', '/', KW_DIV, KW_MOD, ';', ')', '+', '-']
59 | expr_decl . '*' expr_decl
60 | expr_decl . '/' expr_decl
61 | expr_decl . KW_DIV expr_decl
62 | expr_decl . KW_MOD expr_decl
63 | expr_decl . '+' expr_decl
64 | expr_decl . '-' expr_decl
65 | expr_decl . '=' expr_decl
66 | expr_decl . '<' expr_decl
67 | expr_decl . '>' expr_decl
68 | expr_decl . OP_NOTEQUAL expr_decl
69 | expr_decl . OP_LESSOREQUAL expr_decl
70 | expr_decl . OP_GREATEROREQUAL expr_decl
71 | expr_decl . OP_AND expr_decl
72 | expr_decl . KW_AND expr_decl
73 | expr_decl . KW_OR expr_decl
74 | expr_decl . OP_OR expr_decl
'+' shift, and go to state 87
'-' shift, and go to state 88
'+' [reduce using rule 56 (expr_decl)]
'-' [reduce using rule 56 (expr_decl)]
$default reduce using rule 56 (expr_decl)
Conflict between rule 56 and token KW_OR resolved as reduce (KW_OR < KW_NOT).
Conflict between rule 56 and token OP_OR resolved as reduce (OP_OR < KW_NOT).
Conflict between rule 56 and token KW_AND resolved as reduce (KW_AND < KW_NOT).
Conflict between rule 56 and token OP_AND resolved as reduce (OP_AND < KW_NOT).
Conflict between rule 56 and token '>' resolved as reduce ('>' < KW_NOT).
Conflict between rule 56 and token OP_LESSOREQUAL resolved as reduce (OP_LESSOREQUAL < KW_NOT).
Conflict between rule 56 and token OP_GREATEROREQUAL resolved as reduce (OP_GREATEROREQUAL < KW_NOT).
Conflict between rule 56 and token '=' resolved as reduce ('=' < KW_NOT).
Conflict between rule 56 and token OP_NOTEQUAL resolved as reduce (OP_NOTEQUAL < KW_NOT).
Conflict between rule 56 and token '<' resolved as reduce ('<' < KW_NOT).
Conflict between rule 56 and token '*' resolved as reduce ('*' < KW_NOT).
Conflict between rule 56 and token '/' resolved as reduce ('/' < KW_NOT).
Conflict between rule 56 and token KW_DIV resolved as reduce (KW_DIV < KW_NOT).
Conflict between rule 56 and token KW_MOD resolved as reduce (KW_MOD < KW_NOT).
请帮忙吗?我一直在寻找几个小时但仍然没有...
这是我的声明部分:
%left KW_OR OP_OR
%left KW_AND OP_AND
%left '>' OP_LESSOREQUAL OP_GREATEROREQUAL
%left '=' OP_NOTEQUAL '<'
%left OP_PLUS OP_MINUS
%left '*' '/' KW_DIV KW_MOD
%left cast
%right POSITIVE NEGATIVE
%right KW_NOT '!'
这是我在野牛的规则:
expr_decl :
| REAL
| POSINT
| '!' expr_decl { $$ = template("!(%s)", $2); }
| KW_NOT expr_decl { $$ = template("not(%s)", $2); }
| '+' expr_decl %prec POSITIVE { $$ = template("+(%s)", $2); }
| '-' expr_decl %prec NEGATIVE { $$ = template("-(%s)", $2); }
| expr_decl '*' expr_decl { $$ = template("%s * %s", $1, $3); }
| expr_decl '/' expr_decl { $$ = template("%s / %s", $1, $3); }
| expr_decl KW_DIV expr_decl { $$ = template("%s div %s", $1, $3); }
| expr_decl KW_MOD expr_decl { $$ = template("%s mod %s", $1, $3); }
| expr_decl '+' expr_decl %prec OP_PLUS{ $$ = template("%s + %s", $1, $3); }
| expr_decl '-' expr_decl %prec OP_MINUS{ $$ = template("%s + %s", $1, $3); }
| expr_decl '=' expr_decl { $$ = template("%s = %s", $1, $3); }
| expr_decl '<' expr_decl { $$ = template("%s < %s", $1, $3); }
| expr_decl '>' expr_decl { $$ = template("%s > %s", $1, $3); }
| expr_decl OP_NOTEQUAL expr_decl { $$ = template("%s <> %s", $1, $3); }
| expr_decl OP_LESSOREQUAL expr_decl { $$ = template("%s <= %s", $1, $3); }
| expr_decl OP_GREATEROREQUAL expr_decl { $$ = template("%s >= %s", $1, $3); }
| expr_decl OP_AND expr_decl { $$ = template("%s && %s", $1, $3); }
| expr_decl KW_AND expr_decl { $$ = template("%s and %s", $1, $3); }
| expr_decl KW_OR expr_decl { $$ = template("%s || %s", $1, $3); }
| expr_decl OP_OR expr_decl { $$ = template("%s or %s", $1, $3); }
| '(' expr_decl ')' { $$ = template("(%s)", $2); }
;
答案 0 :(得分:2)
输出文件的这一部分:
def get_model(input, dropout):
with tf.name_scope('Conv1'):
input_4D = tf.reshape(input, [-1, HEIGHT, WIDTH, 1])
w1 = tf.Variable(tf.truncated_normal([12, 8, 1, 44], stddev=0.01), name='W1')
b1 = tf.Variable(tf.zeros([44]), name='B1')
conv1 = tf.nn.conv2d(input_4D, w1, strides=[1, 1, 1, 1], padding='SAME')
act1 = tf.nn.relu(conv1 + b1)
drop1 = tf.nn.dropout(act1, dropout)
max_pool1 = tf.nn.max_pool(drop1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
tf.summary.histogram('weights', w1)
tf.summary.histogram('biases', b1)
tf.summary.histogram('activations', act1)
tf.summary.histogram('dropouts', drop1)
with tf.name_scope('Conv2'):
w2 = tf.Variable(tf.truncated_normal([6, 4, 44, 44], stddev=0.01), name='W2')
b2 = tf.Variable(tf.zeros([44]), name='B2')
conv2 = tf.nn.conv2d(max_pool1, w2, strides=[1, 1, 1, 1], padding='SAME')
act2 = tf.nn.relu(conv2 + b2)
drop2 = tf.nn.dropout(act2, dropout)
tf.summary.histogram('weights', w2)
tf.summary.histogram('biases', b2)
tf.summary.histogram('activations', act2)
tf.summary.histogram('dropouts', drop2)
conv_shape = drop2.get_shape()
count = int(conv_shape[1] * conv_shape[2] * conv_shape[3])
flat_output = tf.reshape(drop2, [-1, count])
with tf.name_scope('FC'):
w3 = tf.Variable(tf.truncated_normal([count, NUM_LABELS], stddev=0.01), name='W3')
b3 = tf.Variable(tf.zeros([NUM_LABELS]), name='B3')
fc = tf.add(tf.matmul(flat_output, w3), b3)
tf.summary.histogram('weights', w3)
tf.summary.histogram('biases', b3)
return fc
告诉您在此状态下,在前瞻符号'+' shift, and go to state 87
'-' shift, and go to state 88
'+' [reduce using rule 56 (expr_decl)]
'-' [reduce using rule 56 (expr_decl)]
和'+'
上有两个移位/减少冲突。 reduce操作周围的'-'
.. [
表示该操作已被删除(解决冲突有利于转移)。
消息:
]
告诉您有关语法中优先规则解决的转移/减少冲突(因此不包含在警告中的42个转换/减少冲突中)。
优先规则不能解决Conflict between rule 56 and token KW_OR resolved as reduce (KW_OR < KW_NOT).
Conflict between rule 56 and token OP_OR resolved as reduce (OP_OR < KW_NOT).
Conflict between rule 56 and token KW_AND resolved as reduce (KW_AND < KW_NOT).
:
和'+'
的冲突,因为您没有为这些令牌设置优先级。