forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 2
/
verilog.y
8559 lines (8221 loc) · 280 KB
/
verilog.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2017-2020 The Verible Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%code requires{
#include "common/parser/parser_param.h"
}
%{
/**
verilog.y
yacc/bison LR(1) grammar for SystemVerilog.
The syntax tree constructed by the semantic actions in this file are
fragile and subject to change without notice.
Functionality that relies directly on this structure should be isolated under
//verilog/CST/... (concrete syntax tree) and unit-tested accordingly.
**/
#include <utility>
#include "common/parser/bison_parser_common.h"
#include "common/text/tree_utils.h"
#include "common/util/casts.h"
#include "common/util/logging.h"
#include "verilog/CST/declaration.h"
#include "verilog/CST/DPI.h"
#include "verilog/CST/expression.h"
#include "verilog/CST/functions.h"
#include "verilog/CST/module.h"
#include "verilog/CST/parameters.h"
#include "verilog/CST/port.h"
#include "verilog/CST/type.h"
#include "verilog/CST/verilog_nonterminals.h"
#include "verilog/CST/verilog_treebuilder_utils.h"
/***
* Verilog Language Standard (IEEE 1364-2005):
* http://ieeexplore.ieee.org/xpl/mostRecentIssue.jsp?punumber=10779
*
* System Verilog (IEEE 1800-2017):
* https://standards.ieee.org/standard/1800-2017.html
* This is the Language Reference Manual, or LRM.
*
* Verilog-AMS:
* http://www.accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf
*
* System Verilog Assertions:
* http://www.eecs.umich.edu/courses/eecs578/eecs578.f15/miniprojects/SVAproject/manuals/SVA_manual.pdf
* http://vlsi.pro/sva-sequences-other-operators/
**/
namespace verilog {
using verible::ParserParam;
using verible::MakeNode;
using verible::MakeTaggedNode;
using verible::ExtendNode;
using verible::ForwardChildren;
using verible::SetChild;
using verible::SymbolCastToNode;
using verible::SymbolPtr;
using verible::SyntaxTreeNode;
using verible::down_cast;
using N = NodeEnum;
constexpr std::nullptr_t qualifier_placeholder = nullptr;
constexpr std::nullptr_t expression_placeholder = nullptr;
static std::nullptr_t Recover() {
// TODO(fangism): return a useful ErrorNode or ErrorToken, using the
// most recent recovered error token in the ParserParam.
return nullptr;
}
// Transforms:
// (sublist, separator), item -> sublist +separator +item
// TODO(fangism): if generally useful, factor into concrete_syntax_tree.h
static SymbolPtr ExtendFirstSublist(SymbolPtr& pair, SymbolPtr item) {
// pair node is a 2-tuple (sublist, separator),
// where sublist is a SyntaxTreeNode.
auto& pair_node = down_cast<SyntaxTreeNode&>(*pair);
auto& sublist = pair_node[0];
auto& separator = pair_node[1];
return ExtendNode(sublist, separator, item);
}
// Transforms:
// (..., sublist), item -> (..., sublist +item)
static SymbolPtr ExtendLastSublist(SymbolPtr& list, SymbolPtr& item) {
auto& list_node = down_cast<SyntaxTreeNode&>(*list);
auto& last_sublist = down_cast<SyntaxTreeNode&>(
*list_node.mutable_children().back());
last_sublist.Append(std::move(item));
return std::move(list);
}
// Transforms:
// ((..., sublist), separator), item -> (..., sublist +separator +item)
static SymbolPtr ExtendLastSublistWithSeparator(
SymbolPtr& pair, SymbolPtr& item) {
auto& pair_node = down_cast<SyntaxTreeNode&>(*pair);
auto& list = pair_node[0];
auto& separator = pair_node[1];
/* Extend the last sublist. */
auto& list_node = down_cast<SyntaxTreeNode&>(*list);
auto& sublist_node = down_cast<SyntaxTreeNode&>(
*list_node.mutable_children().back());
sublist_node.Append(std::move(separator), std::move(item));
return std::move(list);
}
// (Below): These helper forwarding functions help ensure consistent structure,
// and check that the correct number of arguments are passed:
static SymbolPtr MakePackedDimensionsNode(SymbolPtr& arg) {
return MakeTaggedNode(N::kPackedDimensions, arg);
}
static SymbolPtr MakeUnpackedDimensionsNode(SymbolPtr& arg) {
return MakeTaggedNode(N::kUnpackedDimensions, arg);
}
%}
%debug
%verbose
%expect 0
%define api.pure
%param { ::verible::ParserParam* param }
/* TODO(fangism): this prefix name should point to an adaptation of yylex */
%define api.prefix {verilog_}
%define api.value.type {::verible::SymbolPtr}
// The string representation of this token changes between bison versions.
// Fix it to keep unit tests happy that look for this string.
%token yyToken_EOF 0 "end of file"
// LINT.IfChange
%token PP_Identifier
%token PP_include "`include"
%token PP_define "`define"
%token PP_define_body "<<`define-tokens>>"
%token PP_ifdef "`ifdef"
%token PP_ifndef "`ifndef"
/* `if doesn't exist for Verilog */
%token PP_else "`else"
%token PP_elsif "`elsif"
%token PP_endif "`endif"
%token PP_undef "`undef"
%token PP_default_text "<<default-text>>"
%token PP_TOKEN_CONCAT "``"
%token DR_timescale "`timescale"
%token DR_resetall "`resetall"
%token DR_celldefine "`celldefine"
%token DR_endcelldefine "`endcelldefine"
%token DR_unconnected_drive "`unconnected_drive"
%token DR_nounconnected_drive "`nounconnected_drive"
%token DR_default_nettype "`default_nettype"
%token DR_suppress_faults "`suppress_faults"
%token DR_nosuppress_faults "`nosuppress_faults"
%token DR_enable_portfaults "`enable_portfaults"
%token DR_disable_portfaults "`disable_portfaults"
%token DR_delay_mode_distributed "`delay_mode_distributed"
%token DR_delay_mode_path "`delay_mode_path"
%token DR_delay_mode_unit "`delay_mode_unit"
%token DR_delay_mode_zero "`delay_mode_zero"
%token DR_default_decay_time "`default_decay_time"
%token DR_default_trireg_strength "`default_trireg_strength"
%token DR_pragma "`pragma"
%token DR_uselib "`uselib"
%token DR_begin_keywords "`begin_keywords"
%token DR_end_keywords "`end_keywords"
%token DR_protect "`protect"
%token DR_endprotect "`endprotect"
/**
The grammar in the SystemVerilog LRM is written in terms of type-specific
identifiers, like module_identifier and class_identifier, however,
without preprocessing, we cannot know the type of an identifier that
is not locally defined, so the grammar here uses only generic identifiers.
**/
// gen_tokenizer annotations existed in the original verilog.y grammar
// which was a way to generate a syntax highlighter.
// TODO(fangism): Remove these if they are not useful.
// gen_tokenizer start IDENTIFIER
%token SymbolIdentifier // encapsulates all of the above
%token EscapedIdentifier // starts with \ and ends with whitespace
%token SystemTFIdentifier // $identifier
%token MacroIdentifier // `identifier
%token MacroCallId
%token MacroIdItem
%token MacroNumericWidth
// gen_tokenizer stop
// gen_tokenizer start NUMERIC_LITERAL
%token TK_DecNumber // DEC_NUMBER
%token TK_RealTime // REALTIME
%token TK_TimeLiteral // TIME_LITERAL
%token TK_DecBase
%token TK_DecDigits
%token TK_XZDigits
%token TK_BinBase
%token TK_BinDigits
%token TK_OctBase
%token TK_OctDigits
%token TK_HexBase
%token TK_HexDigits
%token TK_UnBasedNumber // UNBASED_NUMBER
// gen_tokenizer stop
// gen_tokenizer start STRING_LITERAL
%token TK_StringLiteral // STRING
%token TK_EvalStringLiteral // STRING
%token TK_AngleBracketInclude // STRING
// gen_tokenizer stop
// gen_tokenizer start KEYWORD
/* The base tokens from 1364-1995. */
%token TK_1step "1step"
%token TK_always "always"
%token TK_and "and"
%token TK_assign "assign"
%token TK_begin "begin"
%token TK_buf "buf"
%token TK_bufif0 "bufif0"
%token TK_bufif1 "bufif1"
%token TK_case "case"
%token TK_casex "casex"
%token TK_casez "casez"
%token TK_cmos "cmos"
%token TK_deassign "deassign"
%token TK_default "default"
%token TK_defparam "defparam"
%token TK_disable "disable"
%token TK_edge "edge"
%token TK_else "else"
%token TK_end "end"
%token TK_endcase "endcase"
%token TK_endfunction "endfunction"
%token TK_endmodule "endmodule"
%token TK_endprimitive "endprimitive"
%token TK_endspecify "endspecify"
%token TK_endtable "endtable"
%token TK_endtask "endtask"
%token TK_event "event"
%token TK_for "for"
%token TK_force "force"
%token TK_forever "forever"
%token TK_fork "fork"
%token TK_function "function"
%token TK_highz0 "highz0"
%token TK_highz1 "highz1"
%token TK_if "if"
%token TK_ifnone "ifnone"
%token TK_initial "initial"
%token TK_inout "inout"
%token TK_input "input"
%token TK_integer "integer"
%token TK_join "join"
%token TK_large "large"
%token TK_macromodule "macromodule"
%token TK_medium "medium"
%token TK_module "module"
%token TK_nand "nand"
%token TK_negedge "negedge"
%token TK_nmos "nmos"
%token TK_nor "nor"
%token TK_not "not"
%token TK_notif0 "notif0"
%token TK_notif1 "notif1"
%token TK_or "or"
%token TK_option "option"
%token TK_output "output"
%token TK_parameter "parameter"
%token TK_pmos "pmos"
%token TK_posedge "posedge"
%token TK_primitive "primitive"
%token TK_pull0 "pull0"
%token TK_pull1 "pull1"
%token TK_pulldown "pulldown"
%token TK_pullup "pullup"
%token TK_rcmos "rcmos"
%token TK_real "real"
%token TK_realtime "realtime"
%token TK_reg "reg"
%token TK_release "release"
%token TK_repeat "repeat"
%token TK_rnmos "rnmos"
%token TK_rpmos "rpmos"
%token TK_rtran "rtran"
%token TK_rtranif0 "rtranif0"
%token TK_rtranif1 "rtranif1"
%token TK_sample "sample"
%token TK_scalared "scalared"
%token TK_small "small"
%token TK_specify "specify"
%token TK_specparam "specparam"
%token TK_strong0 "strong0"
%token TK_strong1 "strong1"
%token TK_supply0 "supply0"
%token TK_supply1 "supply1"
%token TK_table "table"
%token TK_task "task"
%token TK_time "time"
%token TK_tran "tran"
%token TK_tranif0 "tranif0"
%token TK_tranif1 "tranif1"
%token TK_tri "tri"
%token TK_tri0 "tri0"
%token TK_tri1 "tri1"
%token TK_triand "triand"
%token TK_trior "trior"
%token TK_trireg "trireg"
%token TK_type_option "type_option"
%token TK_vectored "vectored"
%token TK_wait "wait"
%token TK_wand "wand"
%token TK_weak0 "weak0"
%token TK_weak1 "weak1"
%token TK_while "while"
%token TK_wire "wire"
%token TK_wor "wor"
%token TK_xnor "xnor"
%token TK_xor "xor"
%token TK_Shold "$hold"
%token TK_Snochange "$nochange"
%token TK_Speriod "$period"
%token TK_Srecovery "$recovery"
%token TK_Ssetup "$setup"
%token TK_Ssetuphold "$setuphold"
%token TK_Sskew "$skew"
%token TK_Swidth "$width"
/* Icarus specific tokens. */
%token TKK_attribute "$attribute"
/* The new tokens from 1364-2001. */
%token TK_automatic "automatic"
%token TK_endgenerate "endgenerate"
%token TK_generate "generate"
%token TK_genvar "genvar"
%token TK_localparam "localparam"
%token TK_noshowcancelled "noshowcancelled"
%token TK_pulsestyle_onevent "pulsestyle_onevent"
%token TK_pulsestyle_ondetect "pulsestyle_ondetect"
%token TK_showcancelled "showcancelled"
%token TK_signed "signed"
%token TK_unsigned "unsigned"
%token TK_Sfullskew "$fullskew"
%token TK_Srecrem "$recrem"
%token TK_Sremoval "$removal"
%token TK_Stimeskew "$timeskew"
/* The 1364-2001 configuration tokens. */
%token TK_cell "cell"
%token TK_config "config"
%token TK_design "design"
%token TK_endconfig "endconfig"
%token TK_incdir "incdir"
%token TK_include "include"
%token TK_instance "instance"
%token TK_liblist "liblist"
%token TK_library "library"
%token TK_use "use"
/* The new tokens from 1364-2005. */
%token TK_wone "wone"
%token TK_uwire "uwire"
/* The new tokens from 1800-2005. */
%token TK_alias "alias"
%token TK_always_comb "always_comb"
%token TK_always_ff "always_ff"
%token TK_always_latch "always_latch"
%token TK_assert "assert"
%token TK_assume "assume"
%token TK_before "before"
%token TK_bind "bind"
%token TK_bins "bins"
%token TK_binsof "binsof"
%token TK_bit "bit"
%token TK_break "break"
%token TK_byte "byte"
%token TK_chandle "chandle"
%token TK_class "class"
%token TK_clocking "clocking"
%token TK_const "const"
%token TK_constraint "constraint"
%token TK_context "context"
%token TK_continue "continue"
%token TK_cover "cover"
%token TK_covergroup "covergroup"
%token TK_coverpoint "coverpoint"
%token TK_cross "cross"
%token TK_dist "dist"
%token TK_do "do"
%token TK_endclass "endclass"
%token TK_endclocking "endclocking"
%token TK_endgroup "endgroup"
%token TK_endinterface "endinterface"
%token TK_endpackage "endpackage"
%token TK_endprogram "endprogram"
%token TK_endproperty "endproperty"
%token TK_endsequence "endsequence"
%token TK_enum "enum"
%token TK_expect "expect"
%token TK_export "export"
%token TK_extends "extends"
%token TK_extern "extern"
%token TK_final "final"
%token TK_first_match "first_match"
%token TK_foreach "foreach"
%token TK_forkjoin "forkjoin"
%token TK_iff "iff"
%token TK_ignore_bins "ignore_bins"
%token TK_illegal_bins "illegal_bins"
%token TK_import "import"
%token TK_inside "inside"
%token TK_int "int"
%token TK_interface "interface"
%token TK_intersect "intersect"
%token TK_join_any "join_any"
%token TK_join_none "join_none"
%token TK_local "local"
%token TK_local_SCOPE "local::"
%token TK_logic "logic"
%token TK_longint "longint"
%token TK_matches "matches"
%token TK_modport "modport"
%token TK_new "new"
%token TK_null "null"
%token TK_package "package"
%token TK_packed "packed"
%token TK_priority "priority"
%token TK_program "program"
%token TK_property "property"
%token TK_protected "protected"
%token TK_pure "pure"
%token TK_rand "rand"
%token TK_randc "randc"
%token TK_randcase "randcase"
%token TK_randsequence "randsequence"
%token TK_randomize "randomize"
%token TK_ref "ref"
%token TK_return "return"
%token TK_Sroot "$root"
%token TK_sequence "sequence"
%token TK_shortint "shortint"
%token TK_shortreal "shortreal"
%token TK_solve "solve"
%token TK_static "static"
%token TK_string "string"
%token TK_struct "struct"
%token TK_super "super"
%token TK_tagged "tagged"
%token TK_this "this"
%token TK_throughout "throughout"
%token TK_timeprecision "timeprecision"
%token TK_timeunit "timeunit"
%token TK_timescale_unit "(timescale_unit)"
%token TK_type "type"
%token TK_typedef "typedef"
%token TK_union "union"
%token TK_unique "unique"
%token TK_unique_index "unique_index"
%token TK_Sunit "$unit"
%token TK_var "var"
%token TK_virtual "virtual"
%token TK_void "void"
%token TK_wait_order "wait_order"
%token TK_wildcard "wildcard"
%token TK_with "with"
%token TK_with__covergroup "with(covergroup)"
%token TK_within "within"
/* Fake tokens that are passed once we have an initial token. */
%token TK_timeprecision_check "timeprecision_check"
/* The new tokens from 1800-2009. */
%token TK_timeunit_check "timeunit_check"
%token TK_accept_on "accept_on"
%token TK_checker "checker"
%token TK_endchecker "endchecker"
%token TK_eventually "eventually"
%token TK_global "global"
%token TK_implies "implies"
%token TK_let "let"
%token TK_nexttime "nexttime"
%token TK_reject_on "reject_on"
%token TK_restrict "restrict"
%token TK_s_always "s_always"
%token TK_s_eventually "s_eventually"
%token TK_s_nexttime "s_nexttime"
%token TK_s_until "s_until"
%token TK_s_until_with "s_until_with"
%token TK_strong "strong"
%token TK_sync_accept_on "sync_accept_on"
%token TK_sync_reject_on "sync_reject_on"
%token TK_unique0 "unique0"
%token TK_until "until"
%token TK_until_with "until_with"
%token TK_untyped "untyped"
%token TK_weak "weak"
/* The new tokens from 1800-2012. */
%token TK_implements "implements"
%token TK_interconnect "interconnect"
%token TK_nettype "nettype"
%token TK_soft "soft"
%token TK_absdelay "absdelay"
%token TK_abstol "abstol"
%token TK_access "access"
%token TK_ac_stim "ac_stim"
%token TK_aliasparam "aliasparam"
%token TK_analog "analog"
%token TK_analysis "analysis"
%token TK_connect "connect"
%token TK_connectmodule "connectmodule"
%token TK_connectrules "connectrules"
%token TK_continuous "continuous"
%token TK_ddt_nature "ddt_nature"
%token TK_discipline "discipline"
%token TK_discrete "discrete"
%token TK_domain "domain"
%token TK_driver_update "driver_update"
%token TK_endconnectrules "endconnectrules"
%token TK_enddiscipline "enddiscipline"
%token TK_endnature "endnature"
%token TK_endparamset "endparamset"
%token TK_exclude "exclude"
%token TK_flicker_noise "flicker_noise"
%token TK_flow "flow"
%token TK_from "from"
%token TK_idt_nature "idt_nature"
%token TK_inf "inf"
%token TK_infinite "infinite" /* `default_decay_time argument */
%token TK_laplace_nd "laplace_nd"
%token TK_laplace_np "laplace_np"
%token TK_laplace_zd "laplace_zd"
%token TK_laplace_zp "laplace_zp"
%token TK_last_crossing "last_crossing"
%token TK_limexp "limexp"
%token TK_max "max"
%token TK_min "min"
%token TK_nature "nature"
%token TK_net_resolution "net_resolution"
%token TK_noise_table "noise_table"
%token TK_paramset "paramset"
%token TK_potential "potential"
%token TK_pow "pow"
%token TK_resolveto "resolveto"
%token TK_transition "transition"
%token TK_units "units"
%token TK_white_noise "white_noise"
%token TK_wreal "wreal"
%token TK_zi_nd "zi_nd"
%token TK_zi_np "zi_np"
%token TK_zi_zd "zi_zd"
%token TK_zi_zp "zi_zp"
// built-in methods
%token TK_find "find"
%token TK_find_index "find_index"
%token TK_find_first "find_first"
%token TK_find_first_index "find_first_index"
%token TK_find_last "find_last"
%token TK_find_last_index "find_last_index"
%token TK_sort "sort"
%token TK_rsort "rsort"
%token TK_reverse "reverse"
%token TK_shuffle "shuffle"
%token TK_sum "sum"
%token TK_product "product"
// gen_tokenizer stop
// operator tokens
%token TK_PLUS_EQ "+="
%token TK_MINUS_EQ "-="
%token TK_MUL_EQ "*="
%token TK_DIV_EQ "/="
%token TK_MOD_EQ "%="
%token TK_AND_EQ "&="
%token TK_OR_EQ "|="
%token TK_XOR_EQ "^="
%token TK_INCR "++"
%token TK_DECR "--"
// TODO(b/63595640): Disambiguate between use as less-equal,
// nonblocking_assignment, and clocking_drive.
%token TK_LE "<="
%token TK_GE ">="
%token TK_EG "=>"
%token TK_EQ "=="
%token TK_WILDCARD_EQ "==?"
%token TK_NE "!="
%token TK_WILDCARD_NE "!=?"
%token TK_CEQ "==="
%token TK_CNE "!=="
%token TK_LP "'{"
%token TK_LS "<<"
// or "<<<"
%token TK_RS ">>"
%token TK_RSS ">>>"
%token TK_SG "*>"
%token TK_CONTRIBUTE "<+"
%token TK_PO_POS "+:"
%token TK_PO_NEG "-:"
%token TK_POW "**"
%token TK_PSTAR "(*"
%token TK_STARP "*)"
%token TK_DOTSTAR ".*"
%token TK_LOR "||"
%token TK_LAND "&&"
%token TK_TAND "&&&"
%token TK_NAND "~&"
%token TK_NOR "~|"
%token TK_NXOR "~^"
// or "^~"
%token TK_LOGEQUIV "<->"
%token TK_NONBLOCKING_TRIGGER "->>"
%token _TK_RARROW "->"
// _TK_RARROW is disambiguated into one of the following symbols
// (see verilog_lexical_context.cc):
%token TK_TRIGGER "->(trigger)"
%token TK_LOGICAL_IMPLIES "->(logical-implies)"
%token TK_CONSTRAINT_IMPLIES "->(constraint-implies)"
%token TK_SCOPE_RES "::"
%token TK_COLON_EQ ":="
%token TK_COLON_DIV ":/"
%token TK_POUNDPOUND "##"
%token TK_edge_descriptor
%token TK_LBSTARRB "[*]"
%token TK_LBPLUSRB "[+]"
%token TK_LBSTAR "[*"
%token TK_LBEQ "[="
%token TK_LBRARROW "[->"
%token TK_PIPEARROW "|->"
%token TK_PIPEARROW2 "|=>"
%token TK_POUNDMINUSPOUND "#-#"
%token TK_POUNDEQPOUND "#=#"
%token TK_ATAT "@@"
%token MacroArg
%token MacroCallCloseToEndLine
/* These token types exist for the lexer, but are not used in this parser. */
// The ∗ escaping is needed here because Bison 3.5.91+ puts the string
// literal in a block comment in the generated parser, and the "*/" in the
// literal causes the block comment to end prematurely and causes a syntax
// error. Note that this literal does not affect the grammar in any way.
%token TK_COMMENT_BLOCK "/∗comment∗/"
%token TK_EOL_COMMENT "// end of line comment"
%token TK_SPACE "<<space>>" /* includes tabs */
%token TK_NEWLINE "<<\\n>>"
%token TK_LINE_CONT "<<\\line-cont>>"
%token TK_ATTRIBUTE "(*attribute*)"
%token TK_FILEPATH "<<filepath>>"
/* hack: artificial markers to switch to a different syntax mode */
%token PD_LIBRARY_SYNTAX_BEGIN "`____verible_verilog_library_begin____"
%token PD_LIBRARY_SYNTAX_END "`____verible_verilog_library_end____"
/* most likely a lexical error */
%token TK_OTHER
// LINT.ThenChange(../formatting/verilog_token.cc)
/* A glorified ';' specialized to mark the end of an
assertion_variable_declaration list inside the
body of a property_declaration (which ends with a property_spec)
or a sequence_declaration (which ends with a sequence_expr).
This re-enumeration is set by a contextualizing pass between the
lexer and parser.
*/
%token SemicolonEndOfAssertionVariableDeclarations ";(after-assertion-variable-decls)"
// right-associative modify-assignment operators
%right TK_PLUS_EQ
%right TK_MINUS_EQ
%right TK_MUL_EQ
%right TK_DIV_EQ
%right TK_MOD_EQ
%right TK_AND_EQ
%right TK_OR_EQ
%right TK_XOR_EQ
%right TK_LS_EQ
%right TK_RS_EQ
%right TK_RSS_EQ
%right '?'
%right ':'
%right TK_inside
%right TK_LOGICAL_IMPLIES
%right TK_LOGEQUIV
/* left-associative operators */
%left TK_LOR
%left TK_LAND
%left '|'
%left '^' TK_NXOR TK_NOR
%left '&' TK_NAND
%left TK_EQ TK_NE TK_CEQ TK_CNE
%left TK_WILDCARD_EQ TK_WILDCARD_NE
%left TK_GE TK_LE '<' '>'
%left TK_LS TK_RS TK_RSS
%left '+' '-'
%left '*' '/' '%'
%left TK_POW
/**
%left UNARY_PREC
**/
/* to resolve dangling else ambiguity. */
/* alternatively, rewrite using matched/unmatched-if */
%nonassoc less_than_TK_else
%nonassoc TK_else
/* to resolve exclude (... ambiguity */
%nonassoc '('
%nonassoc TK_exclude
/* root of syntax tree: */
%start source_text
%%
source_text
: description_list
{ param->SetRoot(std::move($1)); }
| /* empty */
{ param->SetRoot(MakeNode()); }
;
GenericIdentifier
// TODO(fangism): re-tag these to look like GenericIdentifier
: SymbolIdentifier
{ $$ = std::move($1); }
| EscapedIdentifier
{ $$ = std::move($1); }
| MacroIdentifier
{ $$ = std::move($1); }
| KeywordIdentifier
{ $$ = std::move($1); }
;
KeywordIdentifier
/* The following are keywords in certain dialects of Verilog.
* These are used in some contexts, but in others we just regard them as
* regular identifiers.
* TODO(hzeller): Often, SymbolIdentifier is used in direct token
* comparisons in the code. They should match GenericIdentifier instead.
*/
/* Verilog-AMS: */
: TK_access
{ $$ = std::move($1); }
| TK_exclude
{ $$ = std::move($1); }
| TK_flow
{ $$ = std::move($1); }
| TK_from
{ $$ = std::move($1); }
| TK_discrete
{ $$ = std::move($1); }
/* TK_sample is in SystemVerilog coverage_event */
| TK_sample
{ $$ = std::move($1); }
| TK_infinite
{ $$ = std::move($1); }
| TK_continuous
{ $$ = std::move($1); }
;
/* TODO(fangism): phase this out:
* Separate into preprocessor_balanced_* and preprocessor_action.
* Require uses of preprocess control flow to be balanced.
*/
preprocessor_directive
: preprocessor_control_flow
{ $$ = std::move($1); }
| preprocessor_action
{ $$ = std::move($1); }
;
preprocessor_if_header
: PP_ifdef PP_Identifier
{ $$ = MakeTaggedNode(N::kPreprocessorIfdefClause, $1, $2); }
/* consumer of $$ is expected to ExtendNode */
| PP_ifndef PP_Identifier
{ $$ = MakeTaggedNode(N::kPreprocessorIfndefClause, $1, $2); }
/* consumer of $$ is expected to ExtendNode */
/* | PP_if expression '\n' */ /* doesn't exist for Verilog */
;
preprocessor_elsif_header
: PP_elsif PP_Identifier
{ $$ = MakeTaggedNode(N::kPreprocessorElsifClause, $1, $2); }
/* consumer of $$ is expected to ExtendNode */
/* `elsif is interpreted as else-if-macro-is-defined,
* not the traditional expression predicate that follows else-if.
*/
;
/* TODO(fangism): Phase this out.
* Require uses of preprocess control flow to be balanced.
*/
preprocessor_control_flow
: preprocessor_if_header
{ $$ = std::move($1); }
| preprocessor_elsif_header
{ $$ = std::move($1); }
| PP_else
{ $$ = std::move($1); }
| PP_endif
{ $$ = std::move($1); }
;
preprocessor_action
: PP_undef PP_Identifier
{ $$ = MakeTaggedNode(N::kPreprocessorUndef, $1, $2); }
| PP_include preprocess_include_argument
{ $$ = MakeTaggedNode(N::kPreprocessorInclude, $1, $2); }
/* The body of a `define macro can be any unstructured sequence of tokens,
* which this parser just accumulates in an un-lexer manner.
* Verilog preprocessing even supports `defines in the bodies of `defines!
*/
| PP_define PP_Identifier PP_define_body
{ $$ = MakeTaggedNode(N::kPreprocessorDefine, $1, $2, $3); }
/* $3 is unlexed text, and may even be empty. */
| PP_define PP_Identifier '(' macro_formals_list_opt ')' PP_define_body
{ $$ = MakeTaggedNode(N::kPreprocessorDefine, $1, $2, MakeParenGroup($3, $4, $5), $6); }
/* $6 is unlexed text, and may even be empty. */
;
macro_formals_list_opt
: macro_formals_list
{ $$ = std::move($1); }
| /* empty */
{ $$.reset(); }
;
macro_formals_list
: macro_formals_list ',' macro_formal_parameter
{ $$ = ExtendNode($1, $2, $3); }
| macro_formal_parameter
{ $$ = MakeTaggedNode(N::kMacroFormalParameterList, $1); }
;
macro_formal_parameter
: PP_Identifier
{ $$ = MakeTaggedNode(N::kMacroFormalArg, $1); }
| PP_Identifier '=' PP_default_text
{ $$ = MakeTaggedNode(N::kMacroFormalArg, $1, $2, $3); }
/* $3 is unlexed text */
;
preprocess_include_argument
: string_literal
{ $$ = std::move($1); }
| TK_AngleBracketInclude
{ $$ = std::move($1); }
| MacroIdentifier
{ $$ = std::move($1); }
| MacroGenericItem
{ $$ = std::move($1); }
| MacroCall
{ $$ = std::move($1); }
;
MacroGenericItem
: MacroCallItem
{ $$ = std::move($1); }
| MacroIdItem
{ $$ = MakeTaggedNode(N::kMacroGenericItem, $1); }
;
MacroCallItem
/* suitable for use as list items */
: MacroCallId '(' macro_args_opt MacroCallCloseToEndLine
{ $$ = MakeTaggedNode(N::kMacroCall, $1, MakeParenGroup($2, $3, $4)); }
;
MacroCall
/* suitable for use in expressions */
: MacroCallId '(' macro_args_opt ')'
{ $$ = MakeTaggedNode(N::kMacroCall, $1, MakeParenGroup($2, $3, $4)); }
;
macro_args_opt
: macro_args_opt ',' macro_arg_opt
{ $$ = ExtendNode($1, $2, $3); }
| macro_arg_opt
{ $$ = MakeTaggedNode(N::kMacroArgList, $1);}
;
macro_arg_opt
: MacroArg
/* un-lexed text */
{ $$ = std::move($1); }
| /* empty */
{ $$ = nullptr; }
;
procedural_assertion_statement
: concurrent_assertion_statement
{ $$ = std::move($1); }
| immediate_assertion_statement
{ $$ = std::move($1); }
/* TODO(fangism):
| checker_instantiation
*/
;
assertion_item
: concurrent_assertion_item
{ $$ = std::move($1); }
| deferred_immediate_assertion_item
{ $$ = std::move($1); }
;
assignment_pattern
: TK_LP expression_list_proper '}'
{ $$ = MakeTaggedNode(N::kAssignmentPattern, $1, $2, $3); }
| TK_LP structure_or_array_pattern_expression_list '}'
{ $$ = MakeTaggedNode(N::kAssignmentPattern, $1, $2, $3); }
| TK_LP expression '{' expression_list_proper '}' '}'
{ $$ = MakeTaggedNode(N::kAssignmentPattern, $1, $2, MakeBraceGroup($3, $4, $5), $6); }
/* replication construct: $2 must be a constant expression */
| TK_LP '}'
{ $$ = MakeTaggedNode(N::kAssignmentPattern, $1, $2); }
;
assignment_pattern_expression
: assignment_pattern
{ $$ = std::move($1); }
| data_type_base assignment_pattern
{ $$ = MakeTaggedNode(N::kAssignmentPatternExpression, $1, $2); }
;
structure_or_array_pattern_expression_list
: structure_or_array_pattern_expression_list ',' structure_or_array_pattern_expression
{ $$ = ExtendNode($1, $2, $3); }
| structure_or_array_pattern_expression
{ $$ = MakeNode($1); }
;
structure_or_array_pattern_expression
: structure_or_array_pattern_key ':' expression
{ $$ = MakeTaggedNode(N::kPatternExpression, $1, $2, $3); }
;
structure_or_array_pattern_key
/* structure_pattern_key : member_identifier | assignment_pattern_key
* array_pattern_key : constant_expression | assignment_pattern_key
* assignment_pattern_key : simple_type | TK_default
*/
: expression
{ $$ = std::move($1); }
/* $1 should be a constant expression or GenericIdentifier (member). */
| simple_type
{ $$ = std::move($1); }
| TK_default
{ $$ = std::move($1); }
;
simple_type
: integer_atom_type
{ $$ = std::move($1); }
| integer_vector_type
{ $$ = std::move($1); }
/* TODO(fangism): support package scope or class scope type here:
| qualified_id
*/
;
block_identifier_opt
: unqualified_id ':'
{ $$ = MakeTaggedNode(N::kBlockIdentifier, $1, $2); }
/* $1 should be a GenericIdentifier, no parameter_value */
| /* empty */
{ $$ = nullptr; }
;
interface_class_declaration
: TK_interface TK_class GenericIdentifier
module_parameter_port_list_opt
declaration_extends_list_opt ';' /* multiple base interfaces allowed */
interface_class_item_list_opt
TK_endclass label_opt
{ $$ = MakeTaggedNode(N::kInterfaceClassDeclaration, $1, $2, $3, $4, $5, $6, $7, $8, $9); }
;
declaration_extends_list_opt
: declaration_extends_list
{ $$ = std::move($1); }
| /* empty */
{ $$ = nullptr; }
;
declaration_extends_list
: TK_extends class_id
{ $$ = MakeTaggedNode(N::kDeclarationExtendsList, $1, $2); }
| declaration_extends_list ',' class_id