compsyn.mly 37.8 KB
Newer Older
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
%{
open Typedef

let pos_fn = ref "";;
let pos_ln = ref 0;;
let pos_cn = ref 0;;

let delunderscore strg = String.concat "" (Str.split (Str.regexp "['_']+") strg)
;;

let string2base_number strg =
	try 
	let pos = String.index strg '\'' in
		let b = String.get strg (pos+1)
		and len = try
			int_of_string (delunderscore (String.sub strg 0 pos))
		with int_of_string -> begin
			Printf.printf "fatal error : base number without width %s at " strg;
			Printf.printf "file : %s " !pos_fn;
			Printf.printf "line : %d " ((!pos_ln) + 1); (*because it start from 0*)
			Printf.printf "char : %d\n" !pos_cn;
			exit 1
		end
		and num = delunderscore(String.sub strg (pos+2) ((String.length strg)-pos-2))
		in begin
			match b with
			'b' -> begin
				let lennum = String.length num
				in begin
					if lennum = len then T_number_base(len,'b',num)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');num]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub num (lennum-len) len))
					end
				end
			end
			| 'B' -> begin
				let lennum = String.length num
				in begin
					if lennum = len then T_number_base(len,'b',num)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');num]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub num (lennum-len) len))
					end
				end
			end
			| 'h' -> begin
				Printf.printf "NOTE : to convert %s 1\n" strg;
				let newnum = Misc2.hexstring2binstring num
				in
				let lennum = String.length newnum
				in begin
					if lennum = len then T_number_base(len,'b',newnum)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');newnum]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub newnum (lennum-len) len))
					end
				end
			end
			| 'H' -> begin
				Printf.printf "NOTE : to convert %s 2\n" strg;
				let newnum = Misc2.hexstring2binstring num
				in
				let lennum = String.length newnum
				in begin
					if lennum = len then T_number_base(len,'b',newnum)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');newnum]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub newnum (lennum-len) len))
					end
				end
			end
			| 'd' -> begin
				let newnum = Misc2.decstring2binstring num
				in
				let lennum = String.length newnum
				in begin
					if lennum = len then T_number_base(len,'b',newnum)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');newnum]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub newnum (lennum-len) len))
					end
				end
			end
			| 'D' -> begin
				let newnum = Misc2.decstring2binstring num
				in
				let lennum = String.length newnum
				in begin
					if lennum = len then T_number_base(len,'b',newnum)
					else if lennum < len then T_number_base(len,'b',(String.concat "" [(String.make (len - lennum) '0');newnum]))
					else begin
						Printf.printf  "warning : lennum > len %s\n" strg;
						T_number_base(len,'b',(String.sub newnum (lennum-len) len))
					end
				end
			end
			| _ -> begin
				Printf.printf  "fatal error : invalid number %s\n" strg;
				exit 1
			end
		end
	with Not_found -> print_endline "not found";print_endline strg; exit 1
;;

let parse_error str = begin
	Printf.printf "fatal error : %s at " str;
	Printf.printf "file : %s " !pos_fn;
	Printf.printf "line : %d " ((!pos_ln) + 1); (*because it start from 0*)
	Printf.printf "char : %d\n" !pos_cn;
	exit 1
end
;;
let get_pos (pos : Lexing.position ) = begin
	pos_fn := pos.Lexing.pos_fname;
	pos_ln := pos.Lexing.pos_lnum;
	pos_cn := pos.Lexing.pos_cnum-pos.Lexing.pos_bol
end
;;
let get_endpos pos2 = begin
	match pos2 with
	(_,pos) -> get_pos pos
end
;;
%}

%token <Lexing.position*Lexing.position> KEY_MODULE
%token <Lexing.position*Lexing.position> KEY_ENDMODULE
%token <Lexing.position*Lexing.position> KEY_INPUT
%token <Lexing.position*Lexing.position> KEY_INOUT
%token <Lexing.position*Lexing.position> KEY_OUTPUT
%token <Lexing.position*Lexing.position> KEY_SMALL
%token <Lexing.position*Lexing.position> KEY_MEDIUM
%token <Lexing.position*Lexing.position> KEY_LARGE
%token <Lexing.position*Lexing.position> KEY_SCALARED
%token <Lexing.position*Lexing.position> KEY_VECTORED
%token <Lexing.position*Lexing.position> KEY_ASSIGN
%token <Lexing.position*Lexing.position> KEY_REG
%token <Lexing.position*Lexing.position> KEY_ALWAYS
%token <Lexing.position*Lexing.position> KEY_IF
%token <Lexing.position*Lexing.position> KEY_ELSE
%token <Lexing.position*Lexing.position> KEY_CASE
%token <Lexing.position*Lexing.position> KEY_ENDCASE
%token <Lexing.position*Lexing.position> KEY_DISABLE
%token <Lexing.position*Lexing.position> KEY_FORCE
%token <Lexing.position*Lexing.position> KEY_DEFAULT
%token <Lexing.position*Lexing.position> KEY_CASEZ
%token <Lexing.position*Lexing.position> KEY_CASEX
%token <Lexing.position*Lexing.position> KEY_FOREVER
%token <Lexing.position*Lexing.position> KEY_REPEAT
%token <Lexing.position*Lexing.position> KEY_WHILE
%token <Lexing.position*Lexing.position> KEY_FOR
%token <Lexing.position*Lexing.position> KEY_WAIT
%token <Lexing.position*Lexing.position> KEY_RELEASE
%token <Lexing.position*Lexing.position> KEY_FORK
%token <Lexing.position*Lexing.position> KEY_JOIN
%token <Lexing.position*Lexing.position> KEY_EVENT
%token <Lexing.position*Lexing.position> KEY_TIME
%token <Lexing.position*Lexing.position> KEY_REAL
%token <Lexing.position*Lexing.position> KEY_INTEGER
%token <Lexing.position*Lexing.position> KEY_PARAMETER
%token <Lexing.position*Lexing.position> KEY_BEGIN
%token <Lexing.position*Lexing.position> KEY_END
%token <Lexing.position*Lexing.position> KEY_EDGE
%token <Lexing.position*Lexing.position> KEY_POSEDGE
%token <Lexing.position*Lexing.position> KEY_NEGEDGE
%token <Lexing.position*Lexing.position> KEY_OR
%token <Lexing.position*Lexing.position> KEY_SPECIFY
%token <Lexing.position*Lexing.position> KEY_ENDSPECIFY
%token <Lexing.position*Lexing.position> KEY_TASK
%token <Lexing.position*Lexing.position> KEY_ENDTASK
%token <Lexing.position*Lexing.position> KEY_ENDFUNCTION
%token <Lexing.position*Lexing.position> KEY_FUNCTION
%token <Lexing.position*Lexing.position> KEY_INITIAL
%token <Lexing.position*Lexing.position> KEY_SPECPARAM
%token <Lexing.position*Lexing.position> KEY_DEFPARAM
%token <Lexing.position*Lexing.position> LEADTO
%token <Lexing.position*Lexing.position> AT

%token <string> IDENTIFIER
/*
%token <string> DECIMAL_NUMBER
*/
%token <string> UNSIGNED_NUMBER
%token <string> FLOAT_NUMBER
%token <string> BASE_NUMBER
%token <string> DOLLOR_SYSTEM_IDENTIFIER

%token DOLLOR_SETUP
%token DOLLOR_HOLD
%token DOLLOR_PERIOD
%token DOLLOR_WIDTH
%token DOLLOR_SKEW
%token DOLLOR_RECOVERY
%token DOLLOR_SETUPHOLD
%token <Lexing.position*Lexing.position> AND3

%token <Lexing.position*Lexing.position> EOL
%token <Lexing.position*Lexing.position> EOF
%token <Lexing.position*Lexing.position> LBRACE
%token <Lexing.position*Lexing.position> RBRACE
%token <Lexing.position*Lexing.position> LBRACKET
%token <Lexing.position*Lexing.position> RBRACKET
%token <Lexing.position*Lexing.position> LPAREN
%token <Lexing.position*Lexing.position> RPAREN
%token <Lexing.position*Lexing.position> COMMA
%token <Lexing.position*Lexing.position> SEMICOLON
%token <Lexing.position*Lexing.position> COLON
%token <Lexing.position*Lexing.position> DOT
%token <Lexing.position*Lexing.position> JING
%token <Lexing.position*Lexing.position> SINGLEASSIGN
%token <Lexing.position*Lexing.position> PATHTO
%token <Lexing.position*Lexing.position> PATHTOSTAR
%token <Lexing.position*Lexing.position> QUESTION_MARK_COLON
/*
      | "+"                                          { ADD                      }
      | "-"                                          { SUB                      }
      | "*"                                          { MUL                      }
      | "/"                                          { DIV                      }
      | "%"                                          { MOD                      }
      | ">"                                          { GT                       }
      | ">="                                         { GE                       }
      | "<"                                          { LT                       }
      | "<="                                         { LE                       }
      | "!"                                          { LOGIC_NEG                }
      | "&&"                                         { LOGIC_AND                }
      | "||"                                         { LOGIC_OR                 }
      | "=="                                         { LOGIC_EQU                }
      | "!="                                         { LOGIC_INE                }
      | "==="                                        { CASE_EQU                 }
      | "!=="                                        { CASE_INE                 }
      | "~"                                          { BIT_NEG                  }
      | "&"                                          { BIT_AND                  }
      | "|"                                          { BIT_OR                   }
      | "^"                                          { BIT_XOR                  }
      | "^~"                                         { BIT_EQU                  }
      | "~^"                                         { BIT_EQU                  }
      | "~&"                                         { RED_NAND                 }
      | "~|"                                         { RED_NOR                  }
      | "<<"                                         { LEFT_SHIFT               }
      | ">>"                                         { RIGHT_SHIFT              }
      | "?"                                          { QUESTION_MARK            }

*/

%token  <Lexing.position*Lexing.position> LOGIC_OR
%token  <Lexing.position*Lexing.position> LOGIC_AND
%token  <Lexing.position*Lexing.position> BIT_OR
%token  <Lexing.position*Lexing.position> BIT_XOR BIT_EQU
%token  <Lexing.position*Lexing.position> BIT_AND
%token  <Lexing.position*Lexing.position> LOGIC_EQU LOGIC_INE CASE_EQU CASE_INE
%token  <Lexing.position*Lexing.position> GT GE LT LE
%token  <Lexing.position*Lexing.position> LEFT_SHIFT RIGHT_SHIFT
%token  <Lexing.position*Lexing.position> ADD SUB
%token  <Lexing.position*Lexing.position> MUL DIV MOD
%token  <Lexing.position*Lexing.position> LOGIC_NEG BIT_NEG RED_NAND RED_NOR
%token  <Lexing.position*Lexing.position> QUESTION_MARK

%right QUESTION_MARK
%left  LOGIC_OR
%left  LOGIC_AND
%left  BIT_OR
%left  BIT_XOR BIT_EQU
%left  BIT_AND
%left  LOGIC_EQU LOGIC_INE CASE_EQU CASE_INE
%left  GT GE LT LE
%left  LEFT_SHIFT RIGHT_SHIFT
%left  ADD SUB
%left  MUL DIV MOD
/*unary only operator*/
%left  LOGIC_NEG BIT_NEG RED_NAND RED_NOR
/*unary operator symbol that maybe used as binary operator*/
%left  UADD USUB UAND UOR UXOR UEQU


%token CAPITAL_E
%token LITTLE_E
%token <Lexing.position*Lexing.position> DOLLOR
%token <string> NETTYPE
%token <string> GATETYPE
%token <string> STRENGTH0
%token <string> STRENGTH1
%token <string> STRING
/*A.1*/
/*Source Text*/
%start source_text
%type <Typedef.module_def list> source_text


%%
source_text	:
		description_list EOF		
			{
				get_endpos $2;
				$1
			}
;

description_list:
		description	{ $1::[] }
		| description source_text		{  $1::$2 }
;

description	:
		module_def	{
					$1
				}
/*		| primitive   {0}*/
/* not supported */
;

module_def			:
		KEY_MODULE IDENTIFIER list_of_ports_opt SEMICOLON module_item_optlist KEY_ENDMODULE		
			{
				(*print_endline $2;*)
				get_endpos $6;
				T_module_def($2,$3,$5)
			}
;

list_of_ports_opt :
			{[]}
		|	list_of_ports	{$1}
;

list_of_ports	:
		LPAREN  port comma_port_optlist RPAREN	
			{
				get_endpos $4;
				$2::$3
			}
;

comma_port_optlist:
			{[]}
		| comma_port comma_port_optlist  {$1::$2}
;

comma_port	:
		COMMA port	
			{
				$2
			}
;

port :
	port_expression_opt			{$1}
/*	| DOT IDENTIFIER LPAREN port_expression_opt LPAREN	{0}*/
/*this seems incorrect*/
;

port_expression_opt	:
						{[]}
	| port_expression			{$1}
;

port_expression:
	port_reference				{[$1]}
	| LBRACE port_reference	comma_port_reference_optlist	RBRACE		
		{
			get_endpos $4;
			$2::$3
		}
;

comma_port_reference_optlist :
						{[]}
	| comma_port_reference comma_port_reference_optlist {$1::$2}
;

comma_port_reference :
	COMMA port_reference			{$2}
;

port_reference :
	IDENTIFIER				{$1}
;

module_item_optlist	:
					{[]}
		|	module_item module_item_optlist	{$1::$2}
;

module_item	:
		parameter_declaration   {$1}
		| input_declaration   {$1}
		| output_declaration   {$1}
		| inout_declaration   {$1}
		| net_declaration   {$1}
		| reg_declaration  {$1}
		| time_declaration  {T_time_declaration($1)}
		| integer_declaration  {T_integer_declaration($1)}
		| real_declaration  {$1}
		| event_declaration  {$1}
		| gate_declaration  {$1}
/*because UDP and module cannot be distinguished,so we select to make them into same*/
/*		| UDP_instantiation  {$1}*/
		| module_instantiation  {$1}
		| parameter_override  {$1}
		| continuous_assign  {T_continuous_assign($1)}
		| specify_block  {$1}
		| initial_statement  {T_initial_statement($1)}
		| always_statement  {T_always_statement($1)}
		| task  {$1}
		| function_avoid_amb  {$1}
;

function_avoid_amb:
	KEY_FUNCTION range_or_type_opt IDENTIFIER SEMICOLON tf_declaration_list statement KEY_ENDFUNCTION
			{
				get_endpos $7;
				T_function_avoid_amb($2,$3,$5,$6)
			}
;

tf_declaration_list:
	tf_declaration   {[$1]}
	| tf_declaration tf_declaration_list  {$1::$2}
;

range_or_type_opt:
				{T_range_or_type_NOSPEC}
	| range_or_type		{$1}
;

range_or_type:
	range	{T_range_or_type_range($1)}
	| KEY_INTEGER   {T_range_or_type_INTEGER}
	| KEY_REAL   {T_range_or_type_REAL}
;

task:
	KEY_TASK IDENTIFIER SEMICOLON tf_declaration_optlist statement_or_null KEY_ENDTASK  
		{
			get_endpos $6;
			T_task($2,$4,$5)
		}
;

tf_declaration_optlist:
			{[]}
	| tf_declaration tf_declaration_optlist {$1::$2}
;
/*it will has model_item type*/
tf_declaration:
	parameter_declaration	{$1}
	| input_declaration	{$1}
	| output_declaration	{$1}
	| inout_declaration	{$1}
	| reg_declaration	{$1}
	| time_declaration	{T_time_declaration($1)}
	| integer_declaration	{T_integer_declaration($1)}
	| real_declaration	{$1}
	| event_declaration	{$1}
;

initial_statement:
	KEY_INITIAL statement    {$2}
;

specify_block:
	KEY_SPECIFY specify_item_optlist KEY_ENDSPECIFY   
		{
			get_endpos $3;
			T_specify_block($2)
		}
;

specify_item_optlist:
			{[]}
	| specify_item specify_item_optlist {$1::$2}
;

specify_item:
	specparam_declaration	{0}
	| path_declaration 	{0}
	| level_sensitive_path_declaration	{0}
	| edge_sensitive_path_declaration	{0}
	| system_timing_check	{0}
	| sdpd {0}
;

sdpd:
	KEY_IF LPAREN expression RPAREN path_description SINGLEASSIGN path_delay_value SEMICOLON   
		{
			get_endpos $8;
			0
		}
;


system_timing_check:
	DOLLOR_SETUP LPAREN timing_check_event COMMA timing_check_event COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $10;
		0
	}
	| DOLLOR_HOLD LPAREN timing_check_event COMMA timing_check_event COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $10;
		0
	}
	| DOLLOR_PERIOD LPAREN controlled_timing_check_event COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $8;
		0
	}
	| DOLLOR_WIDTH LPAREN controlled_timing_check_event COMMA timing_check_limit comma_constant_expression_comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $8;
		0
	}
	| DOLLOR_SKEW LPAREN timing_check_event COMMA timing_check_event COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $10;
		0
	}
	| DOLLOR_RECOVERY LPAREN controlled_timing_check_event COMMA timing_check_event COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $10;
		0
	}
	| DOLLOR_SETUPHOLD LPAREN timing_check_event COMMA timing_check_event COMMA timing_check_limit COMMA timing_check_limit comma_notify_register_opt RPAREN  SEMICOLON   
	{
		get_endpos $12;
		0
	}
;

comma_constant_expression_comma_notify_register_opt:
			{0}
	| comma_constant_expression_comma_notify_register {0}
;

comma_constant_expression_comma_notify_register:
	COMMA constant_expression COMMA notify_register  {0}
;

notify_register:
	identifier  {0}
;

controlled_timing_check_event:
	timing_check_event_control specify_terminal_descriptor and3_timing_check_condition_opt  {0}
;

and3_timing_check_condition_opt:
			{0}
	| and3_timing_check_condition  {0}
;

and3_timing_check_condition:
	AND3 timing_check_condition  {0}
;

timing_check_condition:
	expression  {0}
;

comma_notify_register_opt:
			{0}
	| comma_notify_register {0}
;

comma_notify_register:
	COMMA notify_register  {0}
;

timing_check_limit:
	expression  {0}
;

timing_check_event:
	timing_check_event_control_opt specify_terminal_descriptor and3_timing_check_condition_opt   {0}
;

timing_check_event_control_opt:
			{0}
	| timing_check_event_control {0}
;

timing_check_event_control:
	KEY_POSEDGE  
	{
		get_endpos $1;
		0
	}
	| KEY_NEGEDGE 
	{
		get_endpos $1;
		0
	}
	| edge_control_specifier {0}
;

edge_control_specifier:
	KEY_EDGE LBRACKET edge_descriptor comma_edge_descriptor_optlist RBRACKET  
	{
		get_endpos $5;
		0
	}
;

edge_descriptor:
		{print_string "no supported edge_descriptor";0}
;

comma_edge_descriptor_optlist:
			{0}
	| comma_edge_descriptor comma_edge_descriptor_optlist {0}
;

comma_edge_descriptor:
	COMMA edge_descriptor  {0}
;



edge_sensitive_path_declaration:
	KEY_IF_LPAREN_expression_RPAREN_opt LPAREN edge_identifier_opt specify_terminal_descriptor PATHTO LPAREN specify_terminal_descriptor polarity_operator QUESTION_MARK_COLON data_source_expression RPAREN RPAREN SINGLEASSIGN path_delay_value SEMICOLON 
	{
		get_endpos $15;
		0
	}
	| KEY_IF_LPAREN_expression_RPAREN_opt LPAREN edge_identifier_opt specify_terminal_descriptor PATHTOSTAR LPAREN list_of_path_input_outputs polarity_operator QUESTION_MARK_COLON data_source_expression RPAREN RPAREN  SINGLEASSIGN path_delay_value SEMICOLON 
	{
		get_endpos $15;
		0
	}
;

list_of_path_input_outputs:
	specify_terminal_descriptor comma_specify_terminal_descriptor_optlist {0}
;


comma_specify_terminal_descriptor_optlist:
			{0}
	| comma_specify_terminal_descriptor comma_specify_terminal_descriptor_optlist {0}
;

comma_specify_terminal_descriptor:
	COMMA specify_terminal_descriptor {0}
;

data_source_expression:
	expression  {0}
;

edge_identifier_opt:
		{0}
	| edge_identifier  {0}
;

edge_identifier:
	KEY_POSEDGE  
	{
		get_endpos $1;
		0
	}
	| KEY_NEGEDGE 
	{
		get_endpos $1;
		0
	}
;

polarity_operator:
	ADD  
	{
		get_endpos $1;
		0
	}
	| SUB  
	{
		get_endpos $1;
		0
	}
;

KEY_IF_LPAREN_expression_RPAREN_opt:
			{0}
	| KEY_IF LPAREN expression RPAREN  
	{
		get_endpos $4;
		0
	}
;

level_sensitive_path_declaration:
	KEY_IF LPAREN conditional_port_expression RPAREN LPAREN specify_terminal_descriptor polarity_operator_opt PATHTO specify_terminal_descriptor RPAREN SINGLEASSIGN path_delay_value  SEMICOLON   
	{
		get_endpos $13;
		0
	}
	| KEY_IF LPAREN conditional_port_expression RPAREN LPAREN list_of_path_input_outputs polarity_operator_opt PATHTOSTAR list_of_path_input_outputs RPAREN SINGLEASSIGN path_delay_value SEMICOLON   
	{
		get_endpos $13;
		0
	}
;


specify_terminal_descriptor:
	IDENTIFIER	{0}
	| IDENTIFIER LBRACKET expression RBRACKET	
	{
		get_endpos $4;
		0
	}
	| IDENTIFIER LBRACKET expression COLON expression RBRACKET	
	{
		get_endpos $6;
		0
	}
;

polarity_operator_opt:
		{0}
	| polarity_operator {0}
;

conditional_port_expression:
	expression  {0}
;

path_declaration:
	path_description SINGLEASSIGN path_delay_value  SEMICOLON   
	{
		get_endpos $4;
		0
	}
;

path_description:
	LPAREN specify_terminal_descriptor PATHTO specify_terminal_descriptor RPAREN   
	{
		get_endpos $5;
		0
	}
	| LPAREN list_of_path_input_outputs PATHTOSTAR list_of_path_input_outputs RPAREN   
	{
		get_endpos $5;
		0
	}
;

path_delay_value:
	path_delay_expression   {0}
	| LPAREN path_delay_expression COMMA path_delay_expression RPAREN   
	{
		get_endpos $5;
		0
	}
	| LPAREN path_delay_expression COMMA path_delay_expression COMMA path_delay_expression RPAREN   
	{
		get_endpos $7;
		0
	}
	| LPAREN path_delay_expression COMMA path_delay_expression COMMA path_delay_expression COMMA path_delay_expression COMMA path_delay_expression COMMA path_delay_expression RPAREN   
	{
		get_endpos $13;
		0
	}
;

path_delay_expression:
	mintypmax_expression {0}
;

specparam_declaration:
	KEY_SPECPARAM list_of_param_assignments  SEMICOLON   
	{
		get_endpos $3;
		0
	}
;


parameter_override:
	KEY_DEFPARAM list_of_param_assignments SEMICOLON   
	{
		get_endpos $3;
		T_parameter_override($2)
	}
;
/*
UDP_instantiation:
	IDENTIFIER drive_strength_opt delay_opt UDP_instance comma_UDP_instance_optlist  SEMICOLON   {0}
;

comma_UDP_instance_optlist:
			{0}
	| comma_UDP_instance comma_UDP_instance_optlist   {0}
;

comma_UDP_instance:
	COMMA UDP_instance   {0}
;

UDP_instance:
	name_of_UDP_instance_opt LPAREN terminal comma_terminal_optlist RPAREN {0}

name_of_UDP_instance_opt:
			{0}
	| IDENTIFIER   {0}
;
*/
gate_declaration:
	GATETYPE drive_strength_opt delay_opt gate_instance comma_gate_instance_optlist  SEMICOLON   
	{
		get_endpos $6;
		T_gate_declaration($1,$2,$3,($4::$5))
	}
;

comma_gate_instance_optlist:
				{[]}
	| comma_gate_instance comma_gate_instance_optlist  {$1::$2}
;

comma_gate_instance:
	COMMA gate_instance   {$2}
;

gate_instance:
	name_of_gate_instance_opt LPAREN terminal comma_terminal_optlist RPAREN   
		{
			get_endpos $5;
			T_gate_instance($1,($3::$4))
		}
;

name_of_gate_instance_opt:
				{""}
	| IDENTIFIER {$1}
;


comma_terminal_optlist:
				{[]}
	| comma_terminal comma_terminal_optlist {$1::$2}
;

comma_terminal:
	COMMA terminal   {$2}
;

terminal:
       expression     {$1}
/*       | IDENTIFIER    {0}*/
;

drive_strength_opt:
			{T_drive_strength_NOSPEC}
	| drive_strength	{$1}
;

integer_declaration:
	KEY_INTEGER list_of_register_variables SEMICOLON 
		{
			get_endpos $3;
			$2
		}
;

time_declaration:
	KEY_TIME list_of_register_variables SEMICOLON 
		{
			get_endpos $3;
			$2
		}
;

always_statement:
	KEY_ALWAYS statement   {$2}
;

statement:
	blocking_assignment SEMICOLON  
		{
			get_endpos $2;
			T_blocking_assignment($1)
		}
	| non_blocking_assignment SEMICOLON   
		{
			get_endpos $2;
			T_non_blocking_assignment($1)
		}
	| KEY_IF LPAREN expression RPAREN statement_or_null   
		{
			get_endpos $4;
			T_if_statement($3,$5)
		}
	| KEY_IF LPAREN expression RPAREN statement_or_null KEY_ELSE statement_or_null   
		{
			get_endpos $6;
			T_if_else_statement($3,$5,$7)
		}
	| KEY_CASE LPAREN expression RPAREN case_item_list KEY_ENDCASE   
		{
			get_endpos $6;
			T_case_statement($3,$5)
		}
	| KEY_CASEZ LPAREN expression RPAREN case_item_list KEY_ENDCASE   
		{
			get_endpos $6;
			T_casez_statement($3,$5)
		}
	| KEY_CASEX LPAREN expression RPAREN case_item_list KEY_ENDCASE   
		{
			get_endpos $6;
			T_casex_statement($3,$5)
		}
	| KEY_FOREVER statement   
		{
			get_endpos $1;
			T_forever_statement($2)
		}
	| KEY_REPEAT LPAREN expression RPAREN statement   
		{
			get_endpos $4;
			T_repeat_statement($3,$5)
		}
	| KEY_WHILE LPAREN expression RPAREN statement   
		{
			get_endpos $4;
			T_while_statement($3,$5)
		}
	| KEY_FOR LPAREN assignment SEMICOLON expression SEMICOLON assignment RPAREN statement    
		{
			get_endpos $8;
			T_for_statement($3,$5,$7,$9)
		}
	| delay_control statement_or_null   {T_delay_statement($1,$2)}
	| event_control statement_or_null   {T_event_statement($1,$2)}
	| KEY_WAIT LPAREN expression RPAREN statement_or_null   
		{
			get_endpos $4;
			T_wait_statement($3,$5)
		}
	| LEADTO name_of_event SEMICOLON   
		{
			get_endpos $3;
			T_leadto_event($2)
		}
	| KEY_BEGIN statement_optlist KEY_END  
		{
			get_endpos $3;
			T_seq_block("",[],$2)
		}   /*seq_block*/
        | KEY_BEGIN COLON IDENTIFIER block_declaration_optlist statement_optlist KEY_END 
		{
			get_endpos $6;
			T_seq_block($3,$4,$5)
		} /*seq_block*/
	| KEY_FORK statement_optlist KEY_JOIN   
		{
			get_endpos $3;
			T_par_block("",[],$2)
		}
	| KEY_FORK COLON IDENTIFIER block_declaration_optlist statement_optlist KEY_JOIN   
		{
			get_endpos $6;
			T_par_block($3,$4,$5)
		}
	| IDENTIFIER SEMICOLON   
		{
			get_endpos $2;
			T_task_enable($1,[])
		}
	| IDENTIFIER LPAREN expression comma_expression_optlist RPAREN SEMICOLON   
		{
			get_endpos $6;
			T_task_enable($1,($3::$4))
		}
	| name_of_system_task SEMICOLON   
		{
			get_endpos $2;
			T_system_task_enable($1,[])
		}
	| name_of_system_task LPAREN expression comma_expression_optlist RPAREN SEMICOLON   
		{
			get_endpos $6;
			T_system_task_enable($1,($3::$4))
		}
	| KEY_DISABLE IDENTIFIER SEMICOLON   
		{
			get_endpos $3;
			T_disable_statement($2)
		}  /*this maybe task or block*/
	| KEY_FORCE assignment SEMICOLON   
		{
			get_endpos $3;
			T_force_statement($2)
		}
	| KEY_RELEASE lvalue SEMICOLON   
		{
			get_endpos $3;
			T_release_statement($2)
		}
;

statement_optlist:
				{[]}
	| statement statement_optlist {$1::$2}
;

block_declaration_optlist:
				{[]}
	| block_declaration  block_declaration_optlist   {$1::$2}
;
/*it will has model_item type*/
block_declaration:
	parameter_declaration {$1}
	| reg_declaration {$1}
	| integer_declaration {T_integer_declaration($1)}
	| real_declaration {$1}
	| time_declaration {T_time_declaration($1)}
	| event_declaration {$1}
;

event_declaration:
	KEY_EVENT name_of_event comma_name_of_event_optlist SEMICOLON   
		{
			get_endpos $4;
			T_event_declaration($2::$3)
		}
;

comma_name_of_event_optlist:
				{[]}
	| comma_name_of_event comma_name_of_event_optlist {$1::$2}
;

comma_name_of_event:
	COMMA name_of_event   {$2}
;

name_of_event:
	IDENTIFIER  {$1}
;


real_declaration:
	KEY_REAL list_of_variables SEMICOLON   
		{
			get_endpos $3;
			T_real_declaration($2)
		}
;


parameter_declaration:
	KEY_PARAMETER list_of_param_assignments SEMICOLON   
		{
			get_endpos $3;
			T_parameter_declaration($2)
		}
;

list_of_param_assignments:
	param_assignment comma_param_assignment_optlist  {$1::$2}
;

comma_param_assignment_optlist:
			{[]}
	| comma_param_assignment comma_param_assignment_optlist  {$1::$2}
;

comma_param_assignment:
	COMMA param_assignment  {$2}
;

param_assignment:
	identifier SINGLEASSIGN constant_expression
		{
			get_endpos $2;
			T_param_assignment($1,$3)
		}
;

name_of_system_task:
	DOLLOR_SYSTEM_IDENTIFIER {$1}
;

event_control:
	AT identifier  
		{
			get_endpos $1;
			T_event_control_id($2)
		}
	| AT LPAREN event_expression_list RPAREN  
		{
			get_endpos $4;
			T_event_control_evexp($3)
		}
;

event_expression_list:
	event_expression or_event_expression_optlist   {$1::$2}
	| event_expression comma_event_expression_optlist   {$1::$2}
;

or_event_expression_optlist:
			{[]}
	| KEY_OR event_expression or_event_expression_optlist  {$2::$3}
;

comma_event_expression_optlist:
			{[]}
	| COMMA event_expression comma_event_expression_optlist {$2::$3}
;

event_expression:
	expression   {T_event_expression($1)}
	| KEY_POSEDGE SCALAR_EVENT_EXPRESSION   {T_event_expression_posedge($2)}
	| KEY_NEGEDGE SCALAR_EVENT_EXPRESSION   {T_event_expression_negedge($2)}
;


/*SCALAR_EVENT_EXPRESSION is an expression that resolves to a one bit value*/
SCALAR_EVENT_EXPRESSION:
	expression   {$1}
;

delay_control: 
	JING expression   {T_delay_control($2)}
/*        | JING LPAREN mintypmax_expression RPAREN   {0}
this has been included in primary*/
;

case_item_list:
	case_item   {[$1]}
	| case_item case_item_list   {$1::$2}
;

case_item:
	expression comma_expression_optlist COLON statement_or_null   {T_case_item_normal($1::$2,$4)}
	| KEY_DEFAULT COLON statement_or_null   {T_case_item_default($3)}
	| KEY_DEFAULT statement_or_null   {T_case_item_default($2)}
;

blocking_assignment:
	lvalue SINGLEASSIGN expression   {T_blocking_assignment_direct($1,$3)}
	| lvalue SINGLEASSIGN delay_control expression    {T_blocking_assignment_delay($1,$4,$3)}
	| lvalue SINGLEASSIGN event_control expression   {T_blocking_assignment_event($1,$4,$3)}
;

non_blocking_assignment:
	lvalue LE expression   {T_non_blocking_assignment_direct($1,$3)}
	| lvalue LE delay_control expression   {T_non_blocking_assignment_delay($1,$4,$3)}
	| lvalue LE event_control expression    {T_non_blocking_assignment_event($1,$4,$3)}
;
statement_or_null:
	statement	{$1}
	| SEMICOLON	
		{
			get_endpos $1;
			T_statement_NOSPEC
		}
;

reg_declaration:
	KEY_REG range_opt list_of_register_variables SEMICOLON   
		{
			get_endpos $4;
			T_reg_declaration($2,$3)
		}
;


list_of_register_variables:
	register_variable comma_register_variable_optlist  {$1::$2}
;

comma_register_variable_optlist:
			{[]}
	| comma_register_variable comma_register_variable_optlist  {$1::$2}
;

comma_register_variable:
	COMMA register_variable   {$2}
;

register_variable:
	IDENTIFIER	{T_register_variables_ID($1)}
	| IDENTIFIER LBRACKET constant_expression COLON constant_expression RBRACKET   
		{
			get_endpos $6;
			T_register_variables_IDrange($1,$3,$5)
		}
;
/*in UDP inst, # means delay*/
/*but in module inst, # means parameter*/
module_instantiation:
	IDENTIFIER drive_strength_opt parameter_value_assignment_opt module_instance comma_module_instance_optlist SEMICOLON
		{
			get_endpos $6;
			T_module_instantiation($1,$2,$3,$4::$5)
		}
;

comma_module_instance_optlist:
			{[]}
	| comma_module_instance comma_module_instance_optlist   {$1::$2}
;

comma_module_instance:
	COMMA module_instance    {$2}
;

module_instance:
	IDENTIFIER LPAREN list_of_module_connections RPAREN    
		{
			get_endpos $4;
			T_module_instance($1,$3)
		}
;


list_of_module_connections:
	module_port_connection comma_module_port_connection_optlist	{T_list_of_module_connections_unnamed($1::$2)}
	| named_port_connection comma_named_port_connection_optlist     {T_list_of_module_connections_named($1::$2)}
;

comma_named_port_connection_optlist:
				{[]}
	| comma_named_port_connection comma_named_port_connection_optlist  {$1::$2}
;

comma_named_port_connection:
	COMMA named_port_connection   {$2}
;

named_port_connection:
	DOT IDENTIFIER LPAREN  RPAREN   
		{
			get_endpos $4;
			T_named_port_connection($2,T_expression_NOSPEC(0))
		}
	| DOT IDENTIFIER LPAREN expression RPAREN   
		{
			get_endpos $5;
			T_named_port_connection($2,$4)
		}
;

comma_module_port_connection_optlist:
				{[]}
	| comma_module_port_connection  comma_module_port_connection_optlist {$1::$2}
;

comma_module_port_connection:
	COMMA module_port_connection    {$2}
;

module_port_connection:
	                  {T_expression_NOSPEC(0)}
	| expression	{$1}
;

parameter_value_assignment_opt:
	                       {[]}
	| parameter_value_assignment  {$1}
;

parameter_value_assignment:
	JING LPAREN expression comma_expression_optlist RPAREN   
		{
			get_endpos $5;
			$3::$4
		}
;


continuous_assign:
	 KEY_ASSIGN delay_opt list_of_assignments SEMICOLON   
	 	{
			get_endpos $4;
			T_continuous_assign_assign(T_drive_strength_NOSPEC,$2,$3)
		}
	| KEY_ASSIGN drive_strength delay_opt list_of_assignments SEMICOLON   
		{
			get_endpos $5;
			T_continuous_assign_assign($2,$3,$4)
		}
	| NETTYPE expandrange_opt delay_opt list_of_assignments SEMICOLON   
		{
			get_endpos $5;
			T_continuous_assign_net($1,T_drive_strength_NOSPEC,$2,$3,$4)
		}
	| NETTYPE drive_strength expandrange_opt delay_opt list_of_assignments SEMICOLON   
		{
			get_endpos $6;
			T_continuous_assign_net($1,$2,$3,$4,$5)
		}
;

list_of_assignments:
	assignment comma_assignment_optlist   {$1::$2}
;

comma_assignment_optlist:
			{[]}
	| comma_assignment comma_assignment_optlist  {$1::$2}
;

comma_assignment:
	COMMA assignment  {$2}
;

assignment:
	lvalue SINGLEASSIGN expression  {T_assignment($1,$3)}
;

lvalue :
	identifier			{T_lvalue_id($1)}
	| identifier LBRACKET expression RBRACKET 
		{
			get_endpos $4;
			T_lvalue_arrbit($1,$3)
		}
	| identifier LBRACKET constant_expression COLON constant_expression RBRACKET 
		{
			get_endpos $6;
			T_lvalue_arrrange($1,$3,$5)
		}
	| concatenation		{T_lvalue_concat($1)}
;

expression:
	primary			{T_primary($1)}
	| ADD primary %prec UADD   {T_add1($2)}			/* +a */
	| SUB primary %prec USUB  {T_sub1($2)}			/* -a */
	| LOGIC_NEG primary   {T_logicneg($2)} 			/* !a */
	| BIT_NEG primary   {T_bitneg($2)}				/* ~a */
	| BIT_AND primary %prec  UAND  {T_reduce_and($2)}		/* &a reduction */
	| RED_NAND primary   {T_reduce_nand($2)}			/* ~&a reducation*/
	| BIT_OR primary %prec UOR   {T_reduce_or($2)}		/* |a */
	| RED_NOR primary   {T_reduce_nor($2)}				/* ~|a */
	| BIT_XOR primary %prec UXOR   {T_reduce_xor($2)}		/* ^a */
	| BIT_EQU primary %prec UEQU  {T_reduce_xnor($2)}		/* ^~a or ~^a */
	| expression ADD expression  {T_add2($1,$3)}
	| expression SUB expression  {T_sub2($1,$3)}
	| expression MUL expression  {T_mul2($1,$3)}
	| expression DIV expression  {T_div($1,$3)}
	| expression MOD expression  {T_mod($1,$3)}
	| expression LOGIC_EQU expression  {T_logic_equ($1,$3)}
	| expression LOGIC_INE expression  {T_logic_ine($1,$3)}
	| expression CASE_EQU expression  {T_case_equ($1,$3)}
	| expression CASE_INE expression  {T_case_ine($1,$3)}
	| expression LOGIC_AND expression  {T_logic_and2($1,$3)}
	| expression LOGIC_OR expression  {T_logic_or2($1,$3)}
	| expression LT expression  {T_lt($1,$3)}
	| expression LE expression  {T_le($1,$3)}
	| expression GT expression  {T_gt($1,$3)}
	| expression GE expression  {T_ge($1,$3)}
	| expression BIT_AND expression  {T_bit_and2($1,$3)}
	| expression BIT_OR expression  {T_bit_or2($1,$3)}
	| expression BIT_XOR expression  {T_bit_xor2($1,$3)}
	| expression BIT_EQU expression  {T_bit_equ($1,$3)}
	| expression LEFT_SHIFT expression  {T_leftshift($1,$3)}
	| expression RIGHT_SHIFT expression  {T_rightshift($1,$3)}
	| expression QUESTION_MARK expression  COLON expression  {T_selection($1,$3,$5)}
	| STRING   {T_string($1)}
;

primary:
	number   {T_primary_num($1)}
	| identifier		{T_primary_id($1)}
	| identifier LBRACKET expression RBRACKET		
		{
			get_endpos $4;
			T_primary_arrbit($1,$3)
		}
	| identifier LBRACKET constant_expression COLON constant_expression RBRACKET  
		{
			get_endpos $6;
			T_primary_arrrange($1,$3,$5)
		}
	| concatenation          {T_primary_concat($1)}
	| multiple_concatenation  {$1}
	| identifier LPAREN expression comma_expression_optlist RPAREN     
		{
			get_endpos $5;
			T_primary_funcall($1,$3::$4)
		}
	| name_of_system_function LPAREN expression comma_expression_optlist RPAREN     
		{
			get_endpos $5;
			T_primary_sysfuncall($1,$3::$4)
		}
	| name_of_system_function      {T_primary_sysfuncall($1,[])}
	| LPAREN mintypmax_expression RPAREN   
		{
			get_endpos $3;
			T_primary_minmaxexp($2)
		}
;

multiple_concatenation:
	LBRACE expression LBRACE expression comma_expression_optlist RBRACE RBRACE 
		{
			get_endpos $7;
			T_primary_multiconcat($2,$4::$5)
		}
;

concatenation:
	LBRACE expression comma_expression_optlist RBRACE  
		{
			get_endpos $4;
			$2::$3
		}
;

comma_expression_optlist:
				{[]}
	| comma_expression comma_expression_optlist   {$1::$2}
;

mintypmax_expression:
	expression	{T_mintypmax_expression_1($1)}
	| expression COLON expression COLON expression   {T_mintypmax_expression_3($1,$3,$5)}
;


comma_expression:
	COMMA expression   {$2}
;

number:
	UNSIGNED_NUMBER				{T_number_unsign(int_of_string (delunderscore $1))}
	| BASE_NUMBER  {string2base_number $1}
	| UNSIGNED_NUMBER DOT UNSIGNED_NUMBER     {T_number_float(float_of_string( String.concat "" [delunderscore $1;".";delunderscore $3]))}
	| FLOAT_NUMBER	{T_number_float(float_of_string (delunderscore $1))}
;


identifier:
	IDENTIFIER dot_IDENTIFIER_optlist		{$1::$2}
;

dot_IDENTIFIER_optlist:
				{[]}
	| dot_IDENTIFIER dot_IDENTIFIER_optlist {$1::$2}
;

dot_IDENTIFIER:
	DOT IDENTIFIER			{$2}
;

drive_strength:
	LPAREN STRENGTH0 COMMA STRENGTH1 RPAREN    
		{
			get_endpos $5;
			T_drive_strength($2,$4)
		}
	| LPAREN STRENGTH1 COMMA STRENGTH0 RPAREN   
		{
			get_endpos $5;
			T_drive_strength($2,$4)
		}
;



input_declaration:
	KEY_INPUT range_opt list_of_variables SEMICOLON 
		{
			get_endpos $4;
			T_input_declaration($2,$3)
		}
;
output_declaration:
	KEY_OUTPUT range_opt list_of_variables SEMICOLON 
		{
			get_endpos $4;
			T_output_declaration($2,$3)
		}
;
inout_declaration:
	KEY_INOUT range_opt list_of_variables SEMICOLON 
		{
			get_endpos $4;
			T_inout_declaration($2,$3)
		}
;
net_declaration:
	NETTYPE expandrange_opt delay_opt list_of_variables SEMICOLON 
		{
			get_endpos $5;
			T_net_declaration($1,T_charge_strength_NOSPEC,$2,$3,$4)
		}
	| NETTYPE charge_strength expandrange_opt delay_opt list_of_variables SEMICOLON 
		{
			get_endpos $6;
			T_net_declaration($1,$2,$3,$4,$5)
		}
;

delay_opt:
			{T_delay_NOSPEC}
	| delay		{$1}
;

delay:
	 JING number	{T_delay_number($2)}
	 | JING identifier {T_delay_id($2)}
	 | JING LPAREN mintypmax_expression RPAREN   
	 	{
			get_endpos $4;
			T_delay_minmax1($3)
		}
	 | JING LPAREN mintypmax_expression COMMA mintypmax_expression COMMA mintypmax_expression RPAREN   
	 	{
			get_endpos $8;
			T_delay_minmax3($3,$5,$7)
		}
;

expandrange_opt:
			{T_expandrange_NOSPEC}
	| expandrange    {$1}
;

expandrange:
	range		{T_expandrange_range($1)}
	| KEY_SCALARED  range {T_expandrange_scalared($2)}
	| KEY_VECTORED  range {T_expandrange_vectored($2)}
;

charge_strength:
	LPAREN KEY_SMALL RPAREN  
		{
			get_endpos $3;
			T_charge_strength_SMALL
		}
	| LPAREN KEY_MEDIUM RPAREN  
		{
			get_endpos $3;
			T_charge_strength_MEDIUM
		}
	| LPAREN KEY_LARGE RPAREN  
		{
			get_endpos $3;
			T_charge_strength_LARGE
		}
;

range_opt :
				{T_range_NOSPEC}
	| range {$1}
;

range :
	LBRACKET constant_expression COLON constant_expression RBRACKET   
		{
			get_endpos $5;
			T_range($2,$4)
		}
;

constant_expression:
	expression		{$1}
;

list_of_variables: 
		IDENTIFIER comma_IDENTIFIER_optlist	{$1::$2}
;

comma_IDENTIFIER_optlist:
				{[]}
	| comma_IDENTIFIER comma_IDENTIFIER_optlist  {$1::$2}
;

comma_IDENTIFIER:
	COMMA IDENTIFIER   {$2}
;

name_of_system_function:
	DOLLOR  IDENTIFIER {(String.concat "" ("$"::[$2]))::[]}
;
/*
dot_UNSIGNED_NUMBER_opt:
				{0}
	| dot_UNSIGNED_NUMBER	{0}
;

dot_UNSIGNED_NUMBER:
	DOT UNSIGNED_NUMBER	{0}
;
*/