cil-cparser.opp.exp 38.9 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
File "cil-cparser.mly", line 269, characters 54-60:
Warning: the token ADDROF is unused.
File "cil-cparser.mly", line 237, characters 36-50:
Warning: the token ATTRIBUTE_USED is unused.
File "cil-cparser.mly", line 238, characters 7-22:
Warning: the token BUILTIN_VA_LIST is unused.
File "cil-cparser.mly", line 269, characters 42-46:
Warning: the token CAST is unused.
File "cil-cparser.mly", line 199, characters 54-59:
Warning: the token INT32 is unused.
%{
open Cabs
module E = Errormsg

let parse_error msg : unit =       (* sm: c++-mode highlight hack: -> ' <- *)
  E.parse_error msg

let print = print_string


let currentLoc () = 
  let l, f, c = E.getPosition () in
  { lineno   = l; filename = f; byteno   = c; }

let cabslu = {lineno = -10; filename = "cabs loc unknown"; byteno = -10;}

(*
** Expression building
*)
let smooth_expression lst =
  match lst with
    [] -> NOTHING
  | [expr] -> expr
  | _ -> COMMA (lst)


let currentFunctionName = ref "<outside any function>"
    
let announceFunctionName ((n, decl, _, _):name) =
  !Lexerhack.add_identifier n;
  (* Start a context that includes the parameter names and the whole body. 
   * Will pop when we finish parsing the function body *)
  !Lexerhack.push_context ();
  (* Go through all the parameter names and mark them as identifiers *)
  let rec findProto = function
      PROTO (d, args, _) when isJUSTBASE d -> 
        List.iter (fun (_, (an, _, _, _)) -> !Lexerhack.add_identifier an) args

    | PROTO (d, _, _) -> findProto d
    | PARENTYPE (_, d, _) -> findProto d
    | PTR (_, d) -> findProto d
    | ARRAY (d, _, _) -> findProto d
    | _ -> parse_error "Cannot find the prototype in a function definition";
           raise Parsing.Parse_error 

  and isJUSTBASE = function
      JUSTBASE -> true
    | PARENTYPE (_, d, _) -> isJUSTBASE d
    | _ -> false
  in
  findProto decl;
  currentFunctionName := n



let applyPointer (ptspecs: attribute list list) (dt: decl_type)  
       : decl_type = 
  (* Outer specification first *)
  let rec loop = function
      [] -> dt
    | attrs :: rest -> PTR(attrs, loop rest)
  in
  loop ptspecs

let doDeclaration (loc: cabsloc) (specs: spec_elem list) (nl: init_name list) : definition = 
  if isTypedef specs then begin
    (* Tell the lexer about the new type names *)
    List.iter (fun ((n, _, _, _), _) -> !Lexerhack.add_type n) nl;
    TYPEDEF ((specs, List.map (fun (n, _) -> n) nl), loc)
  end else
    if nl = [] then
      ONLYTYPEDEF (specs, loc)
    else begin
      (* Tell the lexer about the new variable names *)
      List.iter (fun ((n, _, _, _), _) -> !Lexerhack.add_identifier n) nl;
      DECDEF ((specs, nl), loc)  
    end


let doFunctionDef (loc: cabsloc)
                  (lend: cabsloc)
                  (specs: spec_elem list) 
                  (n: name) 
                  (b: block) : definition = 
  let fname = (specs, n) in
  FUNDEF (fname, b, loc, lend)


let doOldParDecl (names: string list)
                 ((pardefs: name_group list), (isva: bool)) 
    : single_name list * bool =
  let findOneName n =
    (* Search in pardefs for the definition for this parameter *)
    let rec loopGroups = function
        [] -> ([SpecType Tint], (n, JUSTBASE, [], cabslu))
      | (specs, names) :: restgroups ->
          let rec loopNames = function
              [] -> loopGroups restgroups
            | ((n',_, _, _) as sn) :: _ when n' = n -> (specs, sn)
            | _ :: restnames -> loopNames restnames
          in
          loopNames names
    in
    loopGroups pardefs
  in
  let args = List.map findOneName names in
  (args, isva)

let checkConnective (s : string) : unit =
begin
  (* checking this means I could possibly have more connectives, with *)
  (* different meaning *)
  if (s <> "to") then (
    parse_error "transformer connective must be 'to'";
    raise Parsing.Parse_error
  )
  else ()
end

(* takes a not-nul-terminated list, and converts it to a string. *)
let rec intlist_to_string (str: int64 list):string =
  match str with
    [] -> ""  (* add nul-termination *)
  | value::rest ->
      let this_char = 
	if (compare value (Int64.of_int 255) > 0) 
           || (compare value Int64.zero < 0)
	then begin
	  let msg = Printf.sprintf "cparser:intlist_to_string: character 0x%Lx too big" value in
	  parse_error msg;
	  raise Parsing.Parse_error
	end 
	else 
	  String.make 1 (Char.chr (Int64.to_int value))
      in
      this_char ^ (intlist_to_string rest)

let fst3 (result, _, _) = result
let snd3 (_, result, _) = result
let trd3 (_, _, result) = result

%}
%start file
%start interpret
%token <Cabs.cabsloc> WHILE
%token <Cabs.cabsloc> VOID
%token <Cabs.cabsloc> UNSIGNED
%token <Cabs.cabsloc> UNION
%token <Cabs.cabsloc> TYPEOF
%token <Cabs.cabsloc> TYPEDEF
%token <Cabs.cabsloc> TRY
%token <Cabs.cabsloc> THREAD
%token <Cabs.cabsloc> SWITCH
%token <Cabs.cabsloc> STRUCT
%token <Cabs.cabsloc> STATIC
%token <Cabs.cabsloc> SIGNED
%token <Cabs.cabsloc> SHORT
%token <Cabs.cabsloc> SEMICOLON
%token <Cabs.cabsloc> RETURN
%token <Cabs.cabsloc> REGISTER
%token RBRACKET
%token <Cabs.cabsloc> RBRACE
%token <Cabs.cabsloc> PRETTY_FUNCTION__
%token <string * Cabs.cabsloc> PRAGMA_LINE
%token PRAGMA_EOL
%token <Cabs.cabsloc> PRAGMA
%token <string * Cabs.cabsloc> MSATTR
%token <string * Cabs.cabsloc> MSASM
%token <Cabs.cabsloc> LONG
%token LABEL__
%token <Cabs.cabsloc> INT64
%token <Cabs.cabsloc> INT32
%token <Cabs.cabsloc> INT
%token <Cabs.cabsloc> INLINE
%token <Cabs.cabsloc> GOTO
%token <Cabs.cabsloc> FUNCTION__
%token <Cabs.cabsloc> FOR
%token <Cabs.cabsloc> FLOAT
%token <Cabs.cabsloc> FINALLY
%token <Cabs.cabsloc> EXTERN
%token <Cabs.cabsloc> EXCEPT
%token EOF
%token <Cabs.cabsloc> ENUM
%token ELLIPSIS
%token <Cabs.cabsloc> DOUBLE
%token <Cabs.cabsloc> DO
%token <Cabs.cabsloc> DEFAULT
%token <Cabs.cabsloc> DECLSPEC
%token <int64 list * Cabs.cabsloc> CST_WSTRING
%token <int64 list * Cabs.cabsloc> CST_WCHAR
%token <int64 list * Cabs.cabsloc> CST_STRING
%token <string * Cabs.cabsloc> CST_INT
%token <string * Cabs.cabsloc> CST_FLOAT
%token <int64 list * Cabs.cabsloc> CST_CHAR
%token <Cabs.cabsloc> CONTINUE
%token <Cabs.cabsloc> CHAR
%token <Cabs.cabsloc> CASE
%token BUILTIN_VA_LIST
%token <Cabs.cabsloc> BUILTIN_VA_ARG
%token <Cabs.cabsloc> BREAK
%token BLOCKATTRIBUTE
%token <Cabs.cabsloc> AUTO
%token <Cabs.cabsloc> AT_TRANSFORMEXPR
%token <Cabs.cabsloc> AT_TRANSFORM
%token <Cabs.cabsloc> AT_SPECIFIER
%token AT_NAME
%token <Cabs.cabsloc> AT_EXPR
%token <Cabs.cabsloc> ATTRIBUTE_USED
%token <Cabs.cabsloc> ATTRIBUTE
%token <Cabs.cabsloc> ASM
%token <Cabs.cabsloc> IF
%token ELSE
%token COMMA
%token SUP_SUP_EQ
%token STAR_EQ
%token SLASH_EQ
%token PLUS_EQ
%token PIPE_EQ
%token PERCENT_EQ
%token MINUS_EQ
%token INF_INF_EQ
%token EQ
%token CIRC_EQ
%token AND_EQ
%token QUEST
%token COLON
%token PIPE_PIPE
%token <Cabs.cabsloc> AND_AND
%token PIPE
%token CIRC
%token <Cabs.cabsloc> AND
%token EXCLAM_EQ
%token EQ_EQ
%token SUP_EQ
%token SUP
%token INF_EQ
%token INF
%token SUP_SUP
%token INF_INF
%token <Cabs.cabsloc> PLUS
%token <Cabs.cabsloc> MINUS
%token <Cabs.cabsloc> VOLATILE
%token <Cabs.cabsloc> STAR
%token SLASH
%token <Cabs.cabsloc> RESTRICT
%token PERCENT
%token <Cabs.cabsloc> CONST
%token <Cabs.cabsloc> TILDE
%token <Cabs.cabsloc> SIZEOF
%token RPAREN
%token <Cabs.cabsloc> PLUS_PLUS
%token <Cabs.cabsloc> MINUS_MINUS
%token <Cabs.cabsloc> EXCLAM
%token <Cabs.cabsloc> ALIGNOF
%token LBRACKET
%token <Cabs.cabsloc> LPAREN
%token <Cabs.cabsloc> LBRACE
%token DOT
%token ARROW
%token <string * Cabs.cabsloc> NAMED_TYPE
%token <string * Cabs.cabsloc> IDENT
%nonassoc IF 
%nonassoc ELSE 
%left COMMA 
%right SUP_SUP_EQ STAR_EQ SLASH_EQ PLUS_EQ PIPE_EQ PERCENT_EQ MINUS_EQ INF_INF_EQ EQ CIRC_EQ AND_EQ 
%right QUEST COLON 
%left PIPE_PIPE 
%left AND_AND 
%left PIPE 
%left CIRC 
%left AND 
%left EXCLAM_EQ EQ_EQ 
%left SUP_EQ SUP INF_EQ INF 
%left SUP_SUP INF_INF 
%left PLUS MINUS 
%left VOLATILE STAR SLASH RESTRICT PERCENT CONST 
%right TILDE SIZEOF RPAREN PLUS_PLUS MINUS_MINUS EXCLAM CAST ALIGNOF ADDROF 
%left LBRACKET 
%left LPAREN LBRACE DOT ARROW 
%right NAMED_TYPE 
%left IDENT 
%type <Cabs.decl_type> abs_direct_decl
%type <Cabs.decl_type> abs_direct_decl_opt
%type <Cabs.decl_type * Cabs.attribute list> abstract_decl
%type <Cabs.expression list> arguments
%type <Cabs.attribute list> asmattr
%type <Cabs.attribute list> attributes
%type <Cabs.attribute list> attributes_with_asm
%type <Cabs.block * cabsloc * cabsloc> block
%type <Cabs.statement list> block_element_list
%type <Cabs.expression list> bracket_comma_expression
%type <Cabs.expression list * cabsloc> comma_expression
%type <Cabs.constant * cabsloc> constant
%type <Cabs.spec_elem * cabsloc> cvspec
%type <spec_elem list * cabsloc> decl_spec_list
%type <Cabs.definition> declaration
%type <Cabs.name> declarator
%type <string * Cabs.decl_type> direct_decl
%type <Cabs.enum_item list> enum_list
%type <Cabs.enum_item> enumerator
%type <Cabs.expression * cabsloc> expression
%type <Cabs.name * expression option> field_decl
%type <(Cabs.name * expression option) list> field_decl_list
%type <Cabs.definition list> file
%type <Cabs.definition> function_def
%type <cabsloc * spec_elem list * name> function_def_start
%type <Cabs.definition> global
%type <Cabs.definition list> globals
%type <Cabs.init_name> init_declarator
%type <Cabs.init_name list> init_declarator_list
%type <Cabs.initwhat> init_designators
%type <Cabs.initwhat> init_designators_opt
%type <Cabs.init_expression> init_expression
%type <Cabs.initwhat * Cabs.init_expression> initialiser
%type <(Cabs.initwhat * Cabs.init_expression) list> initialiser_list
%type <Cabs.definition list> interpret
%type <string list> local_label_names
%type <string list> local_labels
%type <Cabs.cabsloc> location
%type <string list> old_parameter_list_ne
%type <Cabs.name> old_proto_decl
%type <Cabs.expression> opt_expression
%type <Cabs.single_name> parameter_decl
%type <Cabs.expression list * cabsloc> paren_comma_expression
%type <attribute list list * cabsloc> pointer
%type <attribute list list * cabsloc> pointer_opt
%type <Cabs.statement> statement
%type <string * cabsloc> string_constant
%type <int64 list * cabsloc> string_list
%type <Cabs.field_group list> struct_decl_list
%type <Cabs.spec_elem list * Cabs.decl_type> type_name
%type <typeSpecifier * cabsloc> type_spec
%type <int64 list * cabsloc> wstring_list
%%

interpret:
| file EOF
    {$1}

file:
| globals
    {$1}

globals:
| 
    { [] }
| global globals
    { $1 :: $2 }
| SEMICOLON globals
    { $2 }

location:
|  %prec IDENT
    { currentLoc () }

global:
| declaration
    { $1 }
| function_def
    { $1 }
| EXTERN string_constant declaration
    { LINKAGE (fst $2, snd $2, [ $3 ]) }
| EXTERN string_constant LBRACE globals RBRACE
    { LINKAGE (fst $2, snd $2, $4)  }
| ASM LPAREN string_constant RPAREN SEMICOLON
    { GLOBASM (fst $3, $1) }
| PRAGMA attr PRAGMA_EOL
    { PRAGMA ($2, $1) }
| PRAGMA attr SEMICOLON PRAGMA_EOL
    { PRAGMA ($2, $1) }
| PRAGMA_LINE
    { PRAGMA (VARIABLE (fst $1), 
                                                  snd $1) }
| IDENT LPAREN old_parameter_list_ne RPAREN old_pardef_list SEMICOLON
    { (* Convert pardecl to new style *)
                             let pardecl, isva = doOldParDecl $3 $5 in 
                             (* Make the function declarator *)
                             doDeclaration (snd $1) []
                               [((fst $1, PROTO(JUSTBASE, pardecl,isva), [], cabslu),
                                 NO_INIT)]
                            }
| IDENT LPAREN RPAREN SEMICOLON
    { (* Make the function declarator *)
                             doDeclaration (snd $1) []
                               [((fst $1, PROTO(JUSTBASE,[],false), [], cabslu),
                                 NO_INIT)]
                            }
| AT_TRANSFORM LBRACE global RBRACE IDENT LBRACE globals RBRACE
    {
    checkConnective(fst $5);
    TRANSFORMER($3, $7, $1)
  }
| AT_TRANSFORMEXPR LBRACE expression RBRACE IDENT LBRACE expression RBRACE
    {
    checkConnective(fst $5);
    EXPRTRANSFORMER(fst $3, fst $7, $1)
  }
| location error SEMICOLON
    { PRAGMA (VARIABLE "parse_error", $1) }

id_or_typename:
| IDENT
    {fst $1}
| NAMED_TYPE
    {fst $1}
| AT_NAME LPAREN IDENT RPAREN
    { "@name(" ^ fst $3 ^ ")" }

maybecomma:
| 
    { () }
| COMMA
    { () }

primary_expression:
| IDENT
    {VARIABLE (fst $1), snd $1}
| constant
    {CONSTANT (fst $1), snd $1}
| paren_comma_expression
    {smooth_expression (fst $1), snd $1}
| LPAREN block RPAREN
    { GNU_BODY (fst3 $2), $1 }
| AT_EXPR LPAREN IDENT RPAREN
    { EXPR_PATTERN(fst $3), $1 }

postfix_expression:
| primary_expression
    { $1 }
| postfix_expression bracket_comma_expression
    {INDEX (fst $1, smooth_expression $2), snd $1}
| postfix_expression LPAREN arguments RPAREN
    {CALL (fst $1, $3), snd $1}
| BUILTIN_VA_ARG LPAREN expression COMMA type_name RPAREN
    { let b, d = $5 in
                          CALL (VARIABLE "__builtin_va_arg", 
                                [fst $3; TYPE_SIZEOF (b, d)]), $1 }
| postfix_expression DOT id_or_typename
    {MEMBEROF (fst $1, $3), snd $1}
| postfix_expression ARROW id_or_typename
    {MEMBEROFPTR (fst $1, $3), snd $1}
| postfix_expression PLUS_PLUS
    {UNARY (POSINCR, fst $1), snd $1}
| postfix_expression MINUS_MINUS
    {UNARY (POSDECR, fst $1), snd $1}
| LPAREN type_name RPAREN LBRACE initialiser_list_opt RBRACE
    { CAST($2, COMPOUND_INIT $5), $1 }

unary_expression:
| postfix_expression
    { $1 }
| PLUS_PLUS unary_expression
    {UNARY (PREINCR, fst $2), $1}
| MINUS_MINUS unary_expression
    {UNARY (PREDECR, fst $2), $1}
| SIZEOF unary_expression
    {EXPR_SIZEOF (fst $2), $1}
| SIZEOF LPAREN type_name RPAREN
    {let b, d = $3 in TYPE_SIZEOF (b, d), $1}
| ALIGNOF unary_expression
    {EXPR_ALIGNOF (fst $2), $1}
| ALIGNOF LPAREN type_name RPAREN
    {let b, d = $3 in TYPE_ALIGNOF (b, d), $1}
| PLUS cast_expression
    {UNARY (PLUS, fst $2), $1}
| MINUS cast_expression
    {UNARY (MINUS, fst $2), $1}
| STAR cast_expression
    {UNARY (MEMOF, fst $2), $1}
| AND cast_expression
    {UNARY (ADDROF, fst $2), $1}
| EXCLAM cast_expression
    {UNARY (NOT, fst $2), $1}
| TILDE cast_expression
    {UNARY (BNOT, fst $2), $1}
| AND_AND IDENT
    { LABELADDR (fst $2), $1 }

cast_expression:
| unary_expression
    { $1 }
| LPAREN type_name RPAREN cast_expression
    { CAST($2, SINGLE_INIT (fst $4)), $1 }

multiplicative_expression:
| cast_expression
    { $1 }
| multiplicative_expression STAR cast_expression
    {BINARY(MUL, fst $1, fst $3), snd $1}
| multiplicative_expression SLASH cast_expression
    {BINARY(DIV, fst $1, fst $3), snd $1}
| multiplicative_expression PERCENT cast_expression
    {BINARY(MOD, fst $1, fst $3), snd $1}

additive_expression:
| multiplicative_expression
    { $1 }
| additive_expression PLUS multiplicative_expression
    {BINARY(ADD, fst $1, fst $3), snd $1}
| additive_expression MINUS multiplicative_expression
    {BINARY(SUB, fst $1, fst $3), snd $1}

shift_expression:
| additive_expression
    { $1 }
| shift_expression INF_INF additive_expression
    {BINARY(SHL, fst $1, fst $3), snd $1}
| shift_expression SUP_SUP additive_expression
    {BINARY(SHR, fst $1, fst $3), snd $1}

relational_expression:
| shift_expression
    { $1 }
| relational_expression INF shift_expression
    {BINARY(LT, fst $1, fst $3), snd $1}
| relational_expression SUP shift_expression
    {BINARY(GT, fst $1, fst $3), snd $1}
| relational_expression INF_EQ shift_expression
    {BINARY(LE, fst $1, fst $3), snd $1}
| relational_expression SUP_EQ shift_expression
    {BINARY(GE, fst $1, fst $3), snd $1}

equality_expression:
| relational_expression
    { $1 }
| equality_expression EQ_EQ relational_expression
    {BINARY(EQ, fst $1, fst $3), snd $1}
| equality_expression EXCLAM_EQ relational_expression
    {BINARY(NE, fst $1, fst $3), snd $1}

bitwise_and_expression:
| equality_expression
    { $1 }
| bitwise_and_expression AND equality_expression
    {BINARY(BAND, fst $1, fst $3), snd $1}

bitwise_xor_expression:
| bitwise_and_expression
    { $1 }
| bitwise_xor_expression CIRC bitwise_and_expression
    {BINARY(XOR, fst $1, fst $3), snd $1}

bitwise_or_expression:
| bitwise_xor_expression
    { $1 }
| bitwise_or_expression PIPE bitwise_xor_expression
    {BINARY(BOR, fst $1, fst $3), snd $1}

logical_and_expression:
| bitwise_or_expression
    { $1 }
| logical_and_expression AND_AND bitwise_or_expression
    {BINARY(AND, fst $1, fst $3), snd $1}

logical_or_expression:
| logical_and_expression
    { $1 }
| logical_or_expression PIPE_PIPE logical_and_expression
    {BINARY(OR, fst $1, fst $3), snd $1}

conditional_expression:
| logical_or_expression
    { $1 }
| logical_or_expression QUEST opt_expression COLON conditional_expression
    {QUESTION (fst $1, $3, fst $5), snd $1}

assignment_expression:
| conditional_expression
    { $1 }
| cast_expression EQ assignment_expression
    {BINARY(ASSIGN, fst $1, fst $3), snd $1}
| cast_expression PLUS_EQ assignment_expression
    {BINARY(ADD_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression MINUS_EQ assignment_expression
    {BINARY(SUB_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression STAR_EQ assignment_expression
    {BINARY(MUL_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression SLASH_EQ assignment_expression
    {BINARY(DIV_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression PERCENT_EQ assignment_expression
    {BINARY(MOD_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression AND_EQ assignment_expression
    {BINARY(BAND_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression PIPE_EQ assignment_expression
    {BINARY(BOR_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression CIRC_EQ assignment_expression
    {BINARY(XOR_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression INF_INF_EQ assignment_expression
    {BINARY(SHL_ASSIGN, fst $1, fst $3), snd $1}
| cast_expression SUP_SUP_EQ assignment_expression
    {BINARY(SHR_ASSIGN, fst $1, fst $3), snd $1}

expression:
| assignment_expression
    { $1 }

constant:
| CST_INT
    {CONST_INT (fst $1), snd $1}
| CST_FLOAT
    {CONST_FLOAT (fst $1), snd $1}
| CST_CHAR
    {CONST_CHAR (fst $1), snd $1}
| CST_WCHAR
    {CONST_WCHAR (fst $1), snd $1}
| string_constant
    {CONST_STRING (fst $1), snd $1}
| wstring_list
    {CONST_WSTRING (fst $1), snd $1}

string_constant:
| string_list
    {intlist_to_string (fst $1), snd $1 }

one_string_constant:
| CST_STRING
    {intlist_to_string (fst $1) }

string_list:
| one_string
    { $1 }
| string_list one_string
    { (fst $1) @ (fst $2), snd $1 }

wstring_list:
| CST_WSTRING
    { $1 }
| wstring_list one_string
    { (fst $1) @ (fst $2), snd $1 }
| wstring_list CST_WSTRING
    { (fst $1) @ (fst $2), snd $1 }

one_string:
| CST_STRING
    {$1}
| FUNCTION__
    {(Cabs.explodeStringToInts 
					    !currentFunctionName), $1}
| PRETTY_FUNCTION__
    {(Cabs.explodeStringToInts 
					    !currentFunctionName), $1}

init_expression:
| expression
    { SINGLE_INIT (fst $1) }
| LBRACE initialiser_list_opt RBRACE
    { COMPOUND_INIT $2}

initialiser_list:
| initialiser
    { [$1] }
| initialiser COMMA initialiser_list_opt
    { $1 :: $3 }

initialiser_list_opt:
| 
    { [] }
| initialiser_list
    { $1 }

initialiser:
| init_designators eq_opt init_expression
    { ($1, $3) }
| gcc_init_designators init_expression
    { ($1, $2) }
| init_expression
    { (NEXT_INIT, $1) }

eq_opt:
| EQ
    { () }
| 
    { () }

init_designators:
| DOT id_or_typename init_designators_opt
    { INFIELD_INIT($2, $3) }
| LBRACKET expression RBRACKET init_designators_opt
    { ATINDEX_INIT(fst $2, $4) }
| LBRACKET expression ELLIPSIS expression RBRACKET
    { ATINDEXRANGE_INIT(fst $2, fst $4) }

init_designators_opt:
| 
    { NEXT_INIT }
| init_designators
    { $1 }

gcc_init_designators:
| id_or_typename COLON
    { INFIELD_INIT($1, NEXT_INIT) }

arguments:
| 
    { [] }
| comma_expression
    { fst $1 }

opt_expression:
| 
    {NOTHING}
| comma_expression
    {smooth_expression (fst $1)}

comma_expression:
| expression
    {[fst $1], snd $1}
| expression COMMA comma_expression
    { fst $1 :: fst $3, snd $1 }
| error COMMA comma_expression
    { $3 }

comma_expression_opt:
| 
    { NOTHING }
| comma_expression
    { smooth_expression (fst $1) }

paren_comma_expression:
| LPAREN comma_expression RPAREN
    { $2 }
| LPAREN error RPAREN
    { [], $1 }

bracket_comma_expression:
| LBRACKET comma_expression RBRACKET
    { fst $2 }
| LBRACKET error RBRACKET
    { [] }

block:
| block_begin local_labels block_attrs block_element_list RBRACE
    {!Lexerhack.pop_context();
                                          { blabels = $2;
                                            battrs = $3;
                                            bstmts = $4 },
					    $1, $5
                                         }
| error location RBRACE
    { { blabels = [];
                                             battrs  = [];
                                             bstmts  = [] },
					     $2, $3
                                         }

block_begin:
| LBRACE
    {!Lexerhack.push_context (); $1}

block_attrs:
| 
    { [] }
| BLOCKATTRIBUTE paren_attr_list_ne
    { [("__blockattribute__", $2)] }

block_element_list:
| 
    { [] }
| declaration block_element_list
    { DEFINITION($1) :: $2 }
| statement block_element_list
    { $1 :: $2 }
| IDENT COLON
    { [ LABEL (fst $1, NOP (snd $1), 
                                                    snd $1)] }

local_labels:
| 
    { [] }
| LABEL__ local_label_names SEMICOLON local_labels
    { $2 @ $4 }

local_label_names:
| IDENT
    { [ fst $1 ] }
| IDENT COMMA local_label_names
    { fst $1 :: $3 }

statement:
| SEMICOLON
    {NOP $1 }
| comma_expression SEMICOLON
    {COMPUTATION (smooth_expression (fst $1), snd $1)}
| block
    {BLOCK (fst3 $1, snd3 $1)}
| IF paren_comma_expression statement %prec IF
    {IF (smooth_expression (fst $2), $3, NOP $1, $1)}
| IF paren_comma_expression statement ELSE statement
    {IF (smooth_expression (fst $2), $3, $5, $1)}
| SWITCH paren_comma_expression statement
    {SWITCH (smooth_expression (fst $2), $3, $1)}
| WHILE paren_comma_expression statement
    {WHILE (smooth_expression (fst $2), $3, $1)}
| DO statement WHILE paren_comma_expression SEMICOLON
    {DOWHILE (smooth_expression (fst $4), $2, $1)}
| FOR LPAREN for_clause opt_expression SEMICOLON opt_expression RPAREN statement
    {FOR ($3, $4, $6, $8, $1)}
| IDENT COLON statement
    {LABEL (fst $1, $3, snd $1)}
| CASE expression COLON
    {CASE (fst $2, NOP $1, $1)}
| CASE expression ELLIPSIS expression COLON
    {CASERANGE (fst $2, fst $4, NOP $1, $1)}
| DEFAULT COLON
    {DEFAULT (NOP $1, $1)}
| RETURN SEMICOLON
    {RETURN (NOTHING, $1)}
| RETURN comma_expression SEMICOLON
    {RETURN (smooth_expression (fst $2), $1)}
| BREAK SEMICOLON
    {BREAK $1}
| CONTINUE SEMICOLON
    {CONTINUE $1}
| GOTO IDENT SEMICOLON
    {GOTO (fst $2, $1)}
| GOTO STAR comma_expression SEMICOLON
    { COMPGOTO (smooth_expression (fst $3), $1) }
| ASM asmattr LPAREN asmtemplate asmoutputs RPAREN SEMICOLON
    { let (outs,ins,clobs) = $5 in
                          ASM ($2, $4, outs, ins, clobs, $1) }
| MSASM
    { ASM ([], [fst $1], [], [], [], snd $1)}
| TRY block EXCEPT paren_comma_expression block
    { let b, _, _ = $2 in
                          let h, _, _ = $5 in
                          if not !Cprint.msvcMode then 
                            parse_error "try/except in GCC code";
                          TRY_EXCEPT (b, COMMA (fst $4), h, $1) }
| TRY block FINALLY block
    { let b, _, _ = $2 in
                          let h, _, _ = $4 in
                          if not !Cprint.msvcMode then 
                            parse_error "try/finally in GCC code";
                          TRY_FINALLY (b, h, $1) }
| error location SEMICOLON
    { (NOP $2)}

for_clause:
| opt_expression SEMICOLON
    { FC_EXP $1 }
| declaration
    { FC_DECL $1 }

declaration:
| decl_spec_list init_declarator_list SEMICOLON
    { doDeclaration (snd $1) (fst $1) $2 }
| decl_spec_list SEMICOLON
    { doDeclaration (snd $1) (fst $1) [] }

init_declarator_list:
| init_declarator
    { [$1] }
| init_declarator COMMA init_declarator_list
    { $1 :: $3 }

init_declarator:
| declarator
    { ($1, NO_INIT) }
| declarator EQ init_expression
    { ($1, $3) }

decl_spec_list:
| TYPEDEF decl_spec_list_opt
    { SpecTypedef :: $2, $1  }
| EXTERN decl_spec_list_opt
    { SpecStorage EXTERN :: $2, $1 }
| STATIC decl_spec_list_opt
    { SpecStorage STATIC :: $2, $1 }
| AUTO decl_spec_list_opt
    { SpecStorage AUTO :: $2, $1 }
| REGISTER decl_spec_list_opt
    { SpecStorage REGISTER :: $2, $1}
| type_spec decl_spec_list_opt_no_named
    { SpecType (fst $1) :: $2, snd $1 }
| INLINE decl_spec_list_opt
    { SpecInline :: $2, $1 }
| cvspec decl_spec_list_opt
    { (fst $1) :: $2, snd $1 }
| attribute_nocv decl_spec_list_opt
    { SpecAttr (fst $1) :: $2, snd $1 }
| AT_SPECIFIER LPAREN IDENT RPAREN
    { [ SpecPattern(fst $3) ], $1 }

decl_spec_list_opt:
|  %prec NAMED_TYPE
    { [] }
| decl_spec_list
    { fst $1 }

decl_spec_list_opt_no_named:
|  %prec IDENT
    { [] }
| decl_spec_list
    { fst $1 }

type_spec:
| VOID
    { Tvoid, $1}
| CHAR
    { Tchar, $1 }
| SHORT
    { Tshort, $1 }
| INT
    { Tint, $1 }
| LONG
    { Tlong, $1 }
| INT64
    { Tint64, $1 }
| FLOAT
    { Tfloat, $1 }
| DOUBLE
    { Tdouble, $1 }
| SIGNED
    { Tsigned, $1 }
| UNSIGNED
    { Tunsigned, $1 }
| STRUCT id_or_typename
    { Tstruct ($2, None,    []), $1 }
| STRUCT id_or_typename LBRACE struct_decl_list RBRACE
    { Tstruct ($2, Some $4, []), $1 }
| STRUCT LBRACE struct_decl_list RBRACE
    { Tstruct ("", Some $3, []), $1 }
| STRUCT just_attributes id_or_typename LBRACE struct_decl_list RBRACE
    { Tstruct ($3, Some $5, $2), $1 }
| STRUCT just_attributes LBRACE struct_decl_list RBRACE
    { Tstruct ("", Some $4, $2), $1 }
| UNION id_or_typename
    { Tunion  ($2, None,    []), $1 }
| UNION id_or_typename LBRACE struct_decl_list RBRACE
    { Tunion  ($2, Some $4, []), $1 }
| UNION LBRACE struct_decl_list RBRACE
    { Tunion  ("", Some $3, []), $1 }
| UNION just_attributes id_or_typename LBRACE struct_decl_list RBRACE
    { Tunion  ($3, Some $5, $2), $1 }
| UNION just_attributes LBRACE struct_decl_list RBRACE
    { Tunion  ("", Some $4, $2), $1 }
| ENUM id_or_typename
    { Tenum   ($2, None,    []), $1 }
| ENUM id_or_typename LBRACE enum_list maybecomma RBRACE
    { Tenum   ($2, Some $4, []), $1 }
| ENUM LBRACE enum_list maybecomma RBRACE
    { Tenum   ("", Some $3, []), $1 }
| ENUM just_attributes id_or_typename LBRACE enum_list maybecomma RBRACE
    { Tenum   ($3, Some $5, $2), $1 }
| ENUM just_attributes LBRACE enum_list maybecomma RBRACE
    { Tenum   ("", Some $4, $2), $1 }
| NAMED_TYPE
    { Tnamed (fst $1), snd $1 }
| TYPEOF LPAREN expression RPAREN
    { TtypeofE (fst $3), $1 }
| TYPEOF LPAREN type_name RPAREN
    { let s, d = $3 in
                                          TtypeofT (s, d), $1 }

struct_decl_list:
| 
    { [] }
| decl_spec_list SEMICOLON struct_decl_list
    { (fst $1, 
                                            [(missingFieldDecl, None)]) :: $3 }
| SEMICOLON struct_decl_list
    { $2 }
| decl_spec_list field_decl_list SEMICOLON struct_decl_list
    { (fst $1, $2) 
                                            :: $4 }
| error SEMICOLON struct_decl_list
    { $3 }

field_decl_list:
| field_decl
    { [$1] }
| field_decl COMMA field_decl_list
    { $1 :: $3 }

field_decl:
| declarator
    { ($1, None) }
| declarator COLON expression
    { ($1, Some (fst $3)) }
| COLON expression
    { (missingFieldDecl, Some (fst $2)) }

enum_list:
| enumerator
    {[$1]}
| enum_list COMMA enumerator
    {$1 @ [$3]}
| enum_list COMMA error
    { $1 }

enumerator:
| IDENT
    {(fst $1, NOTHING, snd $1)}
| IDENT EQ expression
    {(fst $1, fst $3, snd $1)}

declarator:
| pointer_opt direct_decl attributes_with_asm
    { let (n, decl) = $2 in
                                           (n, applyPointer (fst $1) decl, $3, snd $1) }

direct_decl:
| id_or_typename
    { ($1, JUSTBASE) }
| LPAREN attributes declarator RPAREN
    { let (n,decl,al,loc) = $3 in
                                     (n, PARENTYPE($2,decl,al)) }
| direct_decl LBRACKET attributes comma_expression_opt RBRACKET
    { let (n, decl) = $1 in
                                     (n, ARRAY(decl, $3, $4)) }
| direct_decl LBRACKET attributes error RBRACKET
    { let (n, decl) = $1 in
                                     (n, ARRAY(decl, $3, NOTHING)) }
| direct_decl parameter_list_startscope rest_par_list RPAREN
    { let (n, decl) = $1 in
                                     let (params, isva) = $3 in
                                     !Lexerhack.pop_context ();
                                     (n, PROTO(decl, params, isva))
                                   }

parameter_list_startscope:
| LPAREN
    { !Lexerhack.push_context () }

rest_par_list:
| 
    { ([], false) }
| parameter_decl rest_par_list1
    { let (params, isva) = $2 in 
                                     ($1 :: params, isva) 
                                   }

rest_par_list1:
| 
    { ([], false) }
| COMMA ELLIPSIS
    { ([], true) }
| COMMA parameter_decl rest_par_list1
    { let (params, isva) = $3 in 
                                          ($2 :: params, isva)
                                        }

parameter_decl:
| decl_spec_list declarator
    { (fst $1, $2) }
| decl_spec_list abstract_decl
    { let d, a = $2 in
                                            (fst $1, ("", d, a, cabslu)) }
| decl_spec_list
    { (fst $1, ("", JUSTBASE, [], cabslu)) }
| LPAREN parameter_decl RPAREN
    { $2 }

old_proto_decl:
| pointer_opt direct_old_proto_decl
    { let (n, decl, a) = $2 in
					  (n, applyPointer (fst $1) decl, a, snd $1) }

direct_old_proto_decl:
| direct_decl LPAREN old_parameter_list_ne RPAREN old_pardef_list
    { let par_decl, isva = doOldParDecl $3 $5 in
                                     let n, decl = $1 in
                                     (n, PROTO(decl, par_decl, isva), [])
                                   }
| direct_decl LPAREN RPAREN
    { let n, decl = $1 in
                                     (n, PROTO(decl, [], false), [])
                                   }

old_parameter_list_ne:
| IDENT
    { [fst $1] }
| IDENT COMMA old_parameter_list_ne
    { let rest = $3 in
                                                 (fst $1 :: rest) }

old_pardef_list:
| 
    { ([], false) }
| decl_spec_list old_pardef SEMICOLON ELLIPSIS
    { ([(fst $1, $2)], true) }
| decl_spec_list old_pardef SEMICOLON old_pardef_list
    { let rest, isva = $4 in
                                            ((fst $1, $2) :: rest, isva) 
                                          }

old_pardef:
| declarator
    { [$1] }
| declarator COMMA old_pardef
    { $1 :: $3 }
| error
    { [] }

pointer:
| STAR attributes pointer_opt
    { $2 :: fst $3, $1 }

pointer_opt:
| 
    { [], currentLoc () }
| pointer
    { $1 }

type_name:
| decl_spec_list abstract_decl
    { let d, a = $2 in
                                 if a <> [] then begin
                                   parse_error "attributes in type name";
                                   raise Parsing.Parse_error
                                 end;
                                 (fst $1, d) 
                               }
| decl_spec_list
    { (fst $1, JUSTBASE) }

abstract_decl:
| pointer_opt abs_direct_decl attributes
    { applyPointer (fst $1) $2, $3 }
| pointer
    { applyPointer (fst $1) JUSTBASE, [] }

abs_direct_decl:
| LPAREN attributes abstract_decl RPAREN
    { let d, a = $3 in
                                     PARENTYPE ($2, d, a)
                                   }
| LPAREN error RPAREN
    { JUSTBASE }
| abs_direct_decl_opt LBRACKET comma_expression_opt RBRACKET
    { ARRAY($1, [], $3) }
| abs_direct_decl parameter_list_startscope rest_par_list RPAREN
    { let (params, isva) = $3 in
                                     !Lexerhack.pop_context ();
                                     PROTO ($1, params, isva)
                                   }

abs_direct_decl_opt:
| abs_direct_decl
    { $1 }
| 
    { JUSTBASE }

function_def:
| function_def_start block
    { let (loc, specs, decl) = $1 in
            currentFunctionName := "<__FUNCTION__ used outside any functions>";
            !Lexerhack.pop_context (); (* The context pushed by 
                                    * announceFunctionName *)
            doFunctionDef loc (trd3 $2) specs decl (fst3 $2)
          }

function_def_start:
| decl_spec_list declarator
    { announceFunctionName $2;
                              (snd $1, fst $1, $2)
                            }
| decl_spec_list old_proto_decl
    { announceFunctionName $2;
                              (snd $1, fst $1, $2)
                            }
| IDENT parameter_list_startscope rest_par_list RPAREN
    { let (params, isva) = $3 in
                             let fdec = 
                               (fst $1, PROTO(JUSTBASE, params, isva), [], snd $1) in
                             announceFunctionName fdec;
                             (* Default is int type *)
                             let defSpec = [SpecType Tint] in
                             (snd $1, defSpec, fdec)
                           }
| IDENT LPAREN old_parameter_list_ne RPAREN old_pardef_list
    { (* Convert pardecl to new style *)
                             let pardecl, isva = doOldParDecl $3 $5 in
                             (* Make the function declarator *)
                             let fdec = (fst $1,
                                         PROTO(JUSTBASE, pardecl,isva), 
                                         [], snd $1) in
                             announceFunctionName fdec;
                             (* Default is int type *)
                             let defSpec = [SpecType Tint] in
                             (snd $1, defSpec, fdec) 
                            }
| IDENT LPAREN RPAREN
    { (* Make the function declarator *)
                             let fdec = (fst $1,
                                         PROTO(JUSTBASE, [], false), 
                                         [], snd $1) in
                             announceFunctionName fdec;
                             (* Default is int type *)
                             let defSpec = [SpecType Tint] in
                             (snd $1, defSpec, fdec)
                            }

cvspec:
| CONST
    { SpecCV(CV_CONST), $1 }
| VOLATILE
    { SpecCV(CV_VOLATILE), $1 }
| RESTRICT
    { SpecCV(CV_RESTRICT), $1 }

attributes:
| 
    { []}
| attribute attributes
    { fst $1 :: $2 }

attributes_with_asm:
| 
    { [] }
| attribute attributes_with_asm
    { fst $1 :: $2 }
| ASM LPAREN string_constant RPAREN attributes
    { ("__asm__", 
					   [CONSTANT(CONST_STRING (fst $3))]) :: $5 }

attribute_nocv:
| ATTRIBUTE LPAREN paren_attr_list_ne RPAREN
    { ("__attribute__", $3), $1 }
| DECLSPEC paren_attr_list_ne
    { ("__declspec", $2), $1 }
| MSATTR
    { (fst $1, []), snd $1 }
| THREAD
    { ("__thread",[]), $1 }

attribute:
| attribute_nocv
    { $1 }
| CONST
    { ("const", []), $1 }
| RESTRICT
    { ("restrict",[]), $1 }
| VOLATILE
    { ("volatile",[]), $1 }

just_attribute:
| ATTRIBUTE LPAREN paren_attr_list_ne RPAREN
    { ("__attribute__", $3) }
| DECLSPEC paren_attr_list_ne
    { ("__declspec", $2) }

just_attributes:
| just_attribute
    { [$1] }
| just_attribute just_attributes
    { $1 :: $2 }

primary_attr:
| IDENT
    { VARIABLE (fst $1) }
| NAMED_TYPE
    { VARIABLE (fst $1) }
| LPAREN attr RPAREN
    { $2 }
| IDENT IDENT
    { CALL(VARIABLE (fst $1), [VARIABLE (fst $2)]) }
| CST_INT
    { CONSTANT(CONST_INT (fst $1)) }
| string_constant
    { CONSTANT(CONST_STRING (fst $1)) }
| CONST
    { VARIABLE "aconst" }
| IDENT COLON CST_INT
    { VARIABLE (fst $1 ^ ":" ^ fst $3) }
| CST_INT COLON CST_INT
    { VARIABLE (fst $1 ^ ":" ^ fst $3) }
| DEFAULT COLON CST_INT
    { VARIABLE ("default:" ^ fst $3) }
| VOLATILE
    { VARIABLE ("__noreturn__") }

postfix_attr:
| primary_attr
    { $1 }
| IDENT LPAREN RPAREN
    { CALL(VARIABLE (fst $1), [VARIABLE ""]) }
| IDENT paren_attr_list_ne
    { CALL(VARIABLE (fst $1), $2) }
| postfix_attr ARROW id_or_typename
    {MEMBEROFPTR ($1, $3)}
| postfix_attr DOT id_or_typename
    {MEMBEROF ($1, $3)}

unary_attr:
| postfix_attr
    { $1 }
| SIZEOF unary_expression
    {EXPR_SIZEOF (fst $2) }
| SIZEOF LPAREN type_name RPAREN
    {let b, d = $3 in TYPE_SIZEOF (b, d)}
| ALIGNOF unary_expression
    {EXPR_ALIGNOF (fst $2) }
| ALIGNOF LPAREN type_name RPAREN
    {let b, d = $3 in TYPE_ALIGNOF (b, d)}
| PLUS cast_attr
    {UNARY (PLUS, $2)}
| MINUS cast_attr
    {UNARY (MINUS, $2)}
| STAR cast_attr
    {UNARY (MEMOF, $2)}
| AND cast_attr
    {UNARY (ADDROF, $2)}
| EXCLAM cast_attr
    {UNARY (NOT, $2)}
| TILDE cast_attr
    {UNARY (BNOT, $2)}

cast_attr:
| unary_attr
    { $1 }

multiplicative_attr:
| cast_attr
    { $1 }
| multiplicative_attr STAR cast_attr
    {BINARY(MUL ,$1 , $3)}
| multiplicative_attr SLASH cast_attr
    {BINARY(DIV ,$1 , $3)}
| multiplicative_attr PERCENT cast_attr
    {BINARY(MOD ,$1 , $3)}

additive_attr:
| multiplicative_attr
    { $1 }
| additive_attr PLUS multiplicative_attr
    {BINARY(ADD ,$1 , $3)}
| additive_attr MINUS multiplicative_attr
    {BINARY(SUB ,$1 , $3)}

shift_attr:
| additive_attr
    { $1 }
| shift_attr INF_INF additive_attr
    {BINARY(SHL ,$1 , $3)}
| shift_attr SUP_SUP additive_attr
    {BINARY(SHR ,$1 , $3)}

relational_attr:
| shift_attr
    { $1 }
| relational_attr INF shift_attr
    {BINARY(LT ,$1 , $3)}
| relational_attr SUP shift_attr
    {BINARY(GT ,$1 , $3)}
| relational_attr INF_EQ shift_attr
    {BINARY(LE ,$1 , $3)}
| relational_attr SUP_EQ shift_attr
    {BINARY(GE ,$1 , $3)}

equality_attr:
| relational_attr
    { $1 }
| equality_attr EQ_EQ relational_attr
    {BINARY(EQ ,$1 , $3)}
| equality_attr EXCLAM_EQ relational_attr
    {BINARY(NE ,$1 , $3)}

bitwise_and_attr:
| equality_attr
    { $1 }
| bitwise_and_attr AND equality_attr
    {BINARY(BAND ,$1 , $3)}

bitwise_xor_attr:
| bitwise_and_attr
    { $1 }
| bitwise_xor_attr CIRC bitwise_and_attr
    {BINARY(XOR ,$1 , $3)}

bitwise_or_attr:
| bitwise_xor_attr
    { $1 }
| bitwise_or_attr PIPE bitwise_xor_attr
    {BINARY(BOR ,$1 , $3)}

logical_and_attr:
| bitwise_or_attr
    { $1 }
| logical_and_attr AND_AND bitwise_or_attr
    {BINARY(AND ,$1 , $3)}

logical_or_attr:
| logical_and_attr
    { $1 }
| logical_or_attr PIPE_PIPE logical_and_attr
    {BINARY(OR ,$1 , $3)}

attr:
| logical_or_attr
    { $1 }

attr_list_ne:
| attr
    { [$1] }
| attr COMMA attr_list_ne
    { $1 :: $3 }
| error COMMA attr_list_ne
    { $3 }

paren_attr_list_ne:
| LPAREN attr_list_ne RPAREN
    { $2 }
| LPAREN error RPAREN
    { [] }

asmattr:
| 
    { [] }
| VOLATILE asmattr
    { ("volatile", []) :: $2 }
| CONST asmattr
    { ("const", []) :: $2 }

asmtemplate:
| one_string_constant
    { [$1] }
| one_string_constant asmtemplate
    { $1 :: $2 }

asmoutputs:
| 
    { ([], [], []) }
| COLON asmoperands asminputs
    { let (ins, clobs) = $3 in
                          ($2, ins, clobs) }

asmoperands:
| 
    { [] }
| asmoperandsne
    { List.rev $1 }

asmoperandsne:
| asmoperand
    { [$1] }
| asmoperandsne COMMA asmoperand
    { $3 :: $1 }

asmoperand:
| string_constant LPAREN expression RPAREN
    { (fst $1, fst $3) }
| string_constant LPAREN error RPAREN
    { (fst $1, NOTHING ) }

asminputs:
| 
    { ([], []) }
| COLON asmoperands asmclobber
    { ($2, $3) }

asmclobber:
| 
    { [] }
| COLON asmcloberlst_ne
    { $2 }

asmcloberlst_ne:
| one_string_constant
    { [$1] }
| one_string_constant COMMA asmcloberlst_ne
    { $1 :: $3 }

%%