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