]> git.saurik.com Git - wxWidgets.git/blame - src/common/parser.y
fixed bug in parsing filenames without paths, added more/better tests
[wxWidgets.git] / src / common / parser.y
CommitLineData
cfe780fb 1 %{
d427503c 2#include "wx/setup.h"
cfe780fb 3#include <string.h>
b8c631bb
JS
4#ifdef _MSC_VER
5#include <io.h>
6#endif
57c208c5 7#if defined(__GNUWIN32__) && !defined(__TWIN32__)
27529614
JS
8#include <sys/unistd.h>
9#endif
b8c631bb 10
cfe780fb
JS
11#include "wx/expr.h"
12
13#ifndef __EXTERN_C__
14#define __EXTERN_C__ 1
15#endif
16
17#if defined(__cplusplus) || defined(__STDC__)
18#if defined(__cplusplus) && defined(__EXTERN_C__)
19extern "C" {
20#endif
21#endif
22int yylex(void);
23int yylook(void);
24int yywrap(void);
25int yyback(int *, int);
26void yyerror(char *);
27
28/* You may need to put /DLEX_SCANNER in your makefile
29 * if you're using LEX!
30 */
cfe780fb 31void yyoutput(int);
cfe780fb
JS
32
33#if defined(__cplusplus) || defined(__STDC__)
34#if defined(__cplusplus) && defined(__EXTERN_C__)
35}
36#endif
37#endif
38%}
39
40%union {
41 char *s;
42/* struct pexpr *expr; */
43}
44
45
46%start commands
47
48%token <s> INTEGER 1
49%token <s> WORD 2
50%token <s> STRING 3
51%token <s> PERIOD 13
52%token OPEN 4
53%token CLOSE 5
54%token COMMA 6
55%token NEWLINE 7
56%token ERROR 8
57%token OPEN_SQUARE 9
58%token CLOSE_SQUARE 10
59%token EQUALS 11
60%token EXP 14
61
62/* %type <expr> command expr arglist arg arg1 */
63%type <s> command expr arglist arg arg1
64
65%%
66
67commands : /* empty */
68 | commands command
69 ;
70
71command : WORD PERIOD
5b077d48 72 {process_command(proio_cons(wxmake_word($1), NULL)); free($1);}
cfe780fb
JS
73 | expr PERIOD
74 {process_command($1);}
75 | error PERIOD
76 {syntax_error("Unrecognized command.");}
77 ;
78
79expr : WORD OPEN arglist CLOSE
5b077d48 80 {$$ = proio_cons(wxmake_word($1), $3); free($1);}
cfe780fb
JS
81 | OPEN_SQUARE arglist CLOSE_SQUARE
82 {$$ = $2; }
83 ;
84
85arglist :
cb73d83f 86 {$$ = proio_cons(NULL, NULL);}
cfe780fb
JS
87 | arg
88 {$$ = proio_cons($1, NULL);}
89 |
90 arg COMMA arglist
91 {$$ = proio_cons($1, $3);}
92 ;
93
94arg : WORD EQUALS arg1
5b077d48 95 {$$ = proio_cons(wxmake_word("="), proio_cons(wxmake_word($1), proio_cons($3, NULL)));
cfe780fb
JS
96 free($1); }
97 | arg1
98 {$$ = $1; }
99
100arg1 : WORD
5b077d48 101 {$$ = wxmake_word($1); free($1);}
cfe780fb 102 | STRING
5b077d48 103 {$$ = wxmake_string($1); free($1);}
cfe780fb 104 | INTEGER
5b077d48 105 {$$ = wxmake_integer($1); free($1);}
cfe780fb 106 | INTEGER PERIOD INTEGER
5b077d48 107 {$$ = wxmake_real($1, $3); free($1); free($3); }
cfe780fb 108 | INTEGER EXP INTEGER
5b077d48 109 {$$ = wxmake_exp($1, $3); free($1); free($3); }
cfe780fb
JS
110 |
111 INTEGER PERIOD INTEGER EXP INTEGER
5b077d48 112 {$$ = wxmake_exp2($1, $3, $5); free($1); free($3);
cfe780fb
JS
113 free($5); }
114
115 | expr
116 {$$ = $1;}
117 ;
118
119%%
120
80d895cd
HH
121/* We include lexer.c if we are building for gtk, wine or motif
122 * and also whenever we are using configure (marked by __WX_SETUP_H__) for,
123 * for example, cross compilation. */
124#if (defined(__WXGTK__) || defined(__WXWINE__) || defined(__WXMOTIF__)) || defined(__WX_SETUP_H__) && !defined(NO_CONFIGURE)
6de97a3b
RR
125#include "lexer.c"
126#else
469e1e5c
SC
127#if (defined(__MWERKS__))
128#include "../common/cwlex_yy.c"
129#else
cfe780fb 130#include "../common/lex_yy.c"
6de97a3b 131#endif
469e1e5c 132#endif
cfe780fb
JS
133
134/*
135void yyerror(s)
136char *s;
137{
138 syntax_error(s);
139}
140*/
141
142/* Ansi prototype. If this doesn't work for you... uncomment
143 the above instead.
144 */
145
146void yyerror(char *s)
147{
148 syntax_error(s);
149}
150
151/*
152 * Unfortunately, my DOS version of FLEX
153 * requires yywrap to be #def'ed, whereas
154 * the UNIX flex expects a proper function.
155 */
156
f6bcfd97
BP
157/* At least on alphaev6-dec-osf4.0e yywrap() must be #define'd */
158#if defined( __ALPHA__ ) && !defined( __VMS__ )
159#ifndef yywrap
160#define yywrap() 1
161#endif
162#else
08998996
HH
163/* HH: Added test for __WX_SETUP_H__ for gnuwin builds
164 * using configure */
165#if !defined(__SC__) && !defined(__GNUWIN32__)
cfe780fb
JS
166#ifdef USE_DEFINE
167#ifndef yywrap
168#define yywrap() 1
169#endif
742ff1e1 170#elif !defined(__ultrix)
cfe780fb 171int yywrap() { return 1; }
59f03363
JJ
172#elif defined(__VMS__)
173int yywrap() { return 1; }
cfe780fb 174#endif
08998996
HH
175#elif defined(__WX_SETUP_H__)
176int yywrap() { return 1; }
cfe780fb 177#endif
f6bcfd97
BP
178#endif
179