]> git.saurik.com Git - wxWidgets.git/blob - src/common/lexer.l
DialogEd compiles and works more or less
[wxWidgets.git] / src / common / lexer.l
1 SIGN [+-]
2 DIGIT [0-9]
3 ALPHA [a-zA-Z_]
4 ALPHADIGIT [a-zA-Z_0-9]
5 STRINGCHAR [^"\\]
6 WORDCHAR [^'\\]
7
8 %{
9 /*
10 * File: lexer.l
11 * Description: Lexical analyser for PROLOGIO; can be used with
12 * either lex and flex.
13 */
14 #include <string.h>
15
16 /* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX)
17 please check, if this is also TRUE under other UNIXes.
18 */
19
20 #if defined(FLEX_SCANNER) && defined(_LINUX)
21 #define PROIO_input my_input
22 #endif
23 /* ---steve162e */
24
25 #include "wx/expr.h"
26
27 #ifdef wx_x
28 extern char *malloc();
29 #endif
30 #define Return(x) return x;
31
32 #if defined(VMS) && !defined(strdup)
33 #define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s));
34 #endif
35
36 static size_t lex_buffer_length = 0;
37 static const char *lex_buffer = NULL;
38 static size_t lex_string_ptr = 0;
39 static int lex_read_from_string = 0;
40
41 static int my_input(void);
42 static int my_unput(char);
43
44 #ifdef FLEX_SCANNER
45 #undef YY_INPUT
46 # define YY_INPUT(buf,result,max_size) \
47 if (lex_read_from_string) \
48 { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \
49 else \
50 if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
51 YY_FATAL_ERROR( "read() in flex scanner failed" );
52 #else
53 # undef unput
54 # define unput(_c) my_unput(_c)
55 #endif
56
57 %}
58
59 %%
60
61 {SIGN}?{DIGIT}+ {yylval.s = strdup(yytext); Return(INTEGER);}
62
63 "e" Return(EXP);
64
65 {ALPHA}{ALPHADIGIT}* {yylval.s = strdup(yytext); Return(WORD);}
66
67 "'"{WORDCHAR}*"'" {int len = strlen(yytext);
68 yytext[len-1] = 0;
69 yylval.s = strdup(yytext+1);
70 Return(WORD);}
71
72 \"({STRINGCHAR}|\\\"|\|\\\\|\\)*\" {yylval.s = strdup(yytext); Return(STRING);}
73
74 "(" Return(OPEN);
75
76 ")" Return(CLOSE);
77
78 "," Return(COMMA);
79
80 "[" Return(OPEN_SQUARE);
81
82 "]" Return(CLOSE_SQUARE);
83
84 "=" Return(EQUALS);
85
86 "." Return(PERIOD);
87
88 [ \t] ;
89
90 \n ;
91
92 "/*" { loop:
93 #ifdef __cplusplus
94 while (yyinput() != '*');
95 switch (yyinput())
96 #else
97 while (input() != '*');
98 switch (input())
99 #endif
100 {
101 case '/': break;
102 case '*': unput('*');
103 default: goto loop;
104 }
105 }
106
107 . Return(ERROR);
108
109 %%
110
111
112 #ifdef FLEX_SCANNER
113 static int lex_input() {
114 return input();
115 }
116 #else /* BSD/AT&T lex */
117 #ifndef input
118 # error "Sorry, but need either flex or AT&T lex"
119 #endif
120 static int lex_input() {
121 return input();
122 }
123 /* # undef unput
124 # define unput(_c) my_unput(_c)
125 */
126
127 # undef input
128 # define input() my_input()
129 static int my_unput(char c)
130 {
131 if (lex_read_from_string) {
132 /* Make sure we have something */
133 if (lex_string_ptr) {
134 if (c == '\n') yylineno--;
135 lex_string_ptr--;
136 }
137 } else {
138 yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;
139 /* unput(c); Causes infinite recursion! */
140 }
141 return c;
142 }
143
144 #endif
145
146 /* Public */
147 void LexFromFile(FILE *fd)
148 {
149 lex_read_from_string = 0;
150 yyin = fd;
151 /* Don't know why this is necessary, but otherwise
152 * lex only works _once_!
153 */
154 #ifdef FLEX_SCANNER
155 yyrestart(fd);
156 yy_init = 1;
157 #endif
158 }
159
160 void LexFromString(char *buffer)
161 {
162 lex_read_from_string = 1;
163 lex_buffer = buffer;
164 lex_buffer_length = strlen(buffer);
165 lex_string_ptr = 0;
166 /* Don't know why this is necessary, but otherwise
167 * lex only works _once_!
168 */
169 #ifdef FLEX_SCANNER
170 yy_init = 1;
171 #endif
172 }
173
174 static int my_input( void )
175 {
176 if (lex_read_from_string) {
177 if (lex_string_ptr == lex_buffer_length)
178 return 0;
179 else {
180 char c = lex_buffer[lex_string_ptr++];
181 #ifndef FLEX_SCANNER
182 if (c == '\n') yylineno++;
183 #endif
184 return c;
185 }
186 } else {
187 return lex_input();
188 }
189 }
190
191 void wxExprCleanUp()
192 {
193 if (yy_current_buffer)
194 yy_delete_buffer(yy_current_buffer);
195 }