author | wenzelm |
Mon, 29 Nov 1999 15:52:49 +0100 | |
changeset 8039 | a901bafe4578 |
parent 5675 | 000879172ee4 |
permissions | -rw-r--r-- |
1826 | 1 |
/* Title: Tools/8bit/c-sources/isa2latex/conv-main.c |
2 |
ID: $Id$ |
|
3 |
Author: Franz Regensburger |
|
4 |
Copyright 1996 TU Muenchen |
|
5 |
||
6 |
converter for isabelle files |
|
7 |
definitions for the lexical analyzer |
|
8 |
*/ |
|
9 |
||
10 |
%{ |
|
11 |
#include "conv-defs.h" |
|
12 |
#define output(c) fputc(c, yyout) |
|
13 |
#define BEGIN_ISA { if (accept_ASCII) \ |
|
14 |
BEGIN ISAA; /* we have -A option */ \ |
|
15 |
else \ |
|
16 |
BEGIN ISA;} |
|
17 |
||
18 |
extern FILE *finput, *foutput; |
|
19 |
extern int tabBlanks; |
|
20 |
extern int tabcount; |
|
4170 | 21 |
extern char isa_env_beg0[], isa_env_beg1[], isa_env_end[]; |
1826 | 22 |
extern int convMode; |
23 |
extern int accept_ASCII; |
|
24 |
extern int destCode; |
|
25 |
extern int cc; |
|
26 |
||
27 |
void reset_tabs(void); |
|
28 |
void put(char c, int longDetect, int longCode); |
|
29 |
||
30 |
int lineno=1; |
|
31 |
int inline_mode=FALSE; |
|
32 |
%} |
|
33 |
%S LATEX ISA ISAA ESC |
|
34 |
%option noyywrap |
|
35 |
||
36 |
%% |
|
37 |
void warning(char *what); |
|
38 |
void not_suitable(char *what, char *where); |
|
39 |
yyin = finput; |
|
40 |
yyout = foutput; |
|
41 |
||
42 |
if (convMode == MIXED) |
|
43 |
BEGIN LATEX; /* we have -x option */ |
|
44 |
else |
|
45 |
BEGIN_ISA; |
|
46 |
||
4170 | 47 |
<LATEX>\\I@@? { BEGIN_ISA; inline_mode=TRUE ; fprintf(foutput, |
48 |
(yytext[3]=='@' ? "\\mbox{\\isainline[\\isamodify]{" |
|
49 |
: "\\mbox{\\isainline{")); } |
|
50 |
<LATEX>\\I@isa@?[ \t]*\n? { BEGIN_ISA; inline_mode=FALSE; fprintf(foutput, |
|
51 |
(yytext[6]=='@' ? isa_env_beg1 |
|
52 |
: isa_env_beg0)); reset_tabs(); |
|
53 |
if (yytext[strlen(yytext)-1] == '\n') |
|
54 |
{ fprintf(foutput, "\n"); lineno++; } |
|
1826 | 55 |
} |
56 |
<LATEX>\\E@ { ECHO; not_suitable("\\E@","LATEX"); } |
|
57 |
<LATEX>\n { put(*yytext,FALSE,0); lineno++; } |
|
58 |
||
59 |
<ISA,ISAA>\\I@ { if (inline_mode) |
|
60 |
{ BEGIN LATEX; inline_mode=FALSE; |
|
61 |
fprintf(foutput, "}}"); } |
|
62 |
else |
|
63 |
{ ECHO; not_suitable("\\I@","ISA"); } |
|
64 |
} |
|
4170 | 65 |
<ISA,ISAA>\n?[ \t]*\\I@isa {if (yytext[0] == '\n') |
66 |
{ fprintf(foutput, "\n"); lineno++; }; |
|
67 |
if (inline_mode) |
|
1826 | 68 |
{ ECHO; not_suitable("\\I@isa","INLINE"); } |
69 |
else |
|
70 |
{ if (convMode == MIXED) { |
|
71 |
BEGIN LATEX; fprintf(foutput, isa_env_end); } |
|
72 |
else { |
|
73 |
ECHO; warning( |
|
74 |
"\\I@isa only allowed with -x option"); } |
|
75 |
} |
|
76 |
} |
|
77 |
<ISA,ISAA>\\E@ { BEGIN ESC; fprintf(foutput, "{\\isaescape{"); } |
|
78 |
<ISA,ISAA><<EOF>> { if (convMode == MIXED) |
|
79 |
not_suitable("EOF", inline_mode? "INLINE": "ISA"); |
|
80 |
yyterminate(); |
|
81 |
} |
|
82 |
<ISA,ISAA>\n { if (inline_mode) |
|
83 |
{ ECHO; not_suitable("\\n","INLINE"); } |
|
84 |
else |
|
85 |
{ put(*yytext,FALSE,0); } |
|
86 |
lineno++; |
|
87 |
} |
|
88 |
<ISA,ISAA>\t { if (inline_mode) |
|
89 |
{ ECHO; not_suitable("\\t","INLINE"); } |
|
90 |
else |
|
91 |
{ put(*yytext,FALSE,0); } |
|
92 |
} |
|
93 |
||
94 |
<ESC>\\I@ { ECHO; not_suitable("\\I@" ,"ESC"); } |
|
95 |
<ESC>\\I@isa { ECHO; not_suitable("\\I@isa","ESC"); } |
|
96 |
<ESC>\\E@ { BEGIN_ISA; fprintf(foutput, "}}"); } |
|
97 |
<ESC><<EOF>> { not_suitable("EOF" ,"ESC"); yyterminate(); } |
|
98 |
<ESC>\n { put(*yytext,FALSE,0); lineno++; } |
|
99 |
||
100 |
/* The following is generated by the perl script gen-isa2latex. */ |
|
101 |
/* Make modifications in configuration file for gen-isa2latex! */ |
|
102 |
/* BEGIN_OF_HI_TABLE */ |
|
4170 | 103 |
<ISAA>\ \ put((char)160,FALSE,0); |
104 |
<ISAA>\\Gamma put((char)161,FALSE,0); |
|
105 |
<ISAA>\\Delta put((char)162,FALSE,0); |
|
106 |
<ISAA>\\Theta put((char)163,FALSE,0); |
|
107 |
<ISAA>LAM\ put((char)164,FALSE,0); |
|
108 |
<ISAA>\\Pi put((char)165,FALSE,0); |
|
109 |
<ISAA>\\Sigma put((char)166,FALSE,0); |
|
110 |
<ISAA>\\Phi put((char)167,FALSE,0); |
|
111 |
<ISAA>\\Psi put((char)168,FALSE,0); |
|
112 |
<ISAA>\\Omega put((char)169,FALSE,0); |
|
113 |
<ISAA>'a put((char)170,FALSE,0); |
|
114 |
<ISAA>'b put((char)171,FALSE,0); |
|
115 |
<ISAA>'c put((char)172,FALSE,0); |
|
116 |
<ISAA>\\delta put((char)173,FALSE,0); |
|
117 |
<ISAA>\\varepsilon put((char)174,FALSE,0); |
|
118 |
<ISAA>\\zeta put((char)175,FALSE,0); |
|
119 |
<ISAA>\\eta put((char)176,FALSE,0); |
|
120 |
<ISAA>\\vartheta put((char)177,FALSE,0); |
|
121 |
<ISAA>\\kappa put((char)178,FALSE,0); |
|
122 |
<ISAA>%\ put((char)179,FALSE,0); |
|
123 |
<ISAA>\\mu put((char)180,FALSE,0); |
|
124 |
<ISAA>\\nu put((char)181,FALSE,0); |
|
125 |
<ISAA>\\xi put((char)182,FALSE,0); |
|
126 |
<ISAA>\\pi put((char)183,FALSE,0); |
|
127 |
<ISAA>'r put((char)184,FALSE,0); |
|
128 |
<ISAA>'s put((char)185,FALSE,0); |
|
129 |
<ISAA>'t put((char)186,FALSE,0); |
|
130 |
<ISAA>\\varphi put((char)187,FALSE,0); |
|
131 |
<ISAA>\\chi put((char)188,FALSE,0); |
|
132 |
<ISAA>\\psi put((char)189,FALSE,0); |
|
133 |
<ISAA>\\omega put((char)190,FALSE,0); |
|
134 |
<ISAA>~\ put((char)191,FALSE,0); |
|
135 |
<ISAA>&\ put((char)192,FALSE,0); |
|
136 |
<ISAA>\|\ put((char)193,FALSE,0); |
|
137 |
<ISAA>!\ put((char)194,FALSE,0); |
|
138 |
<ISAA>\?\ put((char)195,FALSE,0); |
|
139 |
<ISAA>!! put((char)196,FALSE,0); |
|
140 |
<ISAA>\\lceil put((char)197,FALSE,0); |
|
141 |
<ISAA>\\rceil put((char)198,FALSE,0); |
|
142 |
<ISAA>\\lfloor put((char)199,FALSE,0); |
|
143 |
<ISAA>\\rfloor put((char)200,FALSE,0); |
|
144 |
<ISAA>\|- put((char)201,FALSE,0); |
|
145 |
<ISAA>\|= put((char)202,FALSE,0); |
|
146 |
<ISAA>\[\| put((char)203,FALSE,0); |
|
147 |
<ISAA>\|\] put((char)204,FALSE,0); |
|
148 |
<ISAA>\\cdot put((char)205,FALSE,0); |
|
149 |
<ISAA>\ :\ put((char)206,FALSE,0); |
|
150 |
<ISAA>\ \subseteq\ put((char)207,FALSE,0); |
|
151 |
<ISAA>\ Int\ put((char)208,FALSE,0); |
|
152 |
<ISAA>\ Un\ put((char)209,FALSE,0); |
|
153 |
<ISAA>Inter\ put((char)210,FALSE,0); |
|
154 |
<ISAA>Union\ put((char)211,FALSE,0); |
|
155 |
<ISAA>\\sqcap put((char)212,FALSE,0); |
|
156 |
<ISAA>\\sqcup put((char)213,FALSE,0); |
|
157 |
<ISAA>glb\ put((char)214,FALSE,0); |
|
158 |
<ISAA>LUB\ put((char)215,FALSE,0); |
|
159 |
<ISAA>UU put((char)216,FALSE,0); |
|
160 |
<ISAA>=== put((char)217,FALSE,0); |
|
161 |
<ISAA>== put((char)218,FALSE,0); |
|
162 |
<ISAA>~= put((char)219,FALSE,0); |
|
163 |
<ISAA>\\sqsubset put((char)220,FALSE,0); |
|
164 |
<ISAA><< put((char)221,FALSE,0); |
|
165 |
<ISAA><: put((char)222,FALSE,0); |
|
166 |
<ISAA><=: put((char)223,FALSE,0); |
|
167 |
<ISAA>:> put((char)224,FALSE,0); |
|
168 |
<ISAA>~~ put((char)225,FALSE,0); |
|
169 |
<ISAA>\\sim\ put((char)226,FALSE,0); |
|
170 |
<ISAA>\\simeq put((char)227,FALSE,0); |
|
171 |
<ISAA><= put((char)228,FALSE,0); |
|
172 |
<ISAA>:: put((char)229,FALSE,0); |
|
173 |
<ISAA><- put((char)230,FALSE,0); |
|
174 |
<ISAA>-@@@@@ put((char)231,FALSE,0); |
|
175 |
<ISAA>-> put((char)232,FALSE,0); |
|
176 |
<ISAA>\\Leftarrow put((char)233,FALSE,0); |
|
177 |
<ISAA>=@@@@@ put((char)234,FALSE,0); |
|
178 |
<ISAA>=> put((char)235,FALSE,0); |
|
179 |
<ISAA>\\frown put((char)236,FALSE,0); |
|
180 |
<ISAA>\\mapsto put((char)237,FALSE,0); |
|
181 |
<ISAA>\\leadsto put((char)238,FALSE,0); |
|
182 |
<ISAA>\\uparrow put((char)239,FALSE,0); |
|
183 |
<ISAA>\\downarrow put((char)240,FALSE,0); |
|
184 |
<ISAA>~: put((char)241,FALSE,0); |
|
185 |
<ISAA>\\times put((char)242,FALSE,0); |
|
5436 | 186 |
<ISAA>\+\+ put((char)243,FALSE,0); |
4170 | 187 |
<ISAA>\\ominus put((char)244,FALSE,0); |
5436 | 188 |
<ISAA>\*\* put((char)245,FALSE,0); |
4170 | 189 |
<ISAA>\\oslash put((char)246,FALSE,0); |
190 |
<ISAA>\\subset put((char)247,FALSE,0); |
|
191 |
<ISAA>\\infty put((char)248,FALSE,0); |
|
192 |
<ISAA>\\Box put((char)249,FALSE,0); |
|
193 |
<ISAA>\\Diamond put((char)250,FALSE,0); |
|
194 |
<ISAA>\\circ put((char)251,FALSE,0); |
|
195 |
<ISAA>\\bullet put((char)252,FALSE,0); |
|
196 |
<ISAA>\|\| put((char)253,FALSE,0); |
|
197 |
<ISAA>\\tick put((char)254,FALSE,0); |
|
198 |
<ISAA>\\filter put((char)255,FALSE,0); |
|
1826 | 199 |
/* END_OF_HI_TABLE */ |
200 |
/* This is the end of the generated part */ |
|
201 |
||
202 |
/* The following is generated by the perl script gen-isa2latex. */ |
|
203 |
/* Make modifications in configuration file for gen-isa2latex! */ |
|
204 |
/* BEGIN_OF_SEQ_TABLE */ |
|
4773
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
205 |
<ISA,ISAA>êë put((char)32,TRUE,0); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
206 |
<ISAA>==> put((char)32,TRUE,0); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
207 |
<ISA,ISAA>çè put((char)32,TRUE,1); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
208 |
<ISAA>--> put((char)32,TRUE,1); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
209 |
<ISA,ISAA>Ã! put((char)32,TRUE,2); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
210 |
<ISAA>\?! put((char)32,TRUE,2); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
211 |
<ISA,ISAA>ALL@@@@@ put((char)32,TRUE,3); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
212 |
<ISAA>ALL\ put((char)32,TRUE,3); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
213 |
<ISA,ISAA>EX@@@@@ put((char)32,TRUE,4); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
214 |
<ISAA>EX\ put((char)32,TRUE,4); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
215 |
<ISA,ISAA><<\| put((char)32,TRUE,5); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
216 |
<ISAA>@<<\| put((char)32,TRUE,5); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
217 |
<ISA,ISAA><\| put((char)32,TRUE,6); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
218 |
<ISAA>@<\| put((char)32,TRUE,6); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
219 |
<ISA,ISAA>éê put((char)32,TRUE,7); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
220 |
<ISAA><== put((char)32,TRUE,7); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
221 |
<ISA,ISAA>éë put((char)32,TRUE,8); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
222 |
<ISAA><=> put((char)32,TRUE,8); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
223 |
<ISA,ISAA>æç put((char)32,TRUE,9); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
224 |
<ISAA><-- put((char)32,TRUE,9); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
225 |
<ISA,ISAA>æè put((char)32,TRUE,10); |
b6729feb8a5d
improved \tt appearance of many ASCII special symbols like #
oheimb
parents:
4170
diff
changeset
|
226 |
<ISAA><-> put((char)32,TRUE,10); |
5675 | 227 |
<ISA,ISAA>^and put((char)32,TRUE,11); |
228 |
<ISAA>^@and put((char)32,TRUE,11); |
|
229 |
<ISA,ISAA>^arities put((char)32,TRUE,12); |
|
230 |
<ISAA>^@arities put((char)32,TRUE,12); |
|
231 |
<ISA,ISAA>^axclass put((char)32,TRUE,13); |
|
232 |
<ISAA>^@axclass put((char)32,TRUE,13); |
|
233 |
<ISA,ISAA>^constdefs put((char)32,TRUE,14); |
|
234 |
<ISAA>^@constdefs put((char)32,TRUE,14); |
|
235 |
<ISA,ISAA>^consts put((char)32,TRUE,15); |
|
236 |
<ISAA>^@consts put((char)32,TRUE,15); |
|
237 |
<ISA,ISAA>^datatype put((char)32,TRUE,16); |
|
238 |
<ISAA>^@datatype put((char)32,TRUE,16); |
|
239 |
<ISA,ISAA>^defs put((char)32,TRUE,17); |
|
240 |
<ISAA>^@defs put((char)32,TRUE,17); |
|
241 |
<ISA,ISAA>^domain put((char)32,TRUE,18); |
|
242 |
<ISAA>^@domain put((char)32,TRUE,18); |
|
243 |
<ISA,ISAA>^end put((char)32,TRUE,19); |
|
244 |
<ISAA>^@end put((char)32,TRUE,19); |
|
245 |
<ISA,ISAA>^inductive put((char)32,TRUE,20); |
|
246 |
<ISAA>^@inductive put((char)32,TRUE,20); |
|
247 |
<ISA,ISAA>^instance put((char)32,TRUE,21); |
|
248 |
<ISAA>^@instance put((char)32,TRUE,21); |
|
249 |
<ISA,ISAA>^primrec put((char)32,TRUE,22); |
|
250 |
<ISAA>^@primrec put((char)32,TRUE,22); |
|
251 |
<ISA,ISAA>^recdef put((char)32,TRUE,23); |
|
252 |
<ISAA>^@recdef put((char)32,TRUE,23); |
|
253 |
<ISA,ISAA>^rules put((char)32,TRUE,24); |
|
254 |
<ISAA>^@rules put((char)32,TRUE,24); |
|
255 |
<ISA,ISAA>^syntax put((char)32,TRUE,25); |
|
256 |
<ISAA>^@syntax put((char)32,TRUE,25); |
|
257 |
<ISA,ISAA>^translations put((char)32,TRUE,26); |
|
258 |
<ISAA>^@translations put((char)32,TRUE,26); |
|
259 |
<ISA,ISAA>^typedef put((char)32,TRUE,27); |
|
260 |
<ISAA>^@typedef put((char)32,TRUE,27); |
|
261 |
<ISA,ISAA>^types put((char)32,TRUE,28); |
|
262 |
<ISAA>^@types put((char)32,TRUE,28); |
|
1826 | 263 |
/* END_OF_SEQ_TABLE */ |
264 |
/* This is the end of the generated part */ |
|
265 |
||
266 |
. { put(*yytext,FALSE,0);} |
|
267 |
||
268 |
%% |
|
269 |
||
270 |
void warning(char *str) |
|
271 |
{ |
|
272 |
fprintf(stderr,"WARNING: line %d: %s\n", lineno, str); |
|
273 |
} |
|
274 |
||
275 |
void not_suitable(char *what, char *where) |
|
276 |
{ |
|
277 |
char buf[80]; |
|
278 |
sprintf(buf, "'%s' inside %s mode", what, where); |
|
279 |
warning(buf); |
|
280 |
} |
|
281 |
||
282 |
void reset_tabs(void) |
|
283 |
{ |
|
284 |
cc = 0; |
|
285 |
tabcount = 1; |
|
286 |
} |
|
287 |
||
288 |
void put(char c, int longDetect,int longCode) |
|
289 |
{ |
|
290 |
int i; |
|
4170 | 291 |
char s[100]; |
292 |
extern char *translateHi(int ch, int code); |
|
1826 | 293 |
|
294 |
if (YY_START == LATEX || YY_START == ESC) |
|
295 |
/* do not translate in these modes */ |
|
296 |
fputc(c,foutput); |
|
297 |
||
298 |
else /* we are in ISA mode */ |
|
299 |
if (longDetect) { /* lexer has scanned a long sequence */ |
|
300 |
fprintf(foutput, "%s", translateLong(longCode, destCode)); |
|
301 |
if (destCode == TO_LaTeX && ++cc % tabBlanks == 0) |
|
302 |
tabcount++; |
|
303 |
} |
|
304 |
else /* lexer has not scanned a long sequence */ |
|
305 |
if (c & 0x80) { /* Hi-bit is set... */ |
|
4170 | 306 |
strcpy(s, translateHi(c, destCode)); |
307 |
i = strlen(s); |
|
308 |
if((unsigned char)c != 0xa0 && |
|
309 |
i >= 2 && s[i-2] == '\\' && s[i-1] == ' ' && (yytext[0] & 0x80)) |
|
310 |
s[i-2] ='\0'; |
|
311 |
fprintf(foutput, "%s", s); |
|
1826 | 312 |
if (destCode == TO_LaTeX && ++cc % tabBlanks == 0) |
313 |
tabcount++; |
|
314 |
} |
|
315 |
else /* simple char without Hi-Bit*/ |
|
316 |
if (destCode == TO_7bit) |
|
317 |
fputc(c, foutput); |
|
318 |
else |
|
319 |
switch (c) { /* handle control codes */ |
|
320 |
case '\n': if (inline_mode) |
|
321 |
c=' '; |
|
322 |
else { |
|
323 |
fprintf(foutput, "\\\\\n"); |
|
324 |
reset_tabs(); |
|
325 |
break; |
|
326 |
} |
|
327 |
case TAB: if (inline_mode) |
|
328 |
c=' '; |
|
329 |
else { |
|
330 |
for (i = 0; i < tabcount; i++) |
|
331 |
fprintf(foutput, "\\>"); |
|
332 |
reset_tabs(); |
|
333 |
break; |
|
334 |
} |
|
335 |
default: |
|
336 |
if (++cc % tabBlanks == 0) |
|
337 |
tabcount++; |
|
338 |
if ((c >= START_LOW_TABLE) && (c <= END_LOW_TABLE)) |
|
339 |
{ |
|
340 |
fprintf(foutput, "%s", translateLow(c));} |
|
341 |
else /* just reproduce the other control codes */ |
|
342 |
fputc(c, foutput); |
|
343 |
} /* switch */ |
|
344 |
} |
|
345 |
||
346 |
||
347 |
||
348 |
||
349 |
||
350 |