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