1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
|
/*
* Eukleides version 0.9.2
* Copyright (c) Christian Obrecht 2000-2002
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
%x FILTER
%{
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "parser.tab.h"
#define FILTER_MODE 0
#define NORMAL_MODE 1
#define TRACE_MODE 2
#define STRING_MODE 3
#define COMMENT_MODE 4
#undef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 65536
int warning(char *);
extern int filter, undefined, lineno, drawing_style, first, inputmode;
int count, pos;
extern char * buffer;
symrec *sym_table = NULL;
/* Symbol table management */
symrec *putsym (char *sym_name)
{
symrec *ptr;
ptr = (symrec *)malloc (sizeof (symrec));
ptr->name = (char *) malloc (strlen (sym_name) + 1);
strcpy (ptr->name, sym_name);
ptr->type = VARIABLE;
ptr->next = sym_table;
sym_table = ptr;
return ptr;
}
symrec *getsym (char *sym_name)
{
symrec *ptr;
for (ptr = sym_table; ptr != NULL; ptr = ptr->next)
if (strcmp (ptr->name, sym_name) == 0)
return ptr;
return NULL;
}
void clearsym(void)
{
symrec *ptr, *prev;
ptr = sym_table;
while (ptr != NULL) {
free(ptr->name);
prev = ptr;
ptr = ptr->next;
free(prev);
}
sym_table = NULL;
}
saverec *save_table = NULL;
void save(void * s)
{
saverec *ptr;
ptr = (saverec *)malloc(sizeof(saverec));
ptr->s = s;
ptr->next = save_table;
save_table = ptr;
}
void clearsave(void)
{
saverec *ptr, *prev;
ptr = save_table;
while (ptr != NULL) {
free(ptr->s);
prev = ptr;
ptr = ptr->next;
free(prev);
}
save_table = NULL;
}
#undef YY_INPUT
#define YY_INPUT(buf,result,max) (result = char_input(buf,max))
/* Input function */
int char_input(char *buf, int max)
{
int n;
static int cursor = 0, bracepos, loopcount, lastmode;
n = 0;
while (buffer[cursor] != '\0' && n < max) {
buf[n] = buffer[cursor];
switch (buffer[cursor]) {
case '%':
if (inputmode == FILTER_MODE
&& strncmp("%--eukleides",buffer+cursor,12) == 0)
inputmode = COMMENT_MODE;
if (inputmode == NORMAL_MODE) {
inputmode = COMMENT_MODE;
if (strncmp("%--end",buffer+cursor,6) == 0
|| strncmp("%--stop",buffer+cursor,7) == 0)
inputmode = FILTER_MODE;
};
break;
case '\n':
if (inputmode == STRING_MODE || inputmode == COMMENT_MODE)
inputmode = NORMAL_MODE;
break;
case '"':
if (inputmode == NORMAL_MODE || inputmode == TRACE_MODE) {
lastmode = inputmode;
inputmode = STRING_MODE;
}
else if (inputmode == STRING_MODE) inputmode = lastmode;
break;
case '{':
if (inputmode == NORMAL_MODE) {
bracepos = cursor-1;
buffer[cursor] = ';';
loopcount = 100;
inputmode = TRACE_MODE;
}
break;
case '}':
if (inputmode == TRACE_MODE) {
if (--loopcount)
cursor = bracepos;
else
inputmode = NORMAL_MODE;
}
};
cursor++; n++;
}
return n;
}
int yywrap(void)
{
return 1;
}
%}
%%
%{
if (filter) BEGIN FILTER;
else BEGIN INITIAL;
%}
/* Ignore whitespace */
[\t ]+
/* Stop compiling */
"%--stop"[\t ]*\n {
lineno++;
filter = 1;
undefined = 1;
printf("\\endpspicture\n");
printf("%% End of figure\n");
BEGIN FILTER;
}
"%--end"[\t ]*\n {
lineno++;
filter = 1;
clearsave(); /* Clear memory */
clearsym();
sym_table = NULL;
undefined = 1;
drawing_style = FULL;
printf("\\endpspicture\n");
printf("%% End of figure\n");
BEGIN FILTER;
}
/* Comments */
%.*\n { lineno++; }
%.* { return '\n'; }
/* Numbers */
(([0-9]+)|([0-9]*\.[0-9]+)) {
yylval.number = atof(yytext);
return NUMBER;
}
/* Strings */
\"[^\"\n]*[\"\n] {
yylval.string = strdup(yytext+1);
if (yylval.string[yyleng-2] != '"') {
warning("Unterminated character string");
lineno++;
}
else yylval.string[yyleng-2] = '\0';
return STRING;
}
/* Reserved words */
point { return POINT; }
vector { return VECTOR; }
line { return LINE; }
segment { return SEGMENT; }
circle { return CIRCLE; }
conic { return CONIC; }
parabola { return PARABOLA; }
ellipse { return ELLIPSE; }
hyperbola { return HYPERBOLA; }
translation { return TRANSLATION; }
reflection { return REFLECTION; }
rotation { return ROTATION; }
projection { return PROJECTION; }
homothecy { return HOMOTHECY; }
intersection { return INTERSECTION; }
parallel { return PARALLEL; }
perpendicular { return PERPENDICULAR; }
midpoint { return MIDPOINT; }
begin { return TOKBEGIN; }
end { return END; }
center { return CENTER; }
vertices { return VERTICES; }
foci { return FOCI; }
triangle { return TRIANGLE; }
equilateral { return EQUILATERAL; }
isosceles { return ISOSCELES; }
right { return RIGHT; }
barycenter { return BARYCENTER; }
median { return MEDIAN; }
altitude { return ALTITUDE; }
orthocenter { return ORTHOCENTER; }
bisector { return BISECTOR; }
incircle { return INCIRCLE; }
parallelogram { return PARALLELOGRAM; }
rectangle { return RECTANGLE; }
square { return SQUARE; }
pentagon { return PENTAGON; }
hexagon { return HEXAGON; }
abscissa { return ABSCISSA; }
ordinate { return ORDINATE; }
length { return LENGTH; }
distance { return DISTANCE; }
angle { return ANGLE; }
arg { return ARGUMENT; }
radius { return RADIUS; }
major { return MAJOR; }
minor { return MINOR; }
eccentricity { return ECCENTRICITY; }
height { return HEIGHT; }
exp { return EXP; }
ln { return LN; }
pi { return TOKPI; }
sin { return SIN; }
cos { return COS; }
tan { return TAN; }
asin { return ASIN; }
acos { return ACOS; }
atan { return ATAN; }
deg { return TOKDEG; }
rad { return TOKRAD; }
abs { return TOKABS; }
sqrt { return SQRT; }
frame { return FRAME; }
color { return COLOR; }
black { return BLACK; }
darkgray { return DARKGRAY; }
gray { return GRAY; }
lightgray { return LIGHTGRAY; }
white { return WHITE; }
red { return RED; }
green { return GREEN; }
blue { return BLUE; }
cyan { return CYAN; }
magenta { return MAGENTA; }
yellow { return YELLOW; }
thickness { return THICKNESS; }
font { return FONT; }
tricks { return TRICKS; }
export { return EXPORT; }
draw { return DRAW; }
mark { return MARK; }
dot { return DOT; }
box { return BOX; }
cross { return CROSS; }
plus { return PLUS; }
noarrow { return NOARROW; }
arrow { return ARROW; }
backarrow { return BACKARROW; }
doublearrow { return DOUBLEARROW; }
entire { return ENTIRE;}
halfline { return HALFLINE; }
backhalfline { return BACKHALFLINE; }
style { return STYLE; }
full { return FULL; }
dotted { return DOTTED; }
dashed { return DASHED; }
simple { return SIMPLE; }
double { return DOUBLE; }
triple { return TRIPLE; }
interactive { return INTERACTIVE; }
up { return UP; }
trace { return TRACE; }
/* Variables */
[a-zA-Z][a-zA-Z0-9]* {
symrec *s;
s = getsym (yytext);
if (s == NULL)
s = putsym (yytext);
yylval.ptr = s;
switch (s->type)
{
case NUMBER : return NUMBER_VARIABLE;
case POINT : return POINT_VARIABLE;
case VECTOR : return VECTOR_VARIABLE;
case LINE : return LINE_VARIABLE;
case SEGMENT : return SEGMENT_VARIABLE;
case CIRCLE : return CIRCLE_VARIABLE;
case CONIC : return CONIC_VARIABLE;
case VARIABLE : return VARIABLE;
}
}
/* Semi-colons and \r are handled as \n */
(;)|(\r) { return '\n'; }
/* New line */
\n { lineno++; return '\n'; }
/* Trace command block */
"{" {
if (first) {
count = 100;
pos = lineno;
first = 0;
return '\n';
} else return '{';
}
"}" {
if (count == 100)
lineno -= 99*(lineno-pos);
if (--count == 0)
first = 1;
return '}';
}
/* Anything else */
. { return yytext[0]; }
/* Start compiling */
<FILTER>"%--eukleides"[\t ]*\n {
lineno++; filter = 0;
printf("%% Generated by eukleides 0.9.2\n");
printf("\\psset{linecolor=black, linewidth=.5pt, arrowsize=2pt 4}\n");
BEGIN INITIAL;
}
/* New line */
<FILTER>\n { lineno++; ECHO; }
/* Anything else */
<FILTER>. { ECHO; }
%%
|