Wild Life: token.c File Reference

Wild Life 2.29

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros
Macros | Functions | Variables
token.c File Reference

Go to the source code of this file.

## Macros
#define | isoctal(c) (c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7')

## Functions
void | TOKEN_ERROR (ptr_psi_term p)
void | stdin_cleareof ()
void | heap_add_int_attr (ptr_psi_term t, char *attrname, long value)
void | stack_add_int_attr (ptr_psi_term t, char *attrname, long value)
void | heap_mod_int_attr (ptr_psi_term t, char *attrname, long value)
void | heap_add_str_attr (ptr_psi_term t, char *attrname, char *str)
void | stack_add_str_attr (ptr_psi_term t, char *attrname, char *str)
void | heap_mod_str_attr (ptr_psi_term t, char *attrname, char *str)
void | heap_add_psi_attr (ptr_psi_term t, char *attrname, ptr_psi_term g)
void | stack_add_psi_attr (ptr_psi_term t, char *attrname, ptr_psi_term g)
void | bk_stack_add_psi_attr (ptr_psi_term t, char *attrname, ptr_psi_term g)
GENERIC | get_attr (ptr_psi_term t, char *attrname)
FILE * | get_stream (ptr_psi_term t)
void | save_state (ptr_psi_term t)
void | restore_state (ptr_psi_term t)
void | new_state (ptr_psi_term *t)
void | save_parse_state (ptr_parse_block pb)
void | restore_parse_state (ptr_parse_block pb)
void | init_parse_state ()
void | begin_terminal_io ()
void | end_terminal_io ()
char * | expand_file_name (char *s)
long | open_input_file (char *file)
long | open_output_file (string file)
long | read_char ()
void | put_back_char (long c)
void | put_back_token (psi_term t)
void | psi_term_error ()
void | read_comment (ptr_psi_term tok)
void | read_string_error (int n)
int | base2int (int n)
void | read_string (ptr_psi_term tok, long e)
long | symbolic (long c)
long | legal_in_name (long c)
void | read_name (ptr_psi_term tok, long ch, long(*f)(long), ptr_definition typ)
void | read_number (ptr_psi_term tok, long c)
void | read_token_main (ptr_psi_term, long)
void | read_token (ptr_psi_term tok)
void | read_token_b (ptr_psi_term tok)

## Variables
long | trace_input =FALSE
static long | inchange
static long | outchange
static FILE * | out
ptr_psi_term | old_state =NULL

## Macro Definition Documentation

#define isoctal | ( |  | c | ) | (c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7')

Definition at line 737 of file token.c.

## Function Documentation

int base2int | ( | int | n | ) |

Definition at line 705 of file token.c.

707 {
708 switch (n) {
709 case '0': return 0;
710 case '1': return 1;
711 case '2': return 2;
712 case '3': return 3;
713 case '4': return 4;
714 case '5': return 5;
715 case '6': return 6;
716 case '7': return 7;
717 case '8': return 8;
718 case '9': return 9;
719 case 'a':
720 case 'A': return 10;
721 case 'b':
722 case 'B': return 11;
723 case 'c':
724 case 'C': return 12;
725 case 'd':
726 case 'D': return 13;
727 case 'e':
728 case 'E': return 14;
729 case 'f':
730 case 'F': return 15;
731 default:
732 fprintf(stderr,"base2int('%c'): illegal argument\n",n);
733 exit(EXIT_FAILURE);
734 }
735 }

void begin_terminal_io | ( |  | ) |

Definition at line 410 of file token.c.

References inchange, input_state, input_stream, open_input_file(), out, outchange, and output_stream.

411 {
412 inchange = (input_stream!=stdin);
413 outchange = (output_stream!=stdout);
414
415 if (outchange) {
416 out=output_stream;
417 output_stream=stdout;
418 }
419
420 if (inchange) {
421 old_state=input_state;
422 (void)open_input_file("stdin");
423 }
424 }
input_state
ptr_psi_term input_state
Definition: def_glob.h:199
old_state
ptr_psi_term old_state
Definition: token.c:399
outchange
static long outchange
Definition: token.c:397
input_stream
FILE * input_stream
Definition: def_glob.h:38
inchange
static long inchange
Definition: token.c:397
out
static FILE * out
Definition: token.c:398
output_stream
FILE * output_stream
Definition: def_glob.h:41
open_input_file
long open_input_file(char *file)
Definition: token.c:504

void bk_stack_add_psi_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | ptr_psi_term | g
| ) |  |

Definition at line 200 of file token.c.

References bk_stack_insert(), FEATCMP, and heap_copy_string().

204 {
205 (void)bk_stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list), (GENERIC)g);
206 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
bk_stack_insert
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:309
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void end_terminal_io | ( |  | ) |

Definition at line 431 of file token.c.

References inchange, input_state, NULL, old_state, out, outchange, output_stream, and restore_state().

432 {
433 if (inchange) {
434 input_state=old_state;
435 restore_state(old_state);
436 old_state=NULL; /* RM: Feb 17 1993 */
437 }
438 if (outchange)
439 output_stream=out;
440 }
NULL
#define NULL
Definition: def_const.h:203
input_state
ptr_psi_term input_state
Definition: def_glob.h:199
old_state
ptr_psi_term old_state
Definition: token.c:399
outchange
static long outchange
Definition: token.c:397
restore_state
void restore_state(ptr_psi_term t)
Definition: token.c:267
inchange
static long inchange
Definition: token.c:397
out
static FILE * out
Definition: token.c:398
output_stream
FILE * output_stream
Definition: def_glob.h:41

char* expand_file_name | ( | char * | s | ) |

Definition at line 449 of file token.c.

References STRLEN.

451 {
452 char *r;
453 char *home; // *getenv();
454 struct passwd *pw;
455 /* char *user="eight character name"; 18.5 */
456 char userbuf[STRLEN];
457 char *user=userbuf;
458 char *t1,*t2;
459
460 r=s;
461 if (s[0]=='~') {
462 t1=s+1;
463 t2=user;
464 while (*t1!=0 && *t1!='/') {
465 *t2= *t1;
466 *t2++;
467 *t1++;
468 }
469 *t2=0;
470 if ((int)strlen(user)>0) {
471 pw = getpwnam(user);
472 if (pw) {
473 user=pw->pw_dir;
474 r=(char *)malloc(strlen(user)+strlen(t1)+1);
475 sprintf(r,"%s%s",user,t1);
476 }
477 else
478 /* if (warning()) printf("couldn't find user '%s'.\n",user) */;
479 }
480 else {
481 home=getenv("HOME");
482 if (home) {
483 r=(char *)malloc(strlen(home)+strlen(s)+1);
484 sprintf(r,"%s%s",home,s+1);
485 }
486 else
487 /* if (warning()) printf("no HOME directory.\n") */;
488 }
489 }
490
491 /* printf("*** Using file name: '%s'\n",r); */
492
493 return r;
494 }
STRLEN
#define STRLEN
Definition: def_const.h:86

GENERIC get_attr | ( | ptr_psi_term | t,
|  | char * | attrname
| ) |  |

Definition at line 210 of file token.c.

References wl_node::data, FEATCMP, and find().

213 {
214 ptr_node n=find(FEATCMP,attrname,t->attr_list);
215 return n->data;
216 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
wl_node::data
GENERIC data
Definition: def_struct.h:185
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
wl_node
Definition: def_struct.h:181
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

FILE* get_stream | ( | ptr_psi_term | t | ) |

Definition at line 219 of file token.c.

References get_attr(), and STREAM.

221 {
222 return (FILE *) ((ptr_psi_term)get_attr(t,STREAM))->value_3;
223 }
STREAM
#define STREAM
Definition: def_const.h:225
get_attr
GENERIC get_attr(ptr_psi_term t, char *attrname)
Definition: token.c:210
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34

void heap_add_int_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | long | value
| ) |  |

Definition at line 58 of file token.c.

References FEATCMP, heap_alloc(), heap_copy_string(), heap_insert(), heap_psi_term(), integer, REAL, wl_psi_term::type, and wl_psi_term::value_3.

62 {
63 ptr_psi_term t1;
64
65 t1=heap_psi_term(4);
66 t1->type=integer;
67 t1->value_3=heap_alloc(sizeof(REAL));
68 *(REAL *)t1->value_3 = (REAL) value;
69
70 (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list), (GENERIC)t1);
71 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
heap_psi_term
ptr_psi_term heap_psi_term(long stat)
Definition: lefun.c:63
wl_psi_term
Definition: def_struct.h:161
REAL
#define REAL
Definition: def_const.h:72
heap_insert
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:276
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
integer
ptr_definition integer
Definition: def_glob.h:93
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171
heap_alloc
GENERIC heap_alloc(long s)
Definition: memory.c:1518

void heap_add_psi_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | ptr_psi_term | g
| ) |  |

Definition at line 184 of file token.c.

References FEATCMP, heap_copy_string(), and heap_insert().

188 {
189 (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) g);
190 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
heap_insert
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:276
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void heap_add_str_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | char * | str
| ) |  |

Definition at line 122 of file token.c.

References FEATCMP, heap_copy_string(), heap_insert(), heap_psi_term(), quoted_string, wl_psi_term::type, and wl_psi_term::value_3.

126 {
127 ptr_psi_term t1;
128
129 t1=heap_psi_term(4);
130 t1->type=quoted_string;
131 t1->value_3=(GENERIC)heap_copy_string(str);
132
133 (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
134 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
heap_psi_term
ptr_psi_term heap_psi_term(long stat)
Definition: lefun.c:63
wl_psi_term
Definition: def_struct.h:161
heap_insert
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:276
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
quoted_string
ptr_definition quoted_string
Definition: def_glob.h:101
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void heap_mod_int_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | long | value
| ) |  |

Definition at line 91 of file token.c.

References wl_node::data, FEATCMP, find(), REAL, and wl_psi_term::value_3.

95 {
96 ptr_node n;
97 ptr_psi_term t1;
98
99 n=find(FEATCMP,attrname,t->attr_list);
100 t1=(ptr_psi_term)n->data;
101 *(REAL *)t1->value_3 = (REAL) value;
102 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
wl_psi_term
Definition: def_struct.h:161
wl_node::data
GENERIC data
Definition: def_struct.h:185
REAL
#define REAL
Definition: def_const.h:72
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
wl_node
Definition: def_struct.h:181
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void heap_mod_str_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | char * | str
| ) |  |

Definition at line 153 of file token.c.

References wl_node::data, FEATCMP, find(), heap_copy_string(), and wl_psi_term::value_3.

157 {
158 ptr_node n;
159 ptr_psi_term t1;
160
161 n=find(FEATCMP,attrname,t->attr_list);
162 t1=(ptr_psi_term)n->data;
163 t1->value_3=(GENERIC)heap_copy_string(str);
164 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
wl_psi_term
Definition: def_struct.h:161
wl_node::data
GENERIC data
Definition: def_struct.h:185
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
wl_node
Definition: def_struct.h:181
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void init_parse_state | ( |  | ) |

Definition at line 381 of file token.c.

References eof_flag, FALSE, line_count, NULL, old_saved_char, old_saved_psi_term, saved_char, saved_psi_term, start_of_line, stringparse, and TRUE.

382 {
383 line_count=0;
384 start_of_line=TRUE;
385 saved_char=0;
386 old_saved_char=0;
387 saved_psi_term=NULL;
388 old_saved_psi_term=NULL;
389 eof_flag=FALSE;
390 stringparse=FALSE;
391 }
eof_flag
long eof_flag
Definition: def_glob.h:196
start_of_line
long start_of_line
Definition: def_glob.h:191
old_saved_char
long old_saved_char
Definition: def_glob.h:193
NULL
#define NULL
Definition: def_const.h:203
saved_char
long saved_char
Definition: def_glob.h:192
line_count
long line_count
Definition: def_glob.h:39
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
stringparse
long stringparse
Definition: def_glob.h:202
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

long legal_in_name | ( | long | c | ) |

Definition at line 861 of file token.c.

References DIGIT, LOWER, and UPPER.

863 {
864 return
865 UPPER(c) ||
866 LOWER(c) ||
867 DIGIT(c);
868
869 /* || c=='\'' RM: Dec 16 1992 */ ;
870 }
UPPER
#define UPPER(C)
Definition: def_macro.h:39
DIGIT
#define DIGIT(C)
Definition: def_macro.h:37
LOWER
#define LOWER(C)
Definition: def_macro.h:41

void new_state | ( | ptr_psi_term * | t | ) |

Definition at line 301 of file token.c.

References current_module, CURRENT_MODULE, eof_flag, EOF_FLAG, heap_add_int_attr(), heap_add_psi_attr(), heap_add_str_attr(), heap_psi_term(), input_file_name, INPUT_FILE_NAME, input_stream, inputfilesym, lf_false, lf_true, line_count, LINE_COUNT, wl_module::module_name, null_psi_term, old_saved_char, OLD_SAVED_CHAR, old_saved_psi_term, OLD_SAVED_PSI_TERM, saved_char, SAVED_CHAR, saved_psi_term, SAVED_PSI_TERM, start_of_line, START_OF_LINE, stream, STREAM, wl_psi_term::type, and wl_psi_term::value_3.

303 {
304 ptr_psi_term t1;
305
306 *t=heap_psi_term(4);
307 (*t)->type=inputfilesym;
308
309 t1=heap_psi_term(4);
310 t1->type=stream;
311 t1->value_3=(GENERIC)input_stream;
312 heap_add_psi_attr(*t,STREAM,t1);
313
314 /* RM: Jan 27 1993 */
315 heap_add_str_attr(*t,CURRENT_MODULE,current_module->module_name);
316
317 /*
318 printf("Creating new state for file '%s', module '%s'\n",
319 input_file_name,
320 current_module->module_name);
321 */
322
323 heap_add_str_attr(*t,INPUT_FILE_NAME,input_file_name);
324 heap_add_int_attr(*t,LINE_COUNT,line_count);
325 heap_add_int_attr(*t,SAVED_CHAR,saved_char);
326 heap_add_int_attr(*t,OLD_SAVED_CHAR,old_saved_char);
327
328 t1=saved_psi_term?saved_psi_term:null_psi_term;
329 heap_add_psi_attr(*t,SAVED_PSI_TERM,t1);
330
331 t1=old_saved_psi_term?old_saved_psi_term:null_psi_term;
332 heap_add_psi_attr(*t,OLD_SAVED_PSI_TERM,t1);
333
334 t1=heap_psi_term(4);
335 t1->type=(eof_flag?lf_true:lf_false);
336 heap_add_psi_attr(*t,EOF_FLAG,t1);
337
338 t1=heap_psi_term(4);
339 t1->type=(start_of_line?lf_true:lf_false);
340 heap_add_psi_attr(*t,START_OF_LINE,t1);
341 }
LINE_COUNT
#define LINE_COUNT
Definition: def_const.h:227
current_module
ptr_module current_module
Definition: def_glob.h:161
eof_flag
long eof_flag
Definition: def_glob.h:196
stream
ptr_definition stream
Definition: def_glob.h:103
start_of_line
long start_of_line
Definition: def_glob.h:191
input_file_name
string input_file_name
Definition: def_glob.h:40
SAVED_PSI_TERM
#define SAVED_PSI_TERM
Definition: def_const.h:231
heap_psi_term
ptr_psi_term heap_psi_term(long stat)
Definition: lefun.c:63
OLD_SAVED_CHAR
#define OLD_SAVED_CHAR
Definition: def_const.h:230
null_psi_term
ptr_psi_term null_psi_term
Definition: def_glob.h:140
wl_psi_term
Definition: def_struct.h:161
CURRENT_MODULE
#define CURRENT_MODULE
Definition: def_const.h:234
old_saved_char
long old_saved_char
Definition: def_glob.h:193
saved_char
long saved_char
Definition: def_glob.h:192
line_count
long line_count
Definition: def_glob.h:39
STREAM
#define STREAM
Definition: def_const.h:225
START_OF_LINE
#define START_OF_LINE
Definition: def_const.h:228
heap_add_str_attr
void heap_add_str_attr(ptr_psi_term t, char *attrname, char *str)
Definition: token.c:122
heap_add_psi_attr
void heap_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
Definition: token.c:184
lf_true
ptr_definition lf_true
Definition: def_glob.h:107
input_stream
FILE * input_stream
Definition: def_glob.h:38
lf_false
ptr_definition lf_false
Definition: def_glob.h:89
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
INPUT_FILE_NAME
#define INPUT_FILE_NAME
Definition: def_const.h:226
wl_module::module_name
char * module_name
Definition: def_struct.h:75
OLD_SAVED_PSI_TERM
#define OLD_SAVED_PSI_TERM
Definition: def_const.h:232
heap_add_int_attr
void heap_add_int_attr(ptr_psi_term t, char *attrname, long value)
Definition: token.c:58
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
EOF_FLAG
#define EOF_FLAG
Definition: def_const.h:233
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
SAVED_CHAR
#define SAVED_CHAR
Definition: def_const.h:229
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
inputfilesym
ptr_definition inputfilesym
Definition: def_glob.h:120
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

long open_input_file | ( | char * | file | ) |

Definition at line 504 of file token.c.

References Errorline(), expand_file_name(), FALSE, init_parse_state(), input_file_name, input_state, input_stream, new_state(), noisy, NULL, restore_state(), save_state(), stdin_state, and TRUE.

506 {
507 long ok=TRUE;
508 long stdin_flag;
509
510 /* Save global input file state */
511 if (input_state!=NULL) save_state(input_state);
512
513 file=expand_file_name(file);
514
515 if ((stdin_flag=(!strcmp(file,"stdin")))) {
516 input_stream=stdin;
517 noisy=TRUE;
518 }
519 else {
520 input_stream=fopen(file,"r");
521 noisy=FALSE;
522 }
523
524 if (input_stream==NULL) {
525 Errorline("file '%s' does not exist.\n",file);
526 file="stdin";
527 input_stream=stdin;
528 noisy=TRUE;
529 ok=FALSE;
530 }
531
532 if (!stdin_flag || stdin_state==NULL) {
533 /* Initialize a new global input file state */
534 strcpy(input_file_name,file);
535 init_parse_state();
536 /* Create a new state containing the new global values */
537 new_state(&input_state);
538 if (stdin_flag) stdin_state=input_state;
539 }
540 else {
541 input_state=stdin_state;
542 restore_state(input_state);
543 }
544
545 return ok;
546 }
init_parse_state
void init_parse_state()
Definition: token.c:381
stdin_state
ptr_psi_term stdin_state
Definition: def_glob.h:200
input_file_name
string input_file_name
Definition: def_glob.h:40
save_state
void save_state(ptr_psi_term t)
Definition: token.c:230
NULL
#define NULL
Definition: def_const.h:203
input_state
ptr_psi_term input_state
Definition: def_glob.h:199
noisy
long noisy
Definition: def_glob.h:35
Errorline
void Errorline(char *format,...)
Definition: error.c:414
restore_state
void restore_state(ptr_psi_term t)
Definition: token.c:267
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
input_stream
FILE * input_stream
Definition: def_glob.h:38
expand_file_name
char * expand_file_name(char *s)
Definition: token.c:449
new_state
void new_state(ptr_psi_term *t)
Definition: token.c:301

long open_output_file | ( | string | file | ) |

Definition at line 554 of file token.c.

References Errorline(), expand_file_name(), FALSE, NULL, output_stream, and TRUE.

556 {
557 long ok=TRUE;
558
559
560 file=expand_file_name(file);
561
562 if (!strcmp(file,"stdout"))
563 output_stream=stdout;
564 else
565 if (!strcmp(file,"stderr"))
566 output_stream=stderr;
567 else
568 output_stream=fopen(file,"w");
569
570 if (output_stream==NULL) {
571 Errorline("file '%s' could not be opened for output.\n",file);
572 ok=FALSE;
573 output_stream=stdout;
574 }
575
576 return ok;
577 }
NULL
#define NULL
Definition: def_const.h:203
Errorline
void Errorline(char *format,...)
Definition: error.c:414
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
expand_file_name
char * expand_file_name(char *s)
Definition: token.c:449
output_stream
FILE * output_stream
Definition: def_glob.h:41

void psi_term_error | ( |  | ) |

Definition at line 661 of file token.c.

References FALSE, input_file_name, parse_ok, perr_i(), perr_s(), and psi_term_line_number.

662 {
663 perr_i("near line %ld",psi_term_line_number);
664 if (strcmp(input_file_name,"stdin")) {
665 perr_s(" in file \042%s\042",input_file_name);
666 }
667 /* prompt="error>"; 20.8 */
668 parse_ok=FALSE;
669 }
psi_term_line_number
long psi_term_line_number
Definition: def_glob.h:268
input_file_name
string input_file_name
Definition: def_glob.h:40
perr_s
void perr_s(char *s1, char *s2)
Definition: error.c:665
FALSE
#define FALSE
Definition: def_const.h:128
parse_ok
long parse_ok
Definition: def_glob.h:171
perr_i
void perr_i(char *str, long i)
Definition: error.c:677

void put_back_char | ( | long | c | ) |

Definition at line 633 of file token.c.

References Errorline(), old_saved_char, and saved_char.

635 {
636 if (old_saved_char)
637 Errorline("in tokenizer, put_back_char three times (last=%d).\n",c);
638 old_saved_char=saved_char;
639 saved_char=c;
640 }
old_saved_char
long old_saved_char
Definition: def_glob.h:193
saved_char
long saved_char
Definition: def_glob.h:192
Errorline
void Errorline(char *format,...)
Definition: error.c:414

void put_back_token | ( | psi_term | t | ) |

Definition at line 647 of file token.c.

References Errorline(), NULL, old_saved_psi_term, saved_psi_term, and stack_copy_psi_term().

649 {
650 if (old_saved_psi_term!=NULL)
651 Errorline("in parser, put_back_token three times (last=%P).\n",t);
652 old_saved_psi_term=saved_psi_term;
653 saved_psi_term=stack_copy_psi_term(t);
654 }
NULL
#define NULL
Definition: def_const.h:203
Errorline
void Errorline(char *format,...)
Definition: error.c:414
stack_copy_psi_term
ptr_psi_term stack_copy_psi_term(psi_term t)
Definition: parser.c:183
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

long read_char | ( |  | ) |

Definition at line 587 of file token.c.

References EOLN, FALSE, infoline(), input_stream, line_count, NULL, old_saved_char, prompt, saved_char, start_of_line, stringinput, stringparse, trace_input, and TRUE.

588 {
589 int c=0;
590
591 if ((c=saved_char)) {
592 saved_char=old_saved_char;
593 old_saved_char=0;
594 }
595 else if (stringparse) {
596 if ((c=(*stringinput)))
597 stringinput++;
598 else
599 c=EOF;
600 }
601 else if (input_stream == NULL || feof(input_stream))
602 c=EOF;
603 else {
604 if (start_of_line) {
605 start_of_line=FALSE;
606 line_count++;
607 if (input_stream==stdin) infoline("%s",prompt); /* 21.1 */
608 }
609
610 c=fgetc(input_stream);
611
612 if(trace_input) /* RM: Jan 13 1993 */
613 if(c!=EOF)
614 printf("%c",c);
615 else
616 printf(" <EOF>\n");
617
618 if (c==EOLN)
619 start_of_line=TRUE;
620 }
621
622 /* printf("%c\n",c); RM: Jan 5 1993 Just to trace the parser */
623
624 return c;
625 }
start_of_line
long start_of_line
Definition: def_glob.h:191
old_saved_char
long old_saved_char
Definition: def_glob.h:193
NULL
#define NULL
Definition: def_const.h:203
saved_char
long saved_char
Definition: def_glob.h:192
trace_input
long trace_input
Definition: token.c:8
line_count
long line_count
Definition: def_glob.h:39
EOLN
#define EOLN
Definition: def_const.h:140
infoline
void infoline(char *format,...)
Definition: error.c:245
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
input_stream
FILE * input_stream
Definition: def_glob.h:38
prompt
char * prompt
Definition: def_glob.h:42
stringparse
long stringparse
Definition: def_glob.h:202
stringinput
char * stringinput
Definition: def_glob.h:203

void read_comment | ( | ptr_psi_term | tok | ) |

Definition at line 676 of file token.c.

References comment, EOLN, and read_char().

678 {
679 long c;
680
681 do {
682 c=read_char();
683 } while (c!=EOF && c!=EOLN);
684
685 tok->type=comment;
686 }
comment
ptr_definition comment
Definition: def_glob.h:80
EOLN
#define EOLN
Definition: def_const.h:140
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
read_char
long read_char()
Definition: token.c:587

void read_name | ( | ptr_psi_term | tok,
|  | long | ch,
|  | long (*)(long) | f,
|  | ptr_definition | typ
| ) |  |

Definition at line 878 of file token.c.

References bk2_stack_insert(), constant, create_module(), FALSE, find(), global, heap_copy_string(), legal_in_name(), wl_module::module_name, NULL, put_back_char(), read_char(), STRCMP, STRLEN, SYMBOL, symbolic(), TOKEN_ERROR(), TRUE, update_symbol(), var_occurred, var_tree, and warningline().

883 {
884 char c;
885 string str;
886 long len=1;
887 long store=TRUE;
888 long flag=TRUE;
889 ptr_module module=NULL;
890 ptr_node n; /* RM: Feb 9 1993 */
891
892 tok->coref=NULL;
893 tok->resid=NULL;
894 tok->attr_list=NULL;
895
896 str[0]=ch;
897
898 do {
899 c=read_char();
900 flag=(*f)(c);
901
902 if(c=='#' && /* RM: Feb 3 1993 */
903 (long)f==(long)legal_in_name &&
904 len>0 &&
905 len<STRLEN &&
906 !module) {
907 str[len]=0;
908 module=create_module(str);
909 len=0;
910 flag=TRUE;
911
912 /* RM: Sep 21 1993 */
913 /* Change the type function if required */
914 c=read_char();
915 if SYMBOL(c)
916 f=symbolic;
917 put_back_char(c);
918 }
919 else
920 if (flag) {
921 if (store)
922 if (len==STRLEN) {
923 warningline("name too long, extra ignored (%E).\n");
924 store=FALSE;
925 }
926 else
927 str[len++]=c;
928 }
929 else
930 put_back_char(c);
931 } while(flag);
932
933 if(module && len==0) { /* RM: Feb 3 1993 */
934 strcpy(str,module->module_name);
935 len=strlen(str);
936 put_back_char('#');
937 module=NULL;
938 }
939
940 str[len]=0;
941
942 tok->type=typ;
943
944 if(typ==constant) {
945 /* printf("module=%s\n",module->module_name); */
946 tok->type=update_symbol(module,str); /* RM: Feb 3 1993 */
947 tok->value_3=NULL;
948
949 TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
950
951 /* PVR 4.2.94 for correct level incrementing */
952 if (tok->type->type_def==(def_type)global) {
953 var_occurred=TRUE;
954 }
955 if (FALSE /*tok->type->type==global && tok->type->global_value*/) {
956 /* RM: Nov 10 1993 */
957
958 /* Remove this for Bruno who didn't like it, and doesn't like
959 to use "print_depth" */
960
961 /* RM: Feb 9 1993 */
962 /* Add into the variable tree */
963 var_occurred=TRUE;
964 n=find(STRCMP,tok->type->keyword->symbol,var_tree);
965 if (n==NULL) {
966 /* The change is always trailed. */
967 (void)bk2_stack_insert(STRCMP,
968 tok->type->keyword->symbol,
969 &var_tree,
970 (GENERIC)tok->type->global_value);
971 }
972 }
973
974 }
975 else
976 tok->value_3=(GENERIC)heap_copy_string(str);
977 }
wl_psi_term::resid
ptr_residuation resid
Definition: def_struct.h:173
create_module
ptr_module create_module(char *module)
Definition: modules.c:67
global
#define global
Definition: def_const.h:364
wl_module
Definition: def_struct.h:74
wl_definition::type_def
def_type type_def
Definition: def_struct.h:133
constant
ptr_definition constant
Definition: def_glob.h:82
wl_definition::keyword
ptr_keyword keyword
Definition: def_struct.h:124
NULL
#define NULL
Definition: def_const.h:203
var_tree
ptr_node var_tree
Definition: def_glob.h:26
bk2_stack_insert
ptr_node bk2_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:327
wl_keyword::symbol
char * symbol
Definition: def_struct.h:91
update_symbol
ptr_definition update_symbol(ptr_module module, char *symbol)
Definition: modules.c:264
SYMBOL
#define SYMBOL(C)
Definition: def_macro.h:52
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
TRUE
#define TRUE
Definition: def_const.h:127
STRCMP
#define STRCMP
Definition: def_const.h:255
wl_definition::global_value
ptr_psi_term global_value
Definition: def_struct.h:141
FALSE
#define FALSE
Definition: def_const.h:128
var_occurred
long var_occurred
Definition: def_glob.h:189
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_module::module_name
char * module_name
Definition: def_struct.h:75
wl_psi_term::coref
ptr_psi_term coref
Definition: def_struct.h:172
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
legal_in_name
long legal_in_name(long c)
Definition: token.c:861
wl_definition
Definition: def_struct.h:121
symbolic
long symbolic(long c)
Definition: token.c:850
STRLEN
#define STRLEN
Definition: def_const.h:86
TOKEN_ERROR
void TOKEN_ERROR(ptr_psi_term p)
Definition: token.c:30
warningline
void warningline(char *format,...)
Definition: error.c:327
wl_node
Definition: def_struct.h:181
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
read_char
long read_char()
Definition: token.c:587
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171
put_back_char
void put_back_char(long c)
Definition: token.c:633

void read_number | ( | ptr_psi_term | tok,
|  | long | c
| ) |  |

Definition at line 986 of file token.c.

References DIGIT, heap_alloc(), integer, put_back_char(), read_char(), REAL, and real.

989 {
990 long c2;
991 REAL f,p;
992 long /* sgn, */ pwr,posflag;
993
994 /* if (sgn=(c=='-')) c=read_char(); */
995
996 /* tok->type=integer; RM: Mar 8 1993 */
997
998 f=0.0;
999 do { f=f*10.0+(c-'0'); c=read_char(); } while (DIGIT(c));
1000
1001 if (c=='.') {
1002 c2=read_char();
1003 if DIGIT(c2) {
1004 /* tok->type=real; RM: Mar 8 1993 */
1005 p=10.0;
1006 while (DIGIT(c2)) { f=f+(c2-'0')/p; p=p*10.0; c2=read_char(); }
1007 put_back_char(c2);
1008 }
1009 else {
1010 put_back_char(c2);
1011 put_back_char(c);
1012 }
1013 }
1014 else
1015 put_back_char(c);
1016
1017 c=read_char();
1018 if (c=='e' || c=='E') {
1019 c2=read_char();
1020 if (c2=='+' || c2=='-' || DIGIT(c2)) {
1021 tok->type=real;
1022 posflag = (c2=='+' || DIGIT(c2));
1023 if (!DIGIT(c2)) c2=read_char();
1024 pwr=0;
1025 while (DIGIT(c2)) { pwr=pwr*10+(c2-'0'); c2=read_char(); }
1026 put_back_char(c2);
1027 p=1.0;
1028 while (pwr>=100) { pwr-=100; if (posflag) p*=1e100; else p/=1e100; }
1029 while (pwr>=10 ) { pwr-=10; if (posflag) p*=1e10; else p/=1e10; }
1030 while (pwr>0 ) { pwr-=1; if (posflag) p*=1e1; else p/=1e1; }
1031 f*=p;
1032 }
1033 else {
1034 put_back_char(c2);
1035 put_back_char(c);
1036 }
1037 }
1038 else
1039 put_back_char(c);
1040
1041 /* if (sgn) f = -f; */
1042 tok->value_3=heap_alloc(sizeof(REAL)); /* 12.5 */
1043 *(REAL *)tok->value_3=f;
1044
1045 /* RM: Mar 8 1993 */
1046 if(f==floor(f))
1047 tok->type=integer;
1048 else
1049 tok->type=real;
1050 }
DIGIT
#define DIGIT(C)
Definition: def_macro.h:37
REAL
#define REAL
Definition: def_const.h:72
real
ptr_definition real
Definition: def_glob.h:102
integer
ptr_definition integer
Definition: def_glob.h:93
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
read_char
long read_char()
Definition: token.c:587
heap_alloc
GENERIC heap_alloc(long s)
Definition: memory.c:1518
put_back_char
void put_back_char(long c)
Definition: token.c:633

void read_string | ( | ptr_psi_term | tok,
|  | long | e
| ) |  |

Definition at line 743 of file token.c.

References base2int(), FALSE, heap_copy_string(), isoctal, NULL, put_back_char(), read_char(), read_string_error(), STRLEN, TOKEN_ERROR(), TRUE, update_symbol(), and warningline().

746 {
747 long c;
748 string str;
749 long len=0;
750 long store=TRUE;
751 long flag=TRUE;
752
753 str[len]=0;
754
755 do {
756 c=read_char();
757 if (c==EOF) {
758 store=FALSE;
759 flag=FALSE;
760 read_string_error(0);
761 }
762 else if (e=='"' && c=='\\') {
763 c=read_char();
764 if (c==EOF) {
765 store=FALSE;
766 flag=FALSE;
767 put_back_char('\\');
768 read_string_error(0);
769 }
770 else {
771 switch (c) {
772 case 'a': c='\a'; break;
773 case 'b': c='\b'; break;
774 case 'f': c='\f'; break;
775 case 'n': c='\n'; break;
776 case 'r': c='\r'; break;
777 case 't': c='\t'; break;
778 case 'v': c='\v'; break;
779 /* missing \ooo and \xhh */
780 case 'x':
781 {
782 int n;
783 c=read_char();
784 if (c==EOF) {
785 store=flag=FALSE;
786 read_string_error(0);
787 break;
788 }
789 else if (!isxdigit(c)) {
790 store=flag=FALSE;
791 read_string_error(1);
792 break;
793 }
794 else {
795 n = base2int(c);
796 }
797 c=read_char();
798 if (isxdigit(c)) n = 16*n+base2int(c);
799 else put_back_char(c);
800 c=n;
801 break;
802 }
803 default:
804 if (isoctal(c)) {
805 int n,i;
806 for(i=n=0;i<3&&isoctal(c);i++,c=read_char())
807 n = n*8 + base2int(c);
808 if (c!=EOF) put_back_char(c);
809 c=n;
810 break;
811 }
812 else break;
813 }
814 }
815 }
816 else
817 if (c==e) {
818 c=read_char();
819 if (c!=e) {
820 store=FALSE;
821 flag=FALSE;
822 put_back_char(c);
823 }
824 }
825 if (store)
826 if (len==STRLEN) {
827 warningline("string too long, extra ignored (%E).\n");
828 store=FALSE;
829 }
830 else {
831 str[len++]=c;
832 str[len]=0;
833 }
834 } while(flag);
835
836 if (e=='"')
837 tok->value_3=(GENERIC)heap_copy_string(str);
838 else {
839 tok->type=update_symbol(NULL,str); /* Maybe no_module would be better */
840 tok->value_3=NULL;
841 TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
842 }
843 }
base2int
int base2int(int n)
Definition: token.c:705
NULL
#define NULL
Definition: def_const.h:203
update_symbol
ptr_definition update_symbol(ptr_module module, char *symbol)
Definition: modules.c:264
read_string_error
void read_string_error(int n)
Definition: token.c:689
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
isoctal
#define isoctal(c)
Definition: token.c:737
STRLEN
#define STRLEN
Definition: def_const.h:86
TOKEN_ERROR
void TOKEN_ERROR(ptr_psi_term p)
Definition: token.c:30
warningline
void warningline(char *format,...)
Definition: error.c:327
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
read_char
long read_char()
Definition: token.c:587
put_back_char
void put_back_char(long c)
Definition: token.c:633

void read_string_error | ( | int | n | ) |

Definition at line 689 of file token.c.

References FALSE, parse_ok, stringparse, and Syntaxerrorline().

691 {
692 if (stringparse) parse_ok=FALSE;
693 else
694 switch (n) {
695 case 0:
696 Syntaxerrorline("end of file reached before end of string (%E).\n");
697 break;
698 case 1:
699 Syntaxerrorline("Hexadecimal digit expected (%E).\n");
700 break;
701 }
702 }
Syntaxerrorline
void Syntaxerrorline(char *format,...)
Definition: error.c:498
FALSE
#define FALSE
Definition: def_const.h:128
stringparse
long stringparse
Definition: def_glob.h:202
parse_ok
long parse_ok
Definition: def_glob.h:171

void read_token | ( | ptr_psi_term | tok | ) |

Definition at line 1063 of file token.c.

References read_token_main(), and TRUE.

1065 { read_token_main(tok, TRUE); }
read_token_main
void read_token_main(ptr_psi_term, long)
Definition: token.c:1073
TRUE
#define TRUE
Definition: def_const.h:127

void read_token_b | ( | ptr_psi_term | tok | ) |

Definition at line 1069 of file token.c.

References FALSE, and read_token_main().

1071 { read_token_main(tok, FALSE); }
read_token_main
void read_token_main(ptr_psi_term, long)
Definition: token.c:1073
FALSE
#define FALSE
Definition: def_const.h:128

void read_token_main | ( | ptr_psi_term | tok,
|  | long | for_parser
| ) |  |

Definition at line 1073 of file token.c.

References bk2_stack_insert(), choice_stack, comment, constant, wl_psi_term::coref, current_module, cut, wl_node::data, DIGIT, eof, EOLN, Errorline(), FALSE, final_dot, final_question, find(), legal_in_name(), line_count, LOWER, nothing, NULL, old_saved_psi_term, prompt, psi_term_line_number, put_back_char(), quoted_string, read_char(), read_comment(), read_name(), read_number(), read_string(), read_token(), saved_psi_term, SINGLE, stack_psi_term(), STRCMP, SYMBOL, symbolic(), TOKEN_ERROR(), TRUE, update_symbol(), UPPER, var_occurred, var_tree, and variable.

1076 {
1077 long c, c2;
1078 ptr_node n;
1079 char p[2];
1080
1081 if (for_parser && (saved_psi_term!=NULL)) {
1082 *tok= *saved_psi_term;
1083 saved_psi_term=old_saved_psi_term;
1084 old_saved_psi_term=NULL;
1085 }
1086 else {
1087 tok->type=nothing;
1088
1089 do {
1090 c=read_char();
1091 } while(c!=EOF && (c<=32));
1092
1093 if (for_parser) psi_term_line_number=line_count;
1094
1095 switch(c) {
1096 case EOF:
1097 tok->type=eof;
1098 tok->value_3=NULL;
1099 break;
1100 case '%':
1101 read_comment(tok);
1102 break;
1103 case '"':
1104 read_string(tok,c);
1105 tok->type=quoted_string;
1106 break;
1107 case 39: /* The quote symbol "'" */
1108 read_string(tok,c);
1109 break;
1110
1111 default:
1112
1113 /* Adding this results in problems with terms like (N-1) */
1114 /* if (c=='-' && (c2=read_char()) && DIGIT(c2)) {
1115 put_back_char(c2);
1116 read_number(tok,c);
1117 }
1118 else */
1119
1120 if(c=='.' || c=='?') { /* RM: Jul 7 1993 */
1121 c2=read_char();
1122 put_back_char(c2);
1123 /*printf("c2=%d\n",c2);*/
1124 if(c2<=' ' || c2==EOF) {
1125 if(c=='.')
1126 tok->type=final_dot;
1127 else
1128 tok->type=final_question;
1129
1130 tok->value_3=NULL;
1131 }
1132 else
1133 read_name(tok,c,symbolic,constant);
1134 }
1135 else
1136 if DIGIT(c)
1137 read_number(tok,c);
1138 else
1139 if UPPER(c) {
1140 read_name(tok,c,legal_in_name,variable);
1141 }
1142 else
1143 if LOWER(c) {
1144 read_name(tok,c,legal_in_name,constant);
1145 }
1146 else
1147 if SYMBOL(c) {
1148 read_name(tok,c,symbolic,constant);
1149 }
1150 else /* RM: Jul 7 1993 Moved this */
1151 if SINGLE(c) {
1152 p[0]=c; p[1]=0;
1153 tok->type=update_symbol(current_module,p);
1154 tok->value_3=NULL;
1155 TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
1156 }
1157 else {
1158 Errorline("illegal character %d in input (%E).\n",c);
1159 }
1160 }
1161
1162 if (tok->type==variable) {
1163 if (tok->value_3) {
1164 /* If the variable read in has name "_", then it becomes 'top' */
1165 /* and is no longer a variable whose name must be remembered. */
1166 /* As a result, '@' and '_' are synonyms in the program input. */
1167 if (!strcmp((char *)tok->value_3,"_")) {
1168 p[0]='@'; p[1]=0;
1169 tok->type=update_symbol(current_module,p);
1170 tok->value_3=NULL;
1171 TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
1172 }
1173 else {
1174 /* Insert into variable tree, create 'top' value if need be. */
1175 var_occurred=TRUE;
1176 n=find(STRCMP,(char *)tok->value_3,var_tree);
1177 if (n==NULL) {
1178 ptr_psi_term t=stack_psi_term(0);
1179 /* The change is always trailed. */
1180 (void)bk2_stack_insert(STRCMP,(char *)tok->value_3,&var_tree,(GENERIC)t); /* 17.8 */
1181 tok->coref=t;
1182 }
1183 else
1184 tok->coref=(ptr_psi_term)n->data;
1185 }
1186 }
1187 /* else do nothing */
1188 }
1189 }
1190
1191 if (tok->type==comment)
1192 read_token(tok);
1193
1194 if (tok->type!=variable)
1195 tok->coref=NULL;
1196
1197 tok->attr_list=NULL;
1198 tok->status=0;
1199 tok->flags=FALSE; /* 14.9 */
1200 tok->resid=NULL;
1201
1202 if (tok->type==cut) /* 12.7 */
1203 tok->value_3=(GENERIC)choice_stack;
1204
1205 do {
1206 c=read_char();
1207 if (c==EOLN) {
1208 if (for_parser) put_back_char(c);
1209 c=0;
1210 }
1211 else if (c<0 || c>32) {
1212 put_back_char(c);
1213 c=0;
1214 }
1215 } while(c && c!=EOF);
1216
1217 if (for_parser) prompt="| ";
1218 }
wl_psi_term::resid
ptr_residuation resid
Definition: def_struct.h:173
current_module
ptr_module current_module
Definition: def_glob.h:161
UPPER
#define UPPER(C)
Definition: def_macro.h:39
comment
ptr_definition comment
Definition: def_glob.h:80
psi_term_line_number
long psi_term_line_number
Definition: def_glob.h:268
wl_psi_term
Definition: def_struct.h:161
DIGIT
#define DIGIT(C)
Definition: def_macro.h:37
constant
ptr_definition constant
Definition: def_glob.h:82
wl_node::data
GENERIC data
Definition: def_struct.h:185
NULL
#define NULL
Definition: def_const.h:203
var_tree
ptr_node var_tree
Definition: def_glob.h:26
bk2_stack_insert
ptr_node bk2_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:327
read_name
void read_name(ptr_psi_term tok, long ch, long(*f)(long), ptr_definition typ)
Definition: token.c:878
read_string
void read_string(ptr_psi_term tok, long e)
Definition: token.c:743
update_symbol
ptr_definition update_symbol(ptr_module module, char *symbol)
Definition: modules.c:264
LOWER
#define LOWER(C)
Definition: def_macro.h:41
SYMBOL
#define SYMBOL(C)
Definition: def_macro.h:52
line_count
long line_count
Definition: def_glob.h:39
Errorline
void Errorline(char *format,...)
Definition: error.c:414
EOLN
#define EOLN
Definition: def_const.h:140
read_number
void read_number(ptr_psi_term tok, long c)
Definition: token.c:986
eof
ptr_definition eof
Definition: def_glob.h:86
TRUE
#define TRUE
Definition: def_const.h:127
STRCMP
#define STRCMP
Definition: def_const.h:255
final_dot
ptr_definition final_dot
Definition: def_glob.h:137
FALSE
#define FALSE
Definition: def_const.h:128
var_occurred
long var_occurred
Definition: def_glob.h:189
quoted_string
ptr_definition quoted_string
Definition: def_glob.h:101
stack_psi_term
ptr_psi_term stack_psi_term(long stat)
Definition: lefun.c:15
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::coref
ptr_psi_term coref
Definition: def_struct.h:172
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
legal_in_name
long legal_in_name(long c)
Definition: token.c:861
wl_psi_term::status
long status
Definition: def_struct.h:166
wl_psi_term::flags
long flags
Definition: def_struct.h:169
final_question
ptr_definition final_question
Definition: def_glob.h:138
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
read_comment
void read_comment(ptr_psi_term tok)
Definition: token.c:676
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
prompt
char * prompt
Definition: def_glob.h:42
symbolic
long symbolic(long c)
Definition: token.c:850
cut
ptr_definition cut
Definition: def_glob.h:83
SINGLE
#define SINGLE(C)
Definition: def_macro.h:47
nothing
ptr_definition nothing
Definition: def_glob.h:98
TOKEN_ERROR
void TOKEN_ERROR(ptr_psi_term p)
Definition: token.c:30
wl_node
Definition: def_struct.h:181
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
read_char
long read_char()
Definition: token.c:587
variable
ptr_definition variable
Definition: def_glob.h:111
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171
choice_stack
ptr_choice_point choice_stack
Definition: def_glob.h:51
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195
read_token
void read_token(ptr_psi_term tok)
Definition: token.c:1063
put_back_char
void put_back_char(long c)
Definition: token.c:633

void restore_parse_state | ( | ptr_parse_block | pb | ) |

Definition at line 365 of file token.c.

References eof_flag, line_count, old_saved_char, old_saved_psi_term, saved_char, saved_psi_term, and start_of_line.

367 {
368 if (pb) {
369 line_count = pb->lc;
370 start_of_line = pb->sol;
371 saved_char = pb->sc;
372 old_saved_char = pb->osc;
373 saved_psi_term = pb->spt;
374 old_saved_psi_term = pb->ospt;
375 eof_flag = pb->ef;
376 }
377 }
wl_parse_block::ospt
ptr_psi_term ospt
Definition: def_struct.h:377
eof_flag
long eof_flag
Definition: def_glob.h:196
wl_parse_block::sol
long sol
Definition: def_struct.h:373
start_of_line
long start_of_line
Definition: def_glob.h:191
wl_parse_block::osc
long osc
Definition: def_struct.h:375
old_saved_char
long old_saved_char
Definition: def_glob.h:193
saved_char
long saved_char
Definition: def_glob.h:192
line_count
long line_count
Definition: def_glob.h:39
wl_parse_block::lc
long lc
Definition: def_struct.h:372
wl_parse_block::ef
long ef
Definition: def_struct.h:378
wl_parse_block::sc
long sc
Definition: def_struct.h:374
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
wl_parse_block::spt
ptr_psi_term spt
Definition: def_struct.h:376
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

void restore_state | ( | ptr_psi_term | t | ) |

Definition at line 267 of file token.c.

References eof_flag, EOF_FLAG, get_attr(), input_file_name, INPUT_FILE_NAME, input_stream, lf_true, line_count, LINE_COUNT, NULL, null_psi_term, old_saved_char, OLD_SAVED_CHAR, old_saved_psi_term, OLD_SAVED_PSI_TERM, REAL, saved_char, SAVED_CHAR, saved_psi_term, SAVED_PSI_TERM, start_of_line, START_OF_LINE, and STREAM.

269 {
270 // long i;
271 char *str;
272
273
274 input_stream = (FILE *) ((ptr_psi_term)get_attr(t,STREAM))->value_3;
275 str = (char*) ((ptr_psi_term)get_attr(t,INPUT_FILE_NAME))->value_3;
276 strcpy(input_file_name,str);
277 /* for (i=0;i++;i<=strlen(str)) input_file_name[i]=str[i]; */
278 line_count = *(REAL *) ((ptr_psi_term)get_attr(t,LINE_COUNT))->value_3;
279 saved_char = *(REAL *) ((ptr_psi_term)get_attr(t,SAVED_CHAR))->value_3;
280 old_saved_char= *(REAL *)((ptr_psi_term)get_attr(t,OLD_SAVED_CHAR))->value_3;
281
282 saved_psi_term=(ptr_psi_term)get_attr(t,SAVED_PSI_TERM);
283 if (saved_psi_term==null_psi_term) saved_psi_term=NULL;
284
285 old_saved_psi_term=(ptr_psi_term)get_attr(t,OLD_SAVED_PSI_TERM);
286 if (old_saved_psi_term==null_psi_term) old_saved_psi_term=NULL;
287
288 eof_flag = ((ptr_psi_term)get_attr(t,EOF_FLAG))->type==lf_true;
289 start_of_line = ((ptr_psi_term)get_attr(t,START_OF_LINE))->type==lf_true;
290
291
292 /* RM: Jan 27 1993
293 set_current_module(
294 find_module(((ptr_psi_term)get_attr(input_state,
295 CURRENT_MODULE))->value_3));
296 */
297 }
LINE_COUNT
#define LINE_COUNT
Definition: def_const.h:227
eof_flag
long eof_flag
Definition: def_glob.h:196
start_of_line
long start_of_line
Definition: def_glob.h:191
input_file_name
string input_file_name
Definition: def_glob.h:40
SAVED_PSI_TERM
#define SAVED_PSI_TERM
Definition: def_const.h:231
OLD_SAVED_CHAR
#define OLD_SAVED_CHAR
Definition: def_const.h:230
null_psi_term
ptr_psi_term null_psi_term
Definition: def_glob.h:140
wl_psi_term
Definition: def_struct.h:161
old_saved_char
long old_saved_char
Definition: def_glob.h:193
NULL
#define NULL
Definition: def_const.h:203
saved_char
long saved_char
Definition: def_glob.h:192
REAL
#define REAL
Definition: def_const.h:72
line_count
long line_count
Definition: def_glob.h:39
STREAM
#define STREAM
Definition: def_const.h:225
START_OF_LINE
#define START_OF_LINE
Definition: def_const.h:228
lf_true
ptr_definition lf_true
Definition: def_glob.h:107
input_stream
FILE * input_stream
Definition: def_glob.h:38
INPUT_FILE_NAME
#define INPUT_FILE_NAME
Definition: def_const.h:226
OLD_SAVED_PSI_TERM
#define OLD_SAVED_PSI_TERM
Definition: def_const.h:232
get_attr
GENERIC get_attr(ptr_psi_term t, char *attrname)
Definition: token.c:210
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
EOF_FLAG
#define EOF_FLAG
Definition: def_const.h:233
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
SAVED_CHAR
#define SAVED_CHAR
Definition: def_const.h:229
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

void save_parse_state | ( | ptr_parse_block | pb | ) |

Definition at line 350 of file token.c.

References eof_flag, wl_parse_block::lc, line_count, old_saved_char, old_saved_psi_term, saved_char, saved_psi_term, and start_of_line.

352 {
353 if (pb) {
354 pb->lc = line_count;
355 pb->sol = start_of_line;
356 pb->sc = saved_char;
357 pb->osc = old_saved_char;
358 pb->spt = saved_psi_term;
359 pb->ospt = old_saved_psi_term;
360 pb->ef = eof_flag;
361 }
362 }
wl_parse_block::ospt
ptr_psi_term ospt
Definition: def_struct.h:377
eof_flag
long eof_flag
Definition: def_glob.h:196
wl_parse_block::sol
long sol
Definition: def_struct.h:373
start_of_line
long start_of_line
Definition: def_glob.h:191
wl_parse_block::osc
long osc
Definition: def_struct.h:375
old_saved_char
long old_saved_char
Definition: def_glob.h:193
saved_char
long saved_char
Definition: def_glob.h:192
line_count
long line_count
Definition: def_glob.h:39
wl_parse_block::lc
long lc
Definition: def_struct.h:372
wl_parse_block::ef
long ef
Definition: def_struct.h:378
wl_parse_block::sc
long sc
Definition: def_struct.h:374
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
wl_parse_block::spt
ptr_psi_term spt
Definition: def_struct.h:376
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

void save_state | ( | ptr_psi_term | t | ) |

Definition at line 230 of file token.c.

References wl_node::data, eof_flag, EOF_FLAG, FEATCMP, find(), heap_add_psi_attr(), heap_mod_int_attr(), heap_mod_str_attr(), heap_psi_term(), input_file_name, INPUT_FILE_NAME, input_stream, lf_false, lf_true, line_count, LINE_COUNT, null_psi_term, old_saved_char, OLD_SAVED_CHAR, old_saved_psi_term, OLD_SAVED_PSI_TERM, saved_char, SAVED_CHAR, saved_psi_term, SAVED_PSI_TERM, start_of_line, START_OF_LINE, STREAM, wl_psi_term::type, and wl_psi_term::value_3.

232 {
233 ptr_node n;
234 ptr_psi_term t1;
235
236 n=find(FEATCMP,STREAM,t->attr_list);
237 t1=(ptr_psi_term)n->data;
238 t1->value_3=(GENERIC)input_stream;
239
240 /* RM: Jan 27 1993
241 heap_mod_str_attr(t,CURRENT_MODULE,current_module->module_name);
242 */
243
244 heap_mod_str_attr(t,INPUT_FILE_NAME,input_file_name);
245 heap_mod_int_attr(t,LINE_COUNT,line_count);
246 heap_mod_int_attr(t,SAVED_CHAR,saved_char);
247 heap_mod_int_attr(t,OLD_SAVED_CHAR,old_saved_char);
248
249 t1=saved_psi_term?saved_psi_term:null_psi_term;
250 heap_add_psi_attr(t,SAVED_PSI_TERM,t1);
251
252 t1=old_saved_psi_term?old_saved_psi_term:null_psi_term;
253 heap_add_psi_attr(t,OLD_SAVED_PSI_TERM,t1);
254
255 t1=heap_psi_term(4);
256 t1->type=(eof_flag?lf_true:lf_false);
257 heap_add_psi_attr(t,EOF_FLAG,t1);
258
259 t1=heap_psi_term(4);
260 t1->type=(start_of_line?lf_true:lf_false);
261 heap_add_psi_attr(t,START_OF_LINE,t1);
262 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
LINE_COUNT
#define LINE_COUNT
Definition: def_const.h:227
eof_flag
long eof_flag
Definition: def_glob.h:196
start_of_line
long start_of_line
Definition: def_glob.h:191
heap_mod_int_attr
void heap_mod_int_attr(ptr_psi_term t, char *attrname, long value)
Definition: token.c:91
input_file_name
string input_file_name
Definition: def_glob.h:40
SAVED_PSI_TERM
#define SAVED_PSI_TERM
Definition: def_const.h:231
heap_psi_term
ptr_psi_term heap_psi_term(long stat)
Definition: lefun.c:63
OLD_SAVED_CHAR
#define OLD_SAVED_CHAR
Definition: def_const.h:230
null_psi_term
ptr_psi_term null_psi_term
Definition: def_glob.h:140
wl_psi_term
Definition: def_struct.h:161
wl_node::data
GENERIC data
Definition: def_struct.h:185
old_saved_char
long old_saved_char
Definition: def_glob.h:193
saved_char
long saved_char
Definition: def_glob.h:192
line_count
long line_count
Definition: def_glob.h:39
STREAM
#define STREAM
Definition: def_const.h:225
START_OF_LINE
#define START_OF_LINE
Definition: def_const.h:228
heap_add_psi_attr
void heap_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
Definition: token.c:184
lf_true
ptr_definition lf_true
Definition: def_glob.h:107
input_stream
FILE * input_stream
Definition: def_glob.h:38
lf_false
ptr_definition lf_false
Definition: def_glob.h:89
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
INPUT_FILE_NAME
#define INPUT_FILE_NAME
Definition: def_const.h:226
OLD_SAVED_PSI_TERM
#define OLD_SAVED_PSI_TERM
Definition: def_const.h:232
find
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
EOF_FLAG
#define EOF_FLAG
Definition: def_const.h:233
ptr_psi_term
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
heap_mod_str_attr
void heap_mod_str_attr(ptr_psi_term t, char *attrname, char *str)
Definition: token.c:153
wl_node
Definition: def_struct.h:181
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
SAVED_CHAR
#define SAVED_CHAR
Definition: def_const.h:229
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

void stack_add_int_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | long | value
| ) |  |

Definition at line 73 of file token.c.

References FEATCMP, heap_alloc(), heap_copy_string(), integer, REAL, stack_insert(), stack_psi_term(), wl_psi_term::type, and wl_psi_term::value_3.

77 {
78 ptr_psi_term t1;
79
80 t1=stack_psi_term(4);
81 t1->type=integer;
82 t1->value_3=heap_alloc(sizeof(REAL)); /* 12.5 */
83 *(REAL *)t1->value_3 = (REAL) value;
84
85 (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
86 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
wl_psi_term
Definition: def_struct.h:161
REAL
#define REAL
Definition: def_const.h:72
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
stack_insert
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:291
integer
ptr_definition integer
Definition: def_glob.h:93
stack_psi_term
ptr_psi_term stack_psi_term(long stat)
Definition: lefun.c:15
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171
heap_alloc
GENERIC heap_alloc(long s)
Definition: memory.c:1518

void stack_add_psi_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | ptr_psi_term | g
| ) |  |

Definition at line 192 of file token.c.

References FEATCMP, heap_copy_string(), and stack_insert().

196 {
197 (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) g);
198 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
stack_insert
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:291
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void stack_add_str_attr | ( | ptr_psi_term | t,
|  | char * | attrname,
|  | char * | str
| ) |  |

Definition at line 136 of file token.c.

References FEATCMP, heap_copy_string(), quoted_string, stack_copy_string(), stack_insert(), stack_psi_term(), wl_psi_term::type, and wl_psi_term::value_3.

140 {
141 ptr_psi_term t1;
142
143 t1=stack_psi_term(4);
144 t1->type=quoted_string;
145 t1->value_3=(GENERIC)stack_copy_string(str);
146
147 (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
148 }
FEATCMP
#define FEATCMP
Definition: def_const.h:257
stack_copy_string
char * stack_copy_string(char *s)
Definition: trees.c:155
wl_psi_term
Definition: def_struct.h:161
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
stack_insert
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
Definition: trees.c:291
quoted_string
ptr_definition quoted_string
Definition: def_glob.h:101
stack_psi_term
ptr_psi_term stack_psi_term(long stat)
Definition: lefun.c:15
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:170
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:171

void stdin_cleareof | ( |  | ) |

Definition at line 42 of file token.c.

References eof_flag, FALSE, NULL, old_saved_char, old_saved_psi_term, saved_char, saved_psi_term, start_of_line, stdin_terminal, and TRUE.

43 {
44 if (eof_flag && stdin_terminal) {
45 clearerr(stdin);
46 start_of_line=TRUE;
47 saved_psi_term=NULL;
48 old_saved_psi_term=NULL;
49 saved_char=0;
50 old_saved_char=0;
51 eof_flag=FALSE;
52 }
53 }
stdin_terminal
long stdin_terminal
Definition: def_glob.h:188
eof_flag
long eof_flag
Definition: def_glob.h:196
start_of_line
long start_of_line
Definition: def_glob.h:191
old_saved_char
long old_saved_char
Definition: def_glob.h:193
NULL
#define NULL
Definition: def_const.h:203
saved_char
long saved_char
Definition: def_glob.h:192
TRUE
#define TRUE
Definition: def_const.h:127
FALSE
#define FALSE
Definition: def_const.h:128
saved_psi_term
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
old_saved_psi_term
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195

long symbolic | ( | long | c | ) |

Definition at line 850 of file token.c.

References SYMBOL.

852 {
853 return SYMBOL(c);
854 }
SYMBOL
#define SYMBOL(C)
Definition: def_macro.h:52

void TOKEN_ERROR | ( | ptr_psi_term | p | ) |

Definition at line 30 of file token.c.

References error_psi_term, Syntaxerrorline(), and wl_psi_term::type.

33 {
34 if(p->type==error_psi_term->type) {
35 Syntaxerrorline("Module violation (%E).\n");
36 }
37 }
Syntaxerrorline
void Syntaxerrorline(char *format,...)
Definition: error.c:498
error_psi_term
ptr_psi_term error_psi_term
Definition: def_glob.h:23
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165

## Variable Documentation

long inchange
| static

Definition at line 397 of file token.c.

ptr_psi_term old_state =NULL

Definition at line 399 of file token.c.

FILE* out
| static

Definition at line 398 of file token.c.

long outchange
| static

Definition at line 397 of file token.c.

long trace_input =FALSE

Definition at line 8 of file token.c.