]> git.saurik.com Git - wxWidgets.git/blob - src/common/parser.y
Compile and build fixes for wxGTK and wxMotif
[wxWidgets.git] / src / common / parser.y
1 %{
2 #include <string.h>
3 #ifdef _MSC_VER
4 #include <io.h>
5 #endif
6 #ifdef __GNUWIN32__
7 #include <sys/unistd.h>
8 #endif
9
10 #include "wx/expr.h"
11
12 #ifndef __EXTERN_C__
13 #define __EXTERN_C__ 1
14 #endif
15
16 #if defined(__cplusplus) || defined(__STDC__)
17 #if defined(__cplusplus) && defined(__EXTERN_C__)
18 extern "C" {
19 #endif
20 #endif
21 int yylex(void);
22 int yylook(void);
23 int yywrap(void);
24 int yyback(int *, int);
25 void yyerror(char *);
26
27 /* You may need to put /DLEX_SCANNER in your makefile
28 * if you're using LEX!
29 */
30 #ifdef LEX_SCANNER
31 /* int yyoutput(int); */
32 void yyoutput(int);
33 #else
34 void yyoutput(int);
35 #endif
36
37 #if defined(__cplusplus) || defined(__STDC__)
38 #if defined(__cplusplus) && defined(__EXTERN_C__)
39 }
40 #endif
41 #endif
42 %}
43
44 %union {
45 char *s;
46 /* struct pexpr *expr; */
47 }
48
49
50 %start commands
51
52 %token <s> INTEGER 1
53 %token <s> WORD 2
54 %token <s> STRING 3
55 %token <s> PERIOD 13
56 %token OPEN 4
57 %token CLOSE 5
58 %token COMMA 6
59 %token NEWLINE 7
60 %token ERROR 8
61 %token OPEN_SQUARE 9
62 %token CLOSE_SQUARE 10
63 %token EQUALS 11
64 %token EXP 14
65
66 /* %type <expr> command expr arglist arg arg1 */
67 %type <s> command expr arglist arg arg1
68
69 %%
70
71 commands : /* empty */
72 | commands command
73 ;
74
75 command : WORD PERIOD
76 {process_command(proio_cons(make_word($1), NULL)); free($1);}
77 | expr PERIOD
78 {process_command($1);}
79 | error PERIOD
80 {syntax_error("Unrecognized command.");}
81 ;
82
83 expr : WORD OPEN arglist CLOSE
84 {$$ = proio_cons(make_word($1), $3); free($1);}
85 | OPEN_SQUARE CLOSE_SQUARE
86 {$$ = proio_cons(NULL, NULL);}
87 | OPEN_SQUARE arglist CLOSE_SQUARE
88 {$$ = $2; }
89 ;
90
91 arglist :
92 {$$ = NULL;}
93 | arg
94 {$$ = proio_cons($1, NULL);}
95 |
96 arg COMMA arglist
97 {$$ = proio_cons($1, $3);}
98 ;
99
100 arg : WORD EQUALS arg1
101 {$$ = proio_cons(make_word("="), proio_cons(make_word($1), proio_cons($3, NULL)));
102 free($1); }
103 | arg1
104 {$$ = $1; }
105
106 arg1 : WORD
107 {$$ = make_word($1); free($1);}
108 | STRING
109 {$$ = make_string($1); free($1);}
110 | INTEGER
111 {$$ = make_integer($1); free($1);}
112 | INTEGER PERIOD INTEGER
113 {$$ = make_real($1, $3); free($1); free($3); }
114 | INTEGER EXP INTEGER
115 {$$ = make_exp($1, $3); free($1); free($3); }
116 |
117 INTEGER PERIOD INTEGER EXP INTEGER
118 {$$ = make_exp2($1, $3, $5); free($1); free($3);
119 free($5); }
120
121 | expr
122 {$$ = $1;}
123 ;
124
125 %%
126
127 #ifdef __WXGTK__
128 #include "lexer.c"
129 #else
130 #include "../common/lex_yy.c"
131 #endif
132
133 /*
134 void yyerror(s)
135 char *s;
136 {
137 syntax_error(s);
138 }
139 */
140
141 /* Ansi prototype. If this doesn't work for you... uncomment
142 the above instead.
143 */
144
145 void yyerror(char *s)
146 {
147 syntax_error(s);
148 }
149
150 /*
151 * Unfortunately, my DOS version of FLEX
152 * requires yywrap to be #def'ed, whereas
153 * the UNIX flex expects a proper function.
154 */
155
156 /* Not sure if __SC__ is the appropriate thing
157 * to test
158 */
159
160 #ifndef __SC__
161 #ifdef USE_DEFINE
162 #ifndef yywrap
163 #define yywrap() 1
164 #endif
165 #else if !defined(__alpha) && !defined(__ultrix)
166 int yywrap() { return 1; }
167 #endif
168 #endif