]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/deprecated/lexer.l
Removed useless pragma after fixing code to use insigned ints.
[wxWidgets.git] / contrib / src / deprecated / 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 * Copyright: (c) Julian Smart
14 * Licence: wxWindows Licence
15 */
16 #include <string.h>
17 #include <unistd.h>
18
19 /* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX)
20 please check, if this is also TRUE under other UNIXes.
21 */
22
23 #if defined(FLEX_SCANNER) && defined(_LINUX)
24 #define PROIO_input my_input
25 #endif
26 /* ---steve162e */
27
28 #include "wx/deprecated/expr.h"
29
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
43 #ifdef FLEX_SCANNER
44 # undef YY_INPUT
45 # define YY_INPUT(buf,result,max_size) \
46 if (lex_read_from_string) \
47 { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \
48 else \
49 if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
50 YY_FATAL_ERROR( "read() in flex scanner failed" );
51 #else
52 # undef unput
53 # define unput(_c) my_unput(_c)
54 static int my_unput(char);
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
124 # undef input
125 # define input() my_input()
126 static int my_unput(char c)
127 {
128 if (lex_read_from_string != 0) {
129 /* Make sure we have something */
130 if (lex_string_ptr) {
131 if (c == '\n') yylineno--;
132 lex_string_ptr--;
133 }
134 } else {
135 yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;
136 /* unput(c); Causes infinite recursion! */
137 }
138 return c;
139 }
140
141 #endif
142
143 /* Public */
144 void LexFromFile(FILE *fd)
145 {
146 lex_read_from_string = 0;
147 yyin = fd;
148 /* Don't know why this is necessary, but otherwise
149 * lex only works _once_!
150 */
151 #ifdef FLEX_SCANNER
152 yyrestart(fd);
153 yy_init = 1;
154 #endif
155 }
156
157 void LexFromString(char *buffer)
158 {
159 lex_read_from_string = 1;
160 lex_buffer = buffer;
161 lex_buffer_length = strlen(buffer);
162 lex_string_ptr = 0;
163 /* Don't know why this is necessary, but otherwise
164 * lex only works _once_!
165 */
166 #ifdef FLEX_SCANNER
167 yy_init = 1;
168 #endif
169 }
170
171 static int my_input( void )
172 {
173 if (lex_read_from_string) {
174 if (lex_string_ptr == lex_buffer_length)
175 return 0;
176 else {
177 char c = lex_buffer[lex_string_ptr++];
178 #ifndef FLEX_SCANNER
179 if (c == '\n') yylineno++;
180 #endif
181 return c;
182 }
183 } else {
184 return lex_input();
185 }
186 }
187
188 void wxExprCleanUp()
189 {
190 #ifdef FLEX_SCANNER
191 if (yy_current_buffer)
192 yy_delete_buffer(yy_current_buffer);
193 #endif
194 }