|
|
1.1 root 1: %{
2: /*
3: * texttoip - convert a textual representation of interpress to a real
4: * interpress file. The text produced by "iptotext" is the input
5: * that is recognized.
6: *
7: * This is the lex specification of the input scanner.
8: *
9: * Written for Xerox Corporation by William LeFebvre
10: *
11: * 6-May-1984
12: *
13: * Copyright (c) 1984, 1985 Xerox Corp.
14: *
15: * HISTORY
16: * 01-Dec-85 lee at Xerox, WRC
17: * Linted.
18: *
19: * 28-apr-85 ed flint
20: * add conditional compilation for vax11-c (vms)
21: *
22: *
23: * if using this file on vms, you must edit this file and add the following
24: * lines around the #include "stdio.h" line which is at the top of the file
25: *
26: * #ifdef vax11c
27: * # include stdio
28: * #else
29: * # include "stdio.h"
30: * #endif
31: */
32:
33:
34: #ifdef vax11c
35: # include ctype
36: #else
37: # include <ctype.h>
38: #endif
39:
40: # include "iptokens.h"
41: # include "texttoken.h"
42: # include "ipnames.h"
43:
44: # define short_or_long(ch) (ch != '>' ? 1 : 2)
45:
46: extern int yylval_long;
47: extern char *yylval_charP;
48: char *buffptr;
49: char string_buffer[1024];
50: %}
51:
52: %%
53:
54: ^"File: " {
55: return(T_file);
56: }
57:
58: ^"Header: " {
59: return(T_header);
60: }
61:
62: ^>[> ]"Comment: " {
63: yylval_long = short_or_long(yytext[1]);
64: return(T_seq_comment);
65: }
66:
67: ^>[> ]"Identifier: " {
68: yylval_long = short_or_long(yytext[1]);
69: return(T_seq_identifier);
70: }
71:
72: ^>[> ]"Insert file: " {
73: yylval_long = short_or_long(yytext[1]);
74: return(T_seq_insert_file);
75: }
76:
77: ^>[> ]"Integer: " {
78: yylval_long = short_or_long(yytext[1]);
79: return(T_seq_integer);
80: }
81:
82: ^>[> ]"Rational: " {
83: yylval_long = short_or_long(yytext[1]);
84: return(T_seq_rational);
85: }
86:
87: ^>[> ]"String: " {
88: yylval_long = short_or_long(yytext[1]);
89: return(T_seq_string);
90: }
91:
92: ^>[> ]"Adaptive Pixel Vector: " {
93: yylval_long = short_or_long(yytext[1]);
94: return(T_seq_apv);
95: }
96:
97: ^>[> ]"Compressed Pixel Vector: " {
98: yylval_long = short_or_long(yytext[1]);
99: return(T_seq_cpv);
100: }
101:
102: ^>[> ]"Packed Pixel Vector: " {
103: yylval_long = short_or_long(yytext[1]);
104: return(T_seq_ppv);
105: }
106:
107: [+-]?[0-9A-Fa-f][0-9A-Fa-f]* {
108: yylval_long = getnum(yytext);
109: return(T_number);
110: }
111:
112: ^[a-zA-Z{}][a-zA-Z]* {
113: register char *ptr;
114:
115: for (ptr = yytext; *ptr; ptr++)
116: {
117: if (isupper(*ptr))
118: {
119: *ptr = tolower(*ptr);
120: }
121: }
122: for (yylval_long = 0; yylval_long <= OP_LIMIT;
123: yylval_long++)
124: {
125: if (strcmp(yytext, op_names[yylval_long]) == 0)
126: {
127: return(T_operator);
128: }
129: }
130: return(T_operator);
131: }
132:
133: \" {
134: unsigned char ch;
135: int val = 0;
136: int cnt = 0;
137:
138: yylval_charP = buffptr = string_buffer;
139:
140: while ((ch = input()) != '"')
141: {
142: if (ch == '\\')
143: {
144: ch = input();
145: if (ch >= '0' && ch <= '9')
146: {
147: do
148: {
149: val <<= 3;
150: val += (ch - '0');
151: ch = input();
152: } while (ch >= '0' && ch <= '9' &&
153: cnt++ < 3);
154: unput(ch);
155: ch = val;
156: }
157: }
158: *buffptr++ = ch;
159: }
160: *buffptr = '\0';
161: return(T_string);
162: }
163:
164: [a-zA-Z][a-zA-Z0-9\-]* {
165: yylval_charP = yytext;
166: return(T_identifier);
167: }
168:
169: [ \t][ \t]* {
170: yyleng = 0; /* gobble white space */
171: yymore();
172: }
173:
174: \(.*\) {
175: yyleng = 0; /* gobble comments */
176: yymore();
177: }
178:
179: ^\(.*\)\n {
180: /* comment that spans the whole line */
181: yyleng = 0;
182: yymore();
183: }
184:
185: \n {
186: return(T_newline);
187: }
188:
189: . {
190: yylval_long = yytext[yyleng-1];
191: return(T_character);
192: }
193:
194: %%
195:
196: extern int radix;
197:
198: getnum(str)
199:
200: char *str;
201:
202: {
203: register int val;
204: register int digit;
205:
206: /* take the easy and fast way out for base 10 */
207: if (radix == 10)
208: {
209: return(atoi(str));
210: }
211:
212: /* otherwise this is a standard "convert any radix" algorithm */
213: val = 0;
214: while ((digit = *str++) != '\0')
215: {
216: if ((digit -= '0') > 9)
217: {
218: /* it is a letter */
219: if ((digit -= ('A' - '0' - 10)) > 15)
220: {
221: /* it is a lower case digit */
222: digit -= ('a' - 'A');
223: }
224: }
225: if (digit >= radix)
226: {
227: /* this is really too much! give up at this point */
228: return(val);
229: }
230: val *= radix;
231: val += digit;
232: }
233: return(val);
234: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.