OSDN Git Service

Slight build improvements
[mingw/pexports.git] / hparse.y
1 %{
2 #include <string.h>
3 #include <stdio.h>
4
5 #include "pexports.h"
6
7
8 static int inc_flag = 1;
9 static int arg_size = 0;
10
11 extern int yylex(void);
12
13 static void yyerror(char *s);
14
15 #define INC_ARGS(n) arg_size += (inc_flag ? n : 0)
16 %}
17
18 %union {
19        char *s;
20 };
21
22 %token <s> ID
23
24 %type <s> type_name
25 %%
26
27 start
28         : function_declaration
29         | start function_declaration
30         ;
31
32 function_declaration
33         : type_name '(' parameter_list ')' ';'
34         {
35           ADD_FUNCTION($1, arg_size);
36           arg_size = 0;
37         }
38         | type_name '(' ')' ';'
39         {
40           ADD_FUNCTION($1, 0);
41           arg_size = 0;
42         }
43         | error { arg_size = 0; yyclearin; }
44         ;
45
46 type_name
47         : ID
48         | ID pointer
49         { $$ = ""; }
50         | type_name ID
51         { $$ = $2; }
52         | type_name ID pointer
53         { $$ = ""; }
54         | type_name function_pointer
55         { $$ = ""; }
56         ;
57
58 function_pointer
59         : '(' function_pointer_name ')' '(' ')'
60         {}
61         | '(' function_pointer_name ')' '(' 
62         { inc_flag = 0; }
63         parameter_list ')'
64         { inc_flag = 1; }
65         ;
66
67 function_pointer_name
68         : pointer
69         | pointer ID
70         ;
71
72 pointer
73         : '*'
74         | '*' pointer
75         ;
76
77 parameter_declaration
78         : type_name
79         {
80           if (strcmp($1, "POINT") == 0)
81             INC_ARGS(8);
82           else if (strcmp($1, "RECT") == 0)
83             INC_ARGS(16);
84           else if (strcmp($1, "float") == 0)
85             INC_ARGS(sizeof(float));
86           else if (strcmp($1, "double") == 0)
87             INC_ARGS(sizeof(double));
88           else if (strcmp($1, "void") != 0)
89             INC_ARGS(4);
90         }
91         ;
92
93 parameter_list
94         : parameter_declaration
95         | parameter_list ',' parameter_declaration
96         ;
97
98 %%
99 static void
100 yyerror(char *s)
101 {
102   /* ignore error */
103   arg_size = 0;
104 }