[英]How to understand and fix conflicts in PLY
I am working on a SystemVerilog parser and I am running into many ply conflicts (both shift/reduce and reduce/reduce). 我正在使用SystemVerilog解析器,我遇到了很多层冲突(shift / reduce和reduce / reduce)。
I currently have like 170+ conflicts and the problem I have is that I don't really understand the parser.out file generated by PLY. 我目前有170多个冲突,我遇到的问题是我不太了解PLY生成的parser.out文件。 Without properly understanding that there is little I can do, so my goal is to understand what ply is reporting.
如果没有正确理解我无能为力,那么我的目标就是了解报道的内容。 All the PLY documentation is brief and not very explainatory...
所有的PLY文件都很简短,而且不是很解释......
Here you have one of my states, the first where a conflict is found apparently: 在这里你有我的一个州,第一个发现冲突的地方:
state 24
(134) attribute_instance_optional_list -> attribute_instance_list .
(136) attribute_instance_list -> attribute_instance_list . attribute_instance
(138) attribute_instance -> . LPAREN ASTERISK attr_spec_list ASTERISK RPAREN
! shift/reduce conflict for LPAREN resolved as shift
PLUS reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
MINUS reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
EXCLAMATION reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
NEG reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
AMPERSAND reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
NEGAMPERSAND reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
PIPE reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
NEGPIPE reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
CARET reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
NEGCARET reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
UNBASED_UNSIZED_LITERAL reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
STRING_LITERAL reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
REAL_FLOATINGP_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
REAL_FIXEDP_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INT_HEX_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INT_BINARY_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INT_OCTAL_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INT_DECIMAL_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
UNSIGNED_NUMBER reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
DOUBLEPLUS reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
DOUBLEMINUS reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
AT reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
TAGGED reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INOUT reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
INPUT reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
OUTPUT reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
REF reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
ID reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
ESCAPED_ID reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
MODULE reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
MACROMODULE reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .)
LPAREN shift and go to state 21
! LPAREN [ reduce using rule 134 (attribute_instance_optional_list -> attribute_instance_list .) ]
attribute_instance shift and go to state 49
As far as I understand ply, grammar rules are processed and states are built. 据我所知,语法规则被处理并且状态被构建。 Each of those states takes decisions based on the tokens that are coming in. So in this state that I posted (state 24), for example, if a PLUS token was waiting to be shifted in the stack, ply would go ahead and "reduce using rule 134".
这些状态中的每一个都根据正在进入的令牌做出决定。因此,在我发布的状态(状态24)中,例如,如果PLUS令牌等待在堆栈中移位,则ply将继续并且“减少”使用规则134“。 One thing I don't understand is, what does ply do then?
我不明白的一件事是,那么做什么呢? I mean does it stay in the same state (24)?
我的意思是它是否保持同一状态(24)? Is it only when an "attribute_instance" is waiting to be shifted in, when ply actualy moves states and goes to state 49?
仅当“attribute_instance”等待移入时,当ply实际移动状态并进入状态49时?
Another question, what do the parsing "snapshots" listed at the beggining of the state mean? 另一个问题是,在状态开始时列出的解析“快照”是什么意思?
(134) attribute_instance_optional_list -> attribute_instance_list .
(136) attribute_instance_list -> attribute_instance_list . attribute_instance
(138) attribute_instance -> . LPAREN ASTERISK attr_spec_list ASTERISK RPAREN
Does PLY compute all the possible stack states under which state 24 could be reached? PLY是否计算可以达到状态24的所有可能堆栈状态? is that even possible?
甚至可能吗?
In case it is of any use, here you can see my grammar's rules: 如果它有任何用处,在这里你可以看到我的语法规则:
Grammar
Rule 0 S' -> source_text
Rule 1 source_text -> timeunits_declaration description_list
Rule 2 timeunits_declaration -> timeunit_and_precision
Rule 3 timeunits_declaration -> timeunit
Rule 4 timeunits_declaration -> timeprecision
Rule 5 timeunits_declaration -> timeunit timeprecision
Rule 6 timeunits_declaration -> timeprecision timeunit
Rule 7 timeunits_declaration -> empty
Rule 8 timeunit_and_precision -> TIMEUNIT time_literal SLASH time_literal SEMICOLON
Rule 9 timeunit -> TIMEUNIT time_literal SEMICOLON
Rule 10 timeprecision -> TIMEPRECISION time_literal SEMICOLON
Rule 11 time_literal -> UNSIGNED_NUMBER time_unit
Rule 12 time_literal -> REAL_FIXEDP_NUMBER time_unit
Rule 13 time_unit -> S
Rule 14 time_unit -> MS
Rule 15 time_unit -> US
Rule 16 time_unit -> NS
Rule 17 time_unit -> PS
Rule 18 time_unit -> FS
Rule 19 description_list -> description_list description
Rule 20 description_list -> description
Rule 21 description -> module_declaration
Rule 22 module_declaration -> module_nonansi_header timeunits_declaration module_item_list module_footer
Rule 23 module_declaration -> module_ansi_header timeunits_declaration non_port_module_item_list module_footer
Rule 24 module_declaration -> module_implicit_header timeunits_declaration module_item module_footer
Rule 25 module_declaration -> EXTERN module_nonansi_header
Rule 26 module_declaration -> EXTERN module_ansi_header
Rule 27 module_nonansi_header -> attribute_instance_optional_list module_keyword lifetime module_identifier package_import_declaration_list parameter_port_list list_of_ports SEMICOLON
Rule 28 module_ansi_header -> attribute_instance_optional_list module_keyword lifetime module_identifier package_import_declaration_list parameter_port_list list_of_port_declarations_list SEMICOLON
Rule 29 module_implicit_header -> attribute_instance_optional_list module_keyword lifetime module_identifier LPAREN DOT ASTERISK RPAREN SEMICOLON
Rule 30 module_keyword -> MODULE
Rule 31 module_keyword -> MACROMODULE
Rule 32 module_footer -> ENDMODULE COLON module_identifier
Rule 33 module_footer -> ENDMODULE
Rule 34 module_item -> port_declaration SEMICOLON
Rule 35 module_item -> non_port_module_item
Rule 36 port_declaration -> attribute_instance_optional_list inout_declaration
Rule 37 port_declaration -> attribute_instance_optional_list input_declaration
Rule 38 port_declaration -> attribute_instance_optional_list output_declaration
Rule 39 port_declaration -> attribute_instance_optional_list ref_declaration
Rule 40 port_declaration -> attribute_instance_optional_list interface_port_declaration
Rule 41 inout_declaration -> INOUT net_port_type list_of_port_identifiers
Rule 42 input_declaration -> INPUT net_port_type list_of_port_identifiers
Rule 43 input_declaration -> INPUT variable_port_type list_of_variable_identifiers
Rule 44 output_declaration -> OUTPUT net_port_type list_of_port_identifiers
Rule 45 interface_port_declaration -> interface_identifier list_of_interface_identifiers
Rule 46 interface_port_declaration -> interface_identifier DOT modport_identifier list_of_interface_identifiers
Rule 47 ref_declaration -> REF variable_port_type list_of_variable_identifiers
Rule 48 casting_type -> simple_type
Rule 49 casting_type -> constant_primary
Rule 50 casting_type -> signing
Rule 51 casting_type -> STRING
Rule 52 casting_type -> CONST
Rule 53 data_type -> integer_vector_type optional_signing optional_packed_dimension
Rule 54 data_type -> integer_atom_type optional_signing
Rule 55 data_type -> non_integer_type
Rule 56 data_type -> struct_union LBRACE struct_union_member_list RBRACE optional_packed_dimension_list
Rule 57 data_type -> ENUM LBRACE optional_enum_name_declaration_list RBRACE optional_packed_dimension_list
Rule 58 data_type -> ENUM enum_base_type LBRACE optional_enum_name_declaration_list RBRACE optional_packed_dimension_list
Rule 59 data_type -> STRING
Rule 60 data_type -> CHANDLE
Rule 61 data_type -> VIRTUAL interface_identifier optional_parameter_value_assignment optional_modport_identifier
Rule 62 data_type -> VIRTUAL INTERFACE interface_identifier optional_parameter_value_assignment optional_modport_identifier
Rule 63 data_type -> type_identifier optional_packed_dimension_list
Rule 64 data_type -> class_scope type_identifier optional_packed_dimension_list
Rule 65 data_type -> package_scope type_identifier optional_packed_dimension_list
Rule 66 data_type -> class_type
Rule 67 data_type -> EVENT
Rule 68 data_type -> ps_covergroup_identifier
Rule 69 data_type -> type_reference
Rule 70 data_type_or_implicit -> data_type
Rule 71 data_type_or_implicit -> implicit_data_type
Rule 72 implicit_data_type -> optional_signing optional_packed_dimension_list
Rule 73 enum_base_type -> integer_atom_type optional_signing
Rule 74 enum_base_type -> integer_vector_type optional_signing optional_packed_dimension
Rule 75 enum_base_type -> type_identifier optional_packed_dimension
Rule 76 enum_name_declaration -> enum_identifier optional_enum_identifier_pointer
Rule 77 enum_name_declaration -> enum_identifier optional_enum_identifier_pointer EQUALS constant_expression
Rule 78 optional_enum_identifier_pointer -> LBRACKET integral_number RBRACKET
Rule 79 optional_enum_identifier_pointer -> LBRACKET integral_number COLON integral_number RBRACKET
Rule 80 optional_enum_identifier_pointer -> empty
Rule 81 class_scope -> class_type DOUBLECOLON
Rule 82 class_type -> ps_class_identifier optional_parameter_value_assignment
Rule 83 class_type -> ps_class_identifier optional_parameter_value_assignment parametrized_class_list
Rule 84 parametrized_class_list -> parametrized_class_list DOUBLECOLON class_identifier optional_parameter_value_assignment
Rule 85 parametrized_class_list -> DOUBLECOLON class_identifier optional_parameter_value_assignment
Rule 86 integer_type -> integer_vector_type
Rule 87 integer_type -> integer_atom_type
Rule 88 integer_atom_type -> BYTE
Rule 89 integer_atom_type -> SHORTINT
Rule 90 integer_atom_type -> INT
Rule 91 integer_atom_type -> LONGINT
Rule 92 integer_atom_type -> INTEGER
Rule 93 integer_atom_type -> TIME
Rule 94 integer_vector_type -> BIT
Rule 95 integer_vector_type -> LOGIC
Rule 96 integer_vector_type -> REG
Rule 97 non_integer_type -> SHORTREAL
Rule 98 non_integer_type -> REAL
Rule 99 non_integer_type -> REALTIME
Rule 100 net_type -> SUPPLY0
Rule 101 net_type -> SUPPLY1
Rule 102 net_type -> TRI
Rule 103 net_type -> TRIAND
Rule 104 net_type -> TRIOR
Rule 105 net_type -> TRIREG
Rule 106 net_type -> TRI0
Rule 107 net_type -> TRI1
Rule 108 net_type -> UWIRE
Rule 109 net_type -> WIRE
Rule 110 net_type -> WAND
Rule 111 net_type -> WOR
Rule 112 net_port_type -> data_type_or_implicit
Rule 113 net_port_type -> net_type data_type_or_implicit
Rule 114 net_port_type -> net_type_identifier
Rule 115 net_port_type -> INTERCONNECT implicit_data_type
Rule 116 variable_port_type -> var_data_type
Rule 117 var_data_type -> data_type
Rule 118 var_data_type -> VAR data_type_or_implicit
Rule 119 signing -> SIGNED
Rule 120 signing -> UNSIGNED
Rule 121 simple_type -> integer_type
Rule 122 simple_type -> non_integer_type
Rule 123 simple_type -> ps_type_identifier
Rule 124 simple_type -> ps_parameter_identifier
Rule 125 struct_union_member -> attribute_instance_optional_list data_type_or_void list_of_variable_decl_assignments
Rule 126 struct_union_member -> attribute_instance_optional_list random_qualifier data_type_or_void list_of_variable_decl_assignments
Rule 127 data_type_or_void -> data_type
Rule 128 data_type_or_void -> VOID
Rule 129 struct_union -> STRUCT
Rule 130 struct_union -> UNION
Rule 131 struct_union -> UNION TAGGED
Rule 132 type_reference -> TYPE LPAREN expression RPAREN
Rule 133 type_reference -> TYPE LPAREN data_type RPAREN
Rule 134 attribute_instance_optional_list -> attribute_instance_list
Rule 135 attribute_instance_optional_list -> empty
Rule 136 attribute_instance_list -> attribute_instance_list attribute_instance
Rule 137 attribute_instance_list -> attribute_instance
Rule 138 attribute_instance -> LPAREN ASTERISK attr_spec_list ASTERISK RPAREN
Rule 139 attr_spec_list -> attr_spec_list COMMA attr_spec
Rule 140 attr_spec_list -> attr_spec
Rule 141 attr_spec -> attr_name
Rule 142 attr_spec -> attr_name EQUALS constant_expression
Rule 143 attr_name -> identifier
Rule 144 inc_or_dec_expression -> inc_or_dec_operator attribute_instance_optional_list variable_lvalue
Rule 145 inc_or_dec_expression -> variable_lvalue attribute_instance_optional_list inc_or_dec_operator
Rule 146 conditional_expression -> cond_predicate INTERROGATION attribute_instance_optional_list expression COLON expression
Rule 147 constant_expression -> constant_primary
Rule 148 constant_expression -> unary_operator attribute_instance_optional_list constant_primary
Rule 149 constant_expression -> constant_expression binary_operator attribute_instance_optional_list constant_expression
Rule 150 constant_expression -> constant_expression INTERROGATION attribute_instance_optional_list constant_expression COLON constant_expression
Rule 151 constant_mintypmax_expression -> constant_expression
Rule 152 constant_mintypmax_expression -> constant_expression COLON constant_expression COLON constant_expression
Rule 153 constant_param_expression -> constant_mintypmax_expression
Rule 154 constant_param_expression -> data_type
Rule 155 constant_param_expression -> DOLLAR
Rule 156 param_expression -> mintypmax_expression
Rule 157 param_expression -> data_type
Rule 158 param_expression -> DOLLAR
Rule 159 constant_range_expression -> constant_expression
Rule 160 constant_range_expression -> constant_part_select_range
Rule 161 constant_part_select_range -> constant_range
Rule 162 constant_part_select_range -> constant_indexed_range
Rule 163 constant_range -> constant_expression COLON constant_expression
Rule 164 constant_indexed_range -> constant_expression PLUSCOLON constant_expression
Rule 165 constant_indexed_range -> constant_expression MINUSCOLON constant_expression
Rule 166 expression -> primary
Rule 167 expression -> unary_operator attribute_instance_optional_list primary
Rule 168 expression -> inc_or_dec_expression
Rule 169 expression -> LPAREN operator_assignment RPAREN
Rule 170 expression -> expression binary_operator attribute_instance_optional_list expression
Rule 171 expression -> conditional_expression
Rule 172 expression -> inside_expression
Rule 173 expression -> tagged_union_expression
Rule 174 tagged_union_expression -> TAGGED member_identifier
Rule 175 tagged_union_expression -> TAGGED member_identifier expression
Rule 176 inside_expression -> expression INSIDE LBRACE open_range_list RBRACE
Rule 177 value_range -> expression
Rule 178 value_range -> LBRACKET expression COLON expression RBRACKET
Rule 179 mintypmax_expression -> expression
Rule 180 mintypmax_expression -> expression COLON expression COLON expression
Rule 181 module_path_conditional_expression -> module_path_expression INTERROGATION attribute_instance_optional_list module_path_expression COLON module_path_expression
Rule 182 module_path_expression -> module_path_primary
Rule 183 module_path_expression -> unary_module_path_operator attribute_instance_optional_list module_path_primary
Rule 184 module_path_expression -> module_path_expression binary_module_path_operator attribute_instance_optional_list module_path_expression
Rule 185 module_path_expression -> module_path_conditional_expression
Rule 186 module_path_mintypmax_expression -> module_path_expression
Rule 187 module_path_mintypmax_expression -> module_path_expression COLON module_path_expression COLON module_path_expression
Rule 188 part_select_range -> constant_range
Rule 189 part_select_range -> indexed_range
Rule 190 indexed_range -> expression PLUSCOLON constant_expression
Rule 191 indexed_range -> expression MINUSCOLON constant_expression
Rule 192 genvar_expression -> constant_expression
Rule 193 constant_primary -> primary_literal
Rule 194 primary_literal -> number
Rule 195 primary_literal -> time_literal
Rule 196 primary_literal -> UNBASED_UNSIZED_LITERAL
Rule 197 primary_literal -> STRING_LITERAL
Rule 198 number -> REAL_FLOATINGP_NUMBER
Rule 199 number -> REAL_FIXEDP_NUMBER
Rule 200 number -> INT_HEX_NUMBER
Rule 201 number -> INT_BINARY_NUMBER
Rule 202 number -> INT_OCTAL_NUMBER
Rule 203 number -> INT_DECIMAL_NUMBER
Rule 204 number -> UNSIGNED_NUMBER
Rule 205 unary_operator -> PLUS
Rule 206 unary_operator -> MINUS
Rule 207 unary_operator -> EXCLAMATION
Rule 208 unary_operator -> NEG
Rule 209 unary_operator -> AMPERSAND
Rule 210 unary_operator -> NEGAMPERSAND
Rule 211 unary_operator -> PIPE
Rule 212 unary_operator -> NEGPIPE
Rule 213 unary_operator -> CARET
Rule 214 unary_operator -> NEGCARET
Rule 215 binary_operator -> PLUS
Rule 216 binary_operator -> MINUS
Rule 217 binary_operator -> ASTERISK
Rule 218 binary_operator -> SLASH
Rule 219 binary_operator -> PERCENT
Rule 220 binary_operator -> ISEQUAL
Rule 221 binary_operator -> NISEQUAL
Rule 222 binary_operator -> CISEQUAL
Rule 223 binary_operator -> NCISEQUAL
Rule 224 binary_operator -> WISEQUAL
Rule 225 binary_operator -> NWISEQUAL
Rule 226 binary_operator -> DOUBLEAMPERSAND
Rule 227 binary_operator -> DOUBLEPIPE
Rule 228 binary_operator -> DOUBLEASTERISK
Rule 229 binary_operator -> LT
Rule 230 binary_operator -> LE
Rule 231 binary_operator -> GT
Rule 232 binary_operator -> GE
Rule 233 binary_operator -> AMPERSAND
Rule 234 binary_operator -> PIPE
Rule 235 binary_operator -> CARET
Rule 236 binary_operator -> NEGCARET
Rule 237 binary_operator -> RSHIFT
Rule 238 binary_operator -> LSHIFT
Rule 239 binary_operator -> ARSHIFT
Rule 240 binary_operator -> ALSHIFT
Rule 241 binary_operator -> IMPLICATION
Rule 242 binary_operator -> EQUIVALENCE
Rule 243 inc_or_dec_operator -> DOUBLEPLUS
Rule 244 inc_or_dec_operator -> DOUBLEMINUS
Rule 245 unary_module_path_operator -> EXCLAMATION
Rule 246 unary_module_path_operator -> NEG
Rule 247 unary_module_path_operator -> AMPERSAND
Rule 248 unary_module_path_operator -> NEGAMPERSAND
Rule 249 unary_module_path_operator -> PIPE
Rule 250 unary_module_path_operator -> NEGPIPE
Rule 251 unary_module_path_operator -> CARET
Rule 252 unary_module_path_operator -> NEGCARET
Rule 253 binary_module_path_operator -> ISEQUAL
Rule 254 binary_module_path_operator -> NISEQUAL
Rule 255 binary_module_path_operator -> DOUBLEAMPERSAND
Rule 256 binary_module_path_operator -> DOUBLEPIPE
Rule 257 binary_module_path_operator -> AMPERSAND
Rule 258 binary_module_path_operator -> PIPE
Rule 259 binary_module_path_operator -> CARET
Rule 260 binary_module_path_operator -> NEGCARET
Rule 261 array_identifier -> identifier
Rule 262 block_identifier -> identifier
Rule 263 bin_identifier -> identifier
Rule 264 c_identifier -> C_ID
Rule 265 cell_identifier -> identifier
Rule 266 checker_identifier -> identifier
Rule 267 class_identifier -> identifier
Rule 268 class_variable_identifier -> variable_identifier
Rule 269 clocking_identifier -> identifier
Rule 270 config_identifier -> identifier
Rule 271 const_identifier -> identifier
Rule 272 constraint_identifier -> identifier
Rule 273 covergroup_identifier -> identifier
Rule 274 covergroup_variable_identifier -> variable_identifier
Rule 275 cover_point_identifier -> identifier
Rule 276 cross_identifier -> identifier
Rule 277 dynamic_array_variable_identifier -> variable_identifier
Rule 278 enum_identifier -> identifier
Rule 279 escaped_identifier -> ESCAPED_ID
Rule 280 formal_identifier -> identifier
Rule 281 formal_port_identifier -> identifier
Rule 282 function_identifier -> identifier
Rule 283 generate_block_identifier -> identifier
Rule 284 genvar_identifier -> identifier
Rule 285 hierarchical_array_identifier -> hierarchical_identifier
Rule 286 hierarchical_block_identifier -> hierarchical_identifier
Rule 287 hierarchical_event_identifier -> hierarchical_identifier
Rule 288 hierarchical_identifier -> optional_identifier_constant_bit_select_list identifier
Rule 289 hierarchical_identifier -> DOLLAR ROOT DOT optional_identifier_constant_bit_select_list identifier
Rule 290 hierarchical_net_identifier -> hierarchical_identifier
Rule 291 hierarchical_parameter_identifier -> hierarchical_identifier
Rule 292 hierarchical_property_identifier -> hierarchical_identifier
Rule 293 hierarchical_sequence_identifier -> hierarchical_identifier
Rule 294 hierarchical_task_identifier -> hierarchical_identifier
Rule 295 hierarchical_tf_identifier -> hierarchical_identifier
Rule 296 hierarchical_variable_identifier -> hierarchical_identifier
Rule 297 identifier -> simple_identifier
Rule 298 identifier -> escaped_identifier
Rule 299 index_variable_identifier -> identifier
Rule 300 interface_identifier -> identifier
Rule 301 interface_instance_identifier -> identifier
Rule 302 inout_port_identifier -> identifier
Rule 303 input_port_identifier -> identifier
Rule 304 instance_identifier -> identifier
Rule 305 library_identifier -> identifier
Rule 306 member_identifier -> identifier
Rule 307 method_identifier -> identifier
Rule 308 modport_identifier -> identifier
Rule 309 module_identifier -> identifier
Rule 310 net_identifier -> identifier
Rule 311 net_type_identifier -> identifier
Rule 312 output_port_identifier -> identifier
Rule 313 package_identifier -> identifier
Rule 314 package_scope -> package_identifier DOUBLECOLON
Rule 315 package_scope -> DOLLAR UNIT DOUBLECOLON
Rule 316 optional_package_scope -> package_scope
Rule 317 optional_package_scope -> empty
Rule 318 parameter_identifier -> identifier
Rule 319 port_identifier -> identifier
Rule 320 production_identifier -> identifier
Rule 321 program_identifier -> identifier
Rule 322 property_identifier -> identifier
Rule 323 ps_class_identifier -> optional_package_scope class_identifier
Rule 324 ps_covergroup_identifier -> optional_package_scope covergroup_identifier
Rule 325 ps_checker_identifier -> optional_package_scope checker_identifier
Rule 326 ps_identifier -> optional_package_scope identifier
Rule 327 ps_or_hierarchical_array_identifier -> optional_package_scope hierarchical_array_identifier
Rule 328 ps_or_hierarchical_array_identifier -> implicit_class_handle DOT hierarchical_array_identifier
Rule 329 ps_or_hierarchical_array_identifier -> class_scope hierarchical_array_identifier
Rule 330 ps_or_hierarchical_net_identifier -> optional_package_scope net_identifier
Rule 331 ps_or_hierarchical_net_identifier -> hierarchical_net_identifier
Rule 332 ps_or_hierarchical_property_identifier -> optionnal_package_scope property_identifier
Rule 333 ps_or_hierarchical_property_identifier -> hierarchical_property_identifier
Rule 334 ps_or_hierarchical_sequence_identifier -> optional_package_scope sequence_identifier
Rule 335 ps_or_hierarchical_sequence_identifier -> hierarchical_sequence_identifier
Rule 336 ps_or_hierarchical_tf_identifier -> optional_package_scope tf_identifier
Rule 337 ps_or_hierarchical_tf_identifier -> hierarchical_tf_identifier
Rule 338 ps_parameter_identifier -> optional_package_scope parameter_identifier
Rule 339 ps_parameter_identifier -> class_scope parameter_identifier
Rule 340 ps_parameter_identifier -> ps_parameter_identifier_generate_list parameter_identifier
Rule 341 ps_parameter_identifier_generate_list -> ps_parameter_identifier_generate_list DOT ps_parameter_identifier_generate
Rule 342 ps_parameter_identifier_generate_list -> ps_parameter_identifier_generate
Rule 343 ps_parameter_identifier_generate -> generate_block_identifier LBRACKET constant_expression RBRACKET
Rule 344 ps_parameter_identifier_generate -> generate_block_identifier
Rule 345 ps_type_identifier -> type_identifier
Rule 346 ps_type_identifier -> LOCAL DOUBLECOLON type_identifier
Rule 347 ps_type_identifier -> package_scope type_identifier
Rule 348 sequence_identifier -> identifier
Rule 349 signal_identifier -> identifier
Rule 350 simple_identifier -> ID
Rule 351 specparam_identifier -> identifier
Rule 352 system_tf_identifier -> DOLLAR ID
Rule 353 task_identifier -> identifier
Rule 354 tf_identifier -> identifier
Rule 355 terminal_identifier -> identifier
Rule 356 topmodule_identifier -> identifier
Rule 357 type_identifier -> identifier
Rule 358 udp_identifier -> identifier
Rule 359 variable_identifier -> identifier
Rule 360 cond_predicate -> AT
Rule 361 implicit_class_handle -> AT
Rule 362 integral_number -> AT
Rule 363 lifetime -> AT
Rule 364 list_of_interface_identifiers -> AT
Rule 365 list_of_port_declarations_list -> AT
Rule 366 list_of_port_identifiers -> AT
Rule 367 list_of_ports -> AT
Rule 368 list_of_variable_decl_assignments -> AT
Rule 369 list_of_variable_identifiers -> AT
Rule 370 module_item_list -> AT
Rule 371 module_path_primary -> AT
Rule 372 non_port_module_item -> AT
Rule 373 non_port_module_item_list -> AT
Rule 374 open_range_list -> AT
Rule 375 operator_assignment -> AT
Rule 376 optional_enum_name_declaration_list -> AT
Rule 377 optional_identifier_constant_bit_select_list -> AT
Rule 378 optional_modport_identifier -> AT
Rule 379 optional_packed_dimension -> AT
Rule 380 optional_packed_dimension_list -> AT
Rule 381 optional_parameter_value_assignment -> AT
Rule 382 optional_signing -> AT
Rule 383 optionnal_package_scope -> AT
Rule 384 package_import_declaration_list -> AT
Rule 385 parameter_port_list -> AT
Rule 386 primary -> AT
Rule 387 random_qualifier -> AT
Rule 388 struct_union_member_list -> AT
Rule 389 variable_lvalue -> AT
Rule 390 empty -> <empty>
In LR parsing, we often talk about "items": an item is a production with a progress marker, usually written with a • but sometimes with a simple .
在LR解析中,我们经常谈论“项目”:项目是具有进度标记的生产,通常用•写但有时用简单
.
. 。 A state is just a collection of items;
一个州只是一个项目的集合; in effect, the state tells you the set of productions the parse might be inside.
实际上,状态告诉你解析可能在里面的一组产生。
There is one particularly special type of item: the item with a dot at the end: 有一种特殊类型的项目:最后带点的项目:
(134) attribute_instance_optional_list -> attribute_instance_list .
This represents a production which could be finished, since the progress marker is at the end. 这表示可以完成的生产,因为进度标记结束。 If that is the correct production, the parser must then substitute the right-hand side for the left-hand side: this is the action referred to as "reducing" (since it is the opposite of "producing", which is what a "production" does).
如果这是正确的产品,则解析器必须将右侧替换为左侧:这是被称为“减少”的动作(因为它与“生产”相反,这就是“生产“确实”。
However, the mere fact that you are in a state with a possible reduction does not mean that the reduction is possible. 但是,您处于可能减少的状态这一事实并不意味着减少是可能的。 It is also necessary that the next token be consistent with the result of the reduction.
下一个标记也必须与减少的结果一致。 If the next token could not follow the reduced non-terminal (in the context of the parser's state), then the reduction cannot be performed, so the parser will attempt a shift if one is possible.
如果下一个令牌不能跟随缩减的非终端(在解析器的状态的上下文中),则无法执行缩减,因此如果可能的话,解析器将尝试移位。
Shifts are really simple. 转移非常简单。 A shift is possible if one or more items in the state have the dot before the current lookahead symbol.
如果状态中的一个或多个项目在当前先行符号之前具有点,则可以进行移位。 Here, there is no question about additional lookahead because Ply (like many LALR parser generators) only creates LALR(1) parsers which only have a single lookahead in any state, so the only thing we have to go on is the symbol we are currently looking at, and it is reasonably obvious that we can only process it if some available item has that symbol in the next position.
在这里,没有关于额外前瞻的问题,因为Ply(像许多LALR解析器生成器一样)只创建LALR(1)解析器,它在任何状态下只有一个前瞻,所以我们唯一要做的就是我们当前的符号看着,显而易见的是,如果某个可用项目在下一个位置具有该符号,我们只能处理它。
If a given state with a given lookahead symbol can both shift and reduce, then you have a shift-reduce conflict; 如果具有给定前瞻符号的给定状态可以移位和减少,那么您就会发生移位减少冲突; the parser doesn't know what to do.
解析器不知道该怎么做。 (If it has neither a shift nor a reduce available, that indicates that the input has a syntax error. That's how LR parsers identify syntax errors.)
(如果它既没有shift也没有reduce可用,则表示输入有语法错误。这就是LR解析器识别语法错误的方式。)
The one important aspect of LR parsing is that a reduction must be performed immediately if it is going to be performed at all. LR解析的一个重要方面是,如果要进行简化,则必须立即执行缩减。 That is, if we are in a state with a possible reduction, and the item's lookahead set indicates that the lookahead character is feasible, we must perform the reduction.
也就是说,如果我们处于可能减少的状态,并且项目的前瞻设置表明前瞻字符是可行的,我们必须执行减少。 We can't wait and see if it would be possible later, because there is no later for a reduction.
我们不能等待,看看以后是否可能,因为没有后来的减少。 In other words, anything to the left of the • in an item has already been reduced as much as it could be.
换句话说,项目左侧的任何内容都已尽可能减少。 (This is the
R
in LR
parsing, which indicates that every reduction is "rightmost". If the use of "rightmost" doesn't make sense, don't worry about it; I only mentioned this fact in case you were wondering.) (这是
LR
解析中的R
,表示每次缩减都是“最右边”。如果使用“最右边”没有意义,请不要担心;我只是在你想知道的情况下才提到这个事实。 )
Another thing which I might as well mention is that in LALR parsing ("Lookahead LR parsing"), a state is precisely defined by the set of items. 我还要提到的另一件事是在LALR解析(“Lookahead LR解析”)中,状态由项集合精确定义。 Each item has an applicable lookahead set, but the lookahead sets don't form part of the state's identity.
每个项目都有一个适用的前瞻集,但前瞻集不构成该州身份的一部分。 If the parser generator ends up producing two states with the same items but different lookahead sets, it must merge them into a single state, forming the union of each lookahead set.
如果解析器生成器最终生成具有相同项但具有不同前瞻集的两个状态,则它必须将它们合并为单个状态,从而形成每个前瞻集的并集。 For full LR parsing, this limitation doesn't exist;
对于完整的LR解析,此限制不存在; you can (and do) have more than one state for a given set of items, and the result is that the parsing table is much larger and slightly more powerful.
你可以(做)有一个以上的状态对于一个给定的项目,其结果是,分析表大得多及略微更强大。
Now, if a shift action is possible, you can mechanically figure out which state will be active after the shift. 现在,如果可以进行换档操作,您可以机械地确定换班后哪个状态将处于活动状态。 For example, from
例如,来自
(134) attribute_instance_optional_list -> attribute_instance_list .
(136) attribute_instance_list -> attribute_instance_list . attribute_instance
(138) attribute_instance -> . LPAREN ASTERISK attr_spec_list ASTERISK RPAREN
after shifting an LPAREN
, the next state will have just one item: 在转移
LPAREN
,下一个状态将只有一个项目:
(138) attribute_instance -> LPAREN . ASTERISK attr_spec_list ASTERISK RPAREN
(Note how the dot has moved.) (注意点的移动方式。)
That was a simple case, since the next symbol is a terminal, ASTERISK
. 这是一个简单的案例,因为下一个符号是终端,
ASTERISK
。 Most of the time, the next symbol after a shift will be a non-terminal, and in that case we need to add all of the productions for that non-terminal, with the dot at the beginning. 大多数情况下,移位后的下一个符号将是非终端,在这种情况下,我们需要为该非终端添加所有产品,并在开头添加点。 (That's how states end up with more than one item.) So, for example, given the new state with one item and an input of
ASTERISK
(anything else will be an error, since this state has no reduction possibilities), then we will shift into a state which has the shifted item: (这就是状态最终会出现多个项目的情况。)所以,例如,给定一个项目的新状态和
ASTERISK
的输入(其他任何东西都是错误,因为这个状态没有减少的可能性),那么我们将转入具有转移项目的状态:
(138) attribute_instance -> LPAREN ASTERISK . attr_spec_list ASTERISK RPAREN
plus all the productions for attr_spec_list
: 加上
attr_spec_list
所有产品:
(139) attr_spec_list -> . attr_spec_list COMMA attr_spec
(140) attr_spec_list -> . attr_spec
plus all the productions for attr_spec
(since we just added an item with the dot before attr_spec
): 加上
attr_spec
所有产品(因为我们在attr_spec
之前添加了一个带有点的项目):
(141) attr_spec -> . attr_name
(142) attr_spec -> . attr_name EQUALS constant_expression
plus the production for attr_name
: 加上
attr_name
的制作:
(143) attr_name -> . identifier
and so on until we stop seeing new non-terminals: 等等,直到我们停止看到新的非终端:
(297) identifier -> . simple_identifier
(298) identifier -> . escaped_identifier
(350) simple_identifier -> . ID
(279) escaped_identifier -> . ESCAPED_ID
OK, now the next token will have to be ID
or ESCAPED_ID
. 好的,现在下一个标记必须是
ID
或ESCAPED_ID
。 Suppose it is ID
. 假设它是
ID
。 Now what? 怎么办? Well, we will shift into a state
好吧,我们将转变为一个州
(350) simple_identifier -> ID .
with a possible reduction; 可能减少; assuming the lookahead symbol matches the lookahead set (I haven't and don't intend to explain how lookahead sets are computed for each state; there's an algorithm but its details aren't relevant here), then the
ID
will be reduced to simple_identifier
. 假设前瞻符号与前瞻集匹配(我没有也不打算解释如何为每个状态计算先行集;有一个算法,但其细节在这里不相关),那么
ID
将简化为simple_identifier
。 Then where does the parser go? 然后解析器去哪里了? Logically, it goes back to the state which generated the
simple_identifier
production, and shift the simple_identifier
. 逻辑上,它返回到生成
simple_identifier
生成的状态,并移动simple_identifier
。 As it happens, the state is the one we just created 碰巧,状态就是我们刚创造的状态
(138) attribute_instance -> LPAREN ASTERISK . attr_spec_list ASTERISK RPAREN
(139) attr_spec_list -> . attr_spec_list COMMA attr_spec
(140) attr_spec_list -> . attr_spec
(141) attr_spec -> . attr_name
(142) attr_spec -> . attr_name EQUALS constant_expression
(143) attr_name -> . identifier
(297) identifier -> . simple_identifier
(298) identifier -> . escaped_identifier
(350) simple_identifier -> . ID
(279) escaped_identifier -> . ESCAPED_ID
and after we shift the simple_identifier
, we end up with 在我们移动
simple_identifier
,我们最终得到了
(297) identifier -> simple_identifier .
which is a state which requires a reduction to identifier
, so once again back to the same state after which we find ourselves in 这是一个需要减少
identifier
,所以再次回到我们发现自己的同一状态
(143) attr_name -> identifier .
and then 然后
(141) attr_spec -> attr_name .
(142) attr_spec -> attr_name . EQUALS constant_expression
But how did the parser know which state to go back to on each of those reductions? 但是,解析器是如何知道每次减少哪个状态? The answer is that the parser pushes the current state onto the parsing stack with every symbol .
答案是解析器将每个符号将当前状态推送到解析堆栈。 When it does a reduction, it pops the symbols from the right-hand side, discarding each associated state number, until it gets to the beginning of the right-hand-side, at which point the stack indicates which state that right-hand side came from.
当它进行缩小时,它会从右侧弹出符号,丢弃每个相关的状态编号,直到它到达右侧的开头,此时堆栈指示右侧的哪个状态来自。 It then takes a look at that state, shifts the reduced non-terminal, and pushes the new shifted state onto the parse stack.
然后,它会查看该状态,移动缩减的非终端,并将新的移位状态推送到解析堆栈。
So I think that answers the questions "What do the lines at the beginning of the state description mean?" 所以我认为这回答了问题“状态描述开头的界限是什么意思?” and "What state does the parser go to after a reduction?"
和“解析器在减少后会进入什么状态?” The other two questions are easy to answer: "No, it doesn't compute all the possible predecessor states", and "Yes, it could (although it might end up adding predecessors which are actually not possible with any input) but it isn't useful for the parse."
另外两个问题很容易回答:“不,它不会计算所有可能的前任状态”,并且“是的,它可以(虽然它可能最终会添加实际上不可能通过任何输入实现的前任)但它不是这对解析很有用。“ but since they're not horribly relevant to solving the shift-reduce conflict, I won't explain the answer further.
但由于它们与解决转移 - 减少冲突并不是非常相关,我不会进一步解释答案。
Going back to the actual shift-reduce conflict, the situation is that we are in the state 回到实际的转移 - 减少冲突,情况是我们处于状态
(134) attribute_instance_optional_list -> attribute_instance_list .
(136) attribute_instance_list -> attribute_instance_list . attribute_instance
(138) attribute_instance -> . LPAREN ASTERISK attr_spec_list ASTERISK RPAREN
which has a possible reduction, and we are considering the case where we see an LPAREN
, for which there is a possible shift, and it turns out that the lookahead set for the first item also include LPAREN
. 可能会减少,我们正在考虑我们看到
LPAREN
的情况,有可能发生转变,事实证明第一项的前瞻设置也包括LPAREN
。 Although the lookahead set is not shown in the PLY output, we can dig around in the grammar to see where it might have come from. 虽然先行集未显示在PLY输出中,但我们可以在语法中挖掘它以查看它可能来自何处。 The immediate source is
attribute_instance_optional_list
, of course, and we can find that in the grammar,although there are quite a few possibilities: 当然,直接来源是
attribute_instance_optional_list
,我们可以在语法中找到它,尽管有很多可能性:
(27) module_nonansi_header -> attribute_instance_optional_list module_keyword lifetime module_identifier package_import_declaration_list parameter_port_list list_of_ports SEMICOLON
(28) module_ansi_header -> attribute_instance_optional_list module_keyword lifetime module_identifier package_import_declaration_list parameter_port_list list_of_port_declarations_list SEMICOLON
(29) module_implicit_header -> attribute_instance_optional_list module_keyword lifetime module_identifier LPAREN DOT ASTERISK RPAREN SEMICOLON
(36) port_declaration -> attribute_instance_optional_list inout_declaration
(37) port_declaration -> attribute_instance_optional_list input_declaration
(38) port_declaration -> attribute_instance_optional_list output_declaration
(39) port_declaration -> attribute_instance_optional_list ref_declaration
(40) port_declaration -> attribute_instance_optional_list interface_port_declaration
(125) struct_union_member -> attribute_instance_optional_list data_type_or_void list_of_variable_decl_assignments
(126) struct_union_member -> attribute_instance_optional_list random_qualifier data_type_or_void list_of_variable_decl_assignments
(144) inc_or_dec_expression -> inc_or_dec_operator attribute_instance_optional_list variable_lvalue
(145) inc_or_dec_expression -> variable_lvalue attribute_instance_optional_list inc_or_dec_operator
(146) conditional_expression -> cond_predicate INTERROGATION attribute_instance_optional_list expression COLON expression
(148) constant_expression -> unary_operator attribute_instance_optional_list constant_primary
(149) constant_expression -> constant_expression binary_operator attribute_instance_optional_list constant_expression
(150) constant_expression -> constant_expression INTERROGATION attribute_instance_optional_list constant_expression COLON constant_expression
(167) expression -> unary_operator attribute_instance_optional_list primary
(170) expression -> expression binary_operator attribute_instance_optional_list expression
(181) module_path_conditional_expression -> module_path_expression INTERROGATION attribute_instance_optional_list module_path_expression COLON module_path_expression
(183) module_path_expression -> unary_module_path_operator attribute_instance_optional_list module_path_primary
(184) module_path_expression -> module_path_expression binary_module_path_operator attribute_instance_optional_list module_path_expression
As far as I can see, attribute_instance_optional_list
does not appear at the end of any of those productions, which simplifies working out where the LPAREN
conflict comes from. 据我所知,
attribute_instance_optional_list
没有出现在任何这些产品的末尾,这简化了LPAREN
冲突来源的工作。 In all those cases, it is followed by a non-terminal, the possibilities being: 在所有这些情况下,其后是非终端,可能性为:
module_keyword
inout_declaration
input_declaration
output_declaration
ref_declaration
interface_port_declaration
data_type_or_void
random_qualifier
variable_lvalue
inc_or_dec_operator
constant_primary
constant_expression
primary
expression
module_path_primary
module_path_expression
Now, if any of those non-terminals could start with an LPAREN
, we have a possible shift-reduce conflict. 现在,如果这些非终端中的任何一个可以从
LPAREN
开始,我们就有可能的shift-reduce冲突。 And a couple of culprits spring out of the list: expression
and similar. 一些罪魁祸首从名单中脱颖而出:
expression
和类似。
So, there is the problem, in summary: an attribute_instance
can start with a parenthesis, but an attribute_instance_list
can also be followed by a parenthesis. 因此,总的来说存在问题:
attribute_instance
可以以括号开头,但attribute_instance_list
也可以后跟括号。 So when you're in the middle of an attribute_instance_list and you see a ( , you have no way of knowing whether to shift or reduce. 因此,当您处于attribute_instance_list的中间并且您看到(您无法知道是要转移还是减少时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.