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

token More...

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

Variables

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

Detailed Description

token

Definition in file token.c.

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 847 of file token.c.

Function Documentation

int base2int ( int  n)

base2int

Parameters
n- int n

Definition at line 816 of file token.c.

817 {
818  switch (n) {
819  case '0': return 0;
820  case '1': return 1;
821  case '2': return 2;
822  case '3': return 3;
823  case '4': return 4;
824  case '5': return 5;
825  case '6': return 6;
826  case '7': return 7;
827  case '8': return 8;
828  case '9': return 9;
829  case 'a':
830  case 'A': return 10;
831  case 'b':
832  case 'B': return 11;
833  case 'c':
834  case 'C': return 12;
835  case 'd':
836  case 'D': return 13;
837  case 'e':
838  case 'E': return 14;
839  case 'f':
840  case 'F': return 15;
841  default:
842  fprintf(stderr,"base2int('%c'): illegal argument\n",n);
843  exit(EXIT_FAILURE);
844  }
845 }
void begin_terminal_io ( )

begin_terminal_io

BEGIN_TERMINAL_IO() These two routines must bracket any I/O directed to the terminal. This is to avoid mix-ups between terminal and file I/O since the program's input and output streams may be different from stdin stdout. See the routine what_next_aim(), which uses them to isolate the user interface I/O from the program's own I/O.

Definition at line 493 of file token.c.

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

494 {
495  inchange = (input_stream!=stdin);
496  outchange = (output_stream!=stdout);
497 
498  if (outchange) {
500  output_stream=stdout;
501  }
502 
503  if (inchange) {
505  (void)open_input_file("stdin");
506  }
507 }
ptr_psi_term input_state
Definition: def_glob.h:856
ptr_psi_term old_state
Definition: token.c:480
static long outchange
Definition: token.c:478
FILE * input_stream
Definition: def_glob.h:1014
static long inchange
Definition: token.c:478
static FILE * out
Definition: token.c:479
FILE * output_stream
Definition: def_glob.h:1017
long open_input_file(char *file)
open_input_file
Definition: token.c:594
void bk_stack_add_psi_attr ( ptr_psi_term  t,
char *  attrname,
ptr_psi_term  g 
)

bk_stack_add_psi_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
g- ptr_psi_term g

Definition at line 252 of file token.c.

References wl_psi_term::attr_list, bk_stack_insert(), FEATCMP, and heap_copy_string().

253 {
254  (void)bk_stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list), (GENERIC)g);
255 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
bk_stack_insert
Definition: trees.c:357
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
ptr_node attr_list
Definition: def_struct.h:187
void end_terminal_io ( )

end_terminal_io

END_TERMINAL_IO() End of terminal I/O bracketing.

Definition at line 516 of file token.c.

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

517 {
518  if (inchange) {
521  old_state=NULL; /* RM: Feb 17 1993 */
522  }
523  if (outchange)
525 }
#define NULL
Definition: def_const.h:533
ptr_psi_term input_state
Definition: def_glob.h:856
ptr_psi_term old_state
Definition: token.c:480
static long outchange
Definition: token.c:478
void restore_state(ptr_psi_term t)
restore_state
Definition: token.c:334
static long inchange
Definition: token.c:478
static FILE * out
Definition: token.c:479
FILE * output_stream
Definition: def_glob.h:1017
char* expand_file_name ( char *  s)

expand_file_name

Parameters
s- char *s

EXPAND_FILE_NAME(str) Return the expansion of file name STR. For the time being all this does is replace '~' by the HOME directory if no user is given, or tries to find the user.

Definition at line 537 of file token.c.

References STRLEN.

538 {
539  char *r;
540  char *home; // *getenv();
541  struct passwd *pw;
542  /* char *user="eight character name"; 18.5 */
543  char userbuf[STRLEN];
544  char *user=userbuf;
545  char *t1,*t2;
546 
547  r=s;
548  if (s[0]=='~') {
549  t1=s+1;
550  t2=user;
551  while (*t1!=0 && *t1!='/') {
552  *t2= *t1;
553  *t2++;
554  *t1++;
555  }
556  *t2=0;
557  if ((int)strlen(user)>0) {
558  pw = getpwnam(user);
559  if (pw) {
560  user=pw->pw_dir;
561  r=(char *)malloc(strlen(user)+strlen(t1)+1);
562  sprintf(r,"%s%s",user,t1);
563  }
564  else
565  /* if (warning()) printf("couldn't find user '%s'.\n",user) */;
566  }
567  else {
568  home=getenv("HOME");
569  if (home) {
570  r=(char *)malloc(strlen(home)+strlen(s)+1);
571  sprintf(r,"%s%s",home,s+1);
572  }
573  else
574  /* if (warning()) printf("no HOME directory.\n") */;
575  }
576  }
577 
578  /* printf("*** Using file name: '%s'\n",r); */
579 
580  return r;
581 }
#define STRLEN
Maximum size of file names and input tokens (which includes input strings) (Note: calculated tokens c...
Definition: def_const.h:162
GENERIC get_attr ( ptr_psi_term  t,
char *  attrname 
)

get_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname

Get the GENERIC value of a psi-term's attribute

Definition at line 265 of file token.c.

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

266 {
267  ptr_node n=find(FEATCMP,attrname,t->attr_list);
268  return n->data;
269 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
GENERIC data
Definition: def_struct.h:201
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_node attr_list
Definition: def_struct.h:187
FILE* get_stream ( ptr_psi_term  t)

get_stream

Parameters
t- ptr_psi_term t

Get the psi-term's STREAM attribute

Definition at line 278 of file token.c.

References get_attr(), and STREAM.

279 {
280  return (FILE *) ((ptr_psi_term)get_attr(t,STREAM))->value_3;
281 }
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define STREAM
feature name
Definition: def_const.h:876
GENERIC get_attr(ptr_psi_term t, char *attrname)
get_attr
Definition: token.c:265
void heap_add_int_attr ( ptr_psi_term  t,
char *  attrname,
long  value 
)

heap_add_int_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
value- long value

Add an attribute whose value is an integer to a psi-term that does not yet contains this attribute.

Definition at line 74 of file token.c.

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

75 {
76  ptr_psi_term t1;
77 
78  t1=heap_psi_term(4);
79  t1->type=integer;
80  t1->value_3=heap_alloc(sizeof(REAL));
81  *(REAL *)t1->value_3 = (REAL) value;
82 
83  (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list), (GENERIC)t1);
84 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
ptr_psi_term heap_psi_term(long stat)
heap_psi_term
Definition: lefun.c:75
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
heap_insert
Definition: trees.c:320
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
void heap_add_psi_attr ( ptr_psi_term  t,
char *  attrname,
ptr_psi_term  g 
)

heap_add_psi_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
g- ptr_psi_term g

Attach a psi-term to another as an attribute.

Definition at line 226 of file token.c.

References wl_psi_term::attr_list, FEATCMP, heap_copy_string(), and heap_insert().

227 {
228  (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) g);
229 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
heap_insert
Definition: trees.c:320
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
ptr_node attr_list
Definition: def_struct.h:187
void heap_add_str_attr ( ptr_psi_term  t,
char *  attrname,
char *  str 
)

heap_add_str_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
str- char *str

Add an attribute whose value is a string to a psi-term that does not yet contains this attribute.

Definition at line 151 of file token.c.

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

152 {
153  ptr_psi_term t1;
154 
155  t1=heap_psi_term(4);
156  t1->type=quoted_string;
157  t1->value_3=(GENERIC)heap_copy_string(str);
158 
159  (void)heap_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
160 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_psi_term heap_psi_term(long stat)
heap_psi_term
Definition: lefun.c:75
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
heap_insert
Definition: trees.c:320
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
void heap_mod_int_attr ( ptr_psi_term  t,
char *  attrname,
long  value 
)

heap_mod_int_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
value- long value

Modify an attribute whose value is an integer to a psi-term that already contains this attribute with another integer value.

Definition at line 116 of file token.c.

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

117 {
118  ptr_node n;
119  ptr_psi_term t1;
120 
121  n=find(FEATCMP,attrname,t->attr_list);
122  t1=(ptr_psi_term)n->data;
123  *(REAL *)t1->value_3 = (REAL) value;
124 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
GENERIC value_3
Definition: def_struct.h:186
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_node attr_list
Definition: def_struct.h:187
void heap_mod_str_attr ( ptr_psi_term  t,
char *  attrname,
char *  str 
)

heap_mod_str_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
str- char *str

Modify an attribute whose value is a string to a psi-term that already contains this attribute with another integer value.

Definition at line 191 of file token.c.

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

192 {
193  ptr_node n;
194  ptr_psi_term t1;
195 
196  n=find(FEATCMP,attrname,t->attr_list);
197  t1=(ptr_psi_term)n->data;
198  t1->value_3=(GENERIC)heap_copy_string(str);
199 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
GENERIC value_3
Definition: def_struct.h:186
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_node attr_list
Definition: def_struct.h:187
void init_parse_state ( )

init_parse_state

Initialize the parser/tokenizer state variables.

Definition at line 464 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.

465 {
466  line_count=0;
468  saved_char=0;
469  old_saved_char=0;
472  eof_flag=FALSE;
474 }
long eof_flag
Definition: def_glob.h:853
long old_saved_char
Definition: def_glob.h:850
#define NULL
Definition: def_const.h:533
long saved_char
Definition: def_glob.h:849
long line_count
Definition: def_glob.h:1015
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
long start_of_line
???
Definition: def_glob.h:846
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
long stringparse
Definition: def_glob.h:859
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
long legal_in_name ( long  c)

legal_in_name

Parameters
c- long c

LEGAL_IN_NAME(character) Tests if character is legal in a name or a variable (see macros).

Definition at line 980 of file token.c.

References DIGIT, LOWER, and UPPER.

981 {
982  return
983  UPPER(c) ||
984  LOWER(c) ||
985  DIGIT(c);
986 
987  /* || c=='\'' RM: Dec 16 1992 */ ;
988 }
#define UPPER(C)
Definition: def_macro.h:44
#define DIGIT(C)
Definition: def_macro.h:42
#define LOWER(C)
Definition: def_macro.h:46
void new_state ( ptr_psi_term t)

new_state

Parameters
t- ptr_psi_term *t

Create a new file state psi-term that reflects the current global state

Definition at line 372 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.

373 {
374  ptr_psi_term t1;
375 
376  *t=heap_psi_term(4);
377  (*t)->type=inputfilesym;
378 
379  t1=heap_psi_term(4);
380  t1->type=stream;
382  heap_add_psi_attr(*t,STREAM,t1);
383 
384  /* RM: Jan 27 1993 */
386 
387  /*
388  printf("Creating new state for file '%s', module '%s'\n",
389  input_file_name,
390  current_module->module_name);
391  */
392 
397 
400 
403 
404  t1=heap_psi_term(4);
407 
408  t1=heap_psi_term(4);
411 }
#define LINE_COUNT
feature name
Definition: def_const.h:890
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
long eof_flag
Definition: def_glob.h:853
string input_file_name
Definition: def_glob.h:1016
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
#define SAVED_PSI_TERM
feature name
Definition: def_const.h:918
ptr_psi_term heap_psi_term(long stat)
heap_psi_term
Definition: lefun.c:75
#define OLD_SAVED_CHAR
feature name
Definition: def_const.h:911
#define CURRENT_MODULE
feature name
Definition: def_const.h:939
ptr_definition stream
symbol in bi module
Definition: def_glob.h:382
long old_saved_char
Definition: def_glob.h:850
long saved_char
Definition: def_glob.h:849
ptr_psi_term null_psi_term
Used to represent an empty parse token.
Definition: def_glob.h:656
ptr_definition inputfilesym
symbol in bi module
Definition: def_glob.h:501
long line_count
Definition: def_glob.h:1015
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define STREAM
feature name
Definition: def_const.h:876
#define START_OF_LINE
feature name
Definition: def_const.h:897
void heap_add_str_attr(ptr_psi_term t, char *attrname, char *str)
heap_add_str_attr
Definition: token.c:151
void heap_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
heap_add_psi_attr
Definition: token.c:226
FILE * input_stream
Definition: def_glob.h:1014
GENERIC value_3
Definition: def_struct.h:186
long start_of_line
???
Definition: def_glob.h:846
#define INPUT_FILE_NAME
feature name
Definition: def_const.h:883
char * module_name
Definition: def_struct.h:106
#define OLD_SAVED_PSI_TERM
feature name
Definition: def_const.h:925
void heap_add_int_attr(ptr_psi_term t, char *attrname, long value)
heap_add_int_attr
Definition: token.c:74
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
#define EOF_FLAG
feature name
Definition: def_const.h:932
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
#define SAVED_CHAR
feature name
Definition: def_const.h:904
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
long open_input_file ( char *  file)

open_input_file

Parameters
file- char *file

OPEN_INPUT_FILE(file) Open the input file specified by the string FILE. If the file is "stdin", restore the stdin state. Otherwise, open the file and create a new global state for it. If the file can't be opened, print an error and open "stdin" instead.

Definition at line 594 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.

595 {
596  long ok=TRUE;
597  long stdin_flag;
598 
599  /* Save global input file state */
601 
602  file=expand_file_name(file);
603 
604  if ((stdin_flag=(!strcmp(file,"stdin")))) {
605  input_stream=stdin;
606  noisy=TRUE;
607  }
608  else {
609  input_stream=fopen(file,"r");
610  noisy=FALSE;
611  }
612 
613  if (input_stream==NULL) {
614  Errorline("file '%s' does not exist.\n",file);
615  file="stdin";
616  input_stream=stdin;
617  noisy=TRUE;
618  ok=FALSE;
619  }
620 
621  if (!stdin_flag || stdin_state==NULL) {
622  /* Initialize a new global input file state */
623  strcpy(input_file_name,file);
625  /* Create a new state containing the new global values */
627  if (stdin_flag) stdin_state=input_state;
628  }
629  else {
632  }
633 
634  return ok;
635 }
void init_parse_state()
init_parse_state
Definition: token.c:464
ptr_psi_term stdin_state
Definition: def_glob.h:857
string input_file_name
Definition: def_glob.h:1016
void save_state(ptr_psi_term t)
save_state
Definition: token.c:293
#define NULL
Definition: def_const.h:533
ptr_psi_term input_state
Definition: def_glob.h:856
long noisy
Definition: def_glob.h:1011
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
void restore_state(ptr_psi_term t)
restore_state
Definition: token.c:334
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
FILE * input_stream
Definition: def_glob.h:1014
char * expand_file_name(char *s)
expand_file_name
Definition: token.c:537
void new_state(ptr_psi_term *t)
new_state
Definition: token.c:372
long open_output_file ( string  file)

open_output_file

Parameters
file- string file

OPEN_OUTPUT_FILE(file) Same thing as OPEN_INPUT_FILE, only for output. If FILE="stdout" then output_stream=stdout.

Definition at line 646 of file token.c.

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

647 {
648  long ok=TRUE;
649 
650 
651  file=expand_file_name(file);
652 
653  if (!strcmp(file,"stdout"))
654  output_stream=stdout;
655  else
656  if (!strcmp(file,"stderr"))
657  output_stream=stderr;
658  else
659  output_stream=fopen(file,"w");
660 
661  if (output_stream==NULL) {
662  Errorline("file '%s' could not be opened for output.\n",file);
663  ok=FALSE;
664  output_stream=stdout;
665  }
666 
667  return ok;
668 }
#define NULL
Definition: def_const.h:533
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
char * expand_file_name(char *s)
expand_file_name
Definition: token.c:537
FILE * output_stream
Definition: def_glob.h:1017
void psi_term_error ( )

psi_term_error

PSI_TERM_ERROR Print the line number at which the current psi_term started.

Definition at line 761 of file token.c.

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

762 {
763  perr_i("near line %ld",psi_term_line_number);
764  if (strcmp(input_file_name,"stdin")) {
765  perr_s(" in file \042%s\042",input_file_name);
766  }
767  /* prompt="error>"; 20.8 */
768  parse_ok=FALSE;
769 }
long psi_term_line_number
Definition: def_glob.h:909
string input_file_name
Definition: def_glob.h:1016
void perr_s(char *s1, char *s2)
perr_s
Definition: error.c:775
long parse_ok
indicates whether there was a syntax error
Definition: def_glob.h:765
#define FALSE
Standard boolean.
Definition: def_const.h:275
void perr_i(char *str, long i)
perr_i
Definition: error.c:800
void put_back_char ( long  c)

put_back_char

Parameters
c- long c

PUT_BACK_CHAR Put back one character, if there already are 2 saved characters then report an error (= bug).

Definition at line 729 of file token.c.

References Errorline(), old_saved_char, and saved_char.

730 {
731  if (old_saved_char)
732  Errorline("in tokenizer, put_back_char three times (last=%d).\n",c);
734  saved_char=c;
735 }
long old_saved_char
Definition: def_glob.h:850
long saved_char
Definition: def_glob.h:849
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
void put_back_token ( psi_term  t)

put_back_token

Parameters
t- psi_term t

PUT_BACK_TOKEN Put back a psi_term, if there already are two saved then report an error (= bug).

Definition at line 746 of file token.c.

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

747 {
749  Errorline("in parser, put_back_token three times (last=%P).\n",t);
752 }
#define NULL
Definition: def_const.h:533
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
ptr_psi_term stack_copy_psi_term(psi_term t)
stack_copy_psi_term
Definition: parser.c:205
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
long read_char ( )

read_char

READ_CHAR Return the char read from the input stream, if end of file reached then return EOF. If stringparse==TRUE then read characters from the input string instead of from a file.

Definition at line 680 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.

681 {
682  int c=0;
683 
684  if ((c=saved_char)) {
686  old_saved_char=0;
687  }
688  else if (stringparse) {
689  if ((c=(*stringinput)))
690  stringinput++;
691  else
692  c=EOF;
693  }
694  else if (input_stream == NULL || feof(input_stream))
695  c=EOF;
696  else {
697  if (start_of_line) {
699  line_count++;
700  if (input_stream==stdin) infoline("%s",prompt); /* 21.1 */
701  }
702 
703  c=fgetc(input_stream);
704 
705  if(trace_input) /* RM: Jan 13 1993 */
706  if(c!=EOF)
707  printf("%c",c);
708  else
709  printf(" <EOF>\n");
710 
711  if (c==EOLN)
713  }
714 
715  /* printf("%c\n",c); RM: Jan 5 1993 Just to trace the parser */
716 
717  return c;
718 }
long old_saved_char
Definition: def_glob.h:850
#define NULL
Definition: def_const.h:533
long saved_char
Definition: def_glob.h:849
long trace_input
Definition: token.c:12
long line_count
Definition: def_glob.h:1015
#define EOLN
End of line.
Definition: def_const.h:309
void infoline(char *format,...)
infoline
Definition: error.c:281
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
FILE * input_stream
Definition: def_glob.h:1014
long start_of_line
???
Definition: def_glob.h:846
char * prompt
Definition: def_glob.h:1018
long stringparse
Definition: def_glob.h:859
char * stringinput
Definition: def_glob.h:860
void read_comment ( ptr_psi_term  tok)

read_comment

Parameters
tok- ptr_psi_term tok

READ_COMMENT Read a comment starting with '' to the end of the line.

Definition at line 779 of file token.c.

References comment, EOLN, read_char(), and wl_psi_term::type.

780 {
781  long c;
782 
783  do {
784  c=read_char();
785  } while (c!=EOF && c!=EOLN);
786 
787  tok->type=comment;
788 }
ptr_definition comment
symbol in bi module
Definition: def_glob.h:227
#define EOLN
End of line.
Definition: def_const.h:309
ptr_definition type
Definition: def_struct.h:181
long read_char()
read_char
Definition: token.c:680
void read_name ( ptr_psi_term  tok,
long  ch,
long(*)(long)  f,
ptr_definition  typ 
)

read_name

Parameters
tok- ptr_psi_term tok
ch- long ch
f- long (*f)(long)
typ- ptr_definition typ

READ_NAME(C,F,TYP) Read in the name starting with character C followed by character of whose type function is F. The result is a psi_term of symbol type TYP.

Definition at line 1002 of file token.c.

References wl_psi_term::attr_list, bk2_stack_insert(), constant, wl_psi_term::coref, create_module(), FALSE, find(), global_it, wl_definition::global_value, heap_copy_string(), wl_definition::keyword, legal_in_name(), wl_module::module_name, NULL, put_back_char(), read_char(), wl_psi_term::resid, STRCMP, STRLEN, SYMBOL, wl_keyword::symbol, symbolic(), TOKEN_ERROR(), TRUE, wl_psi_term::type, wl_definition::type_def, update_symbol(), wl_psi_term::value_3, var_occurred, var_tree, and warningline().

1003 {
1004  char c;
1005  string str;
1006  long len=1;
1007  long store=TRUE;
1008  long flag=TRUE;
1009  ptr_module module=NULL;
1010  ptr_node n; /* RM: Feb 9 1993 */
1011 
1012  tok->coref=NULL;
1013  tok->resid=NULL;
1014  tok->attr_list=NULL;
1015 
1016  str[0]=ch;
1017 
1018  do {
1019  c=read_char();
1020  flag=(*f)(c);
1021 
1022  if(c=='#' && /* RM: Feb 3 1993 */
1023  (long)f==(long)legal_in_name &&
1024  len>0 &&
1025  len<STRLEN &&
1026  !module) {
1027  str[len]=0;
1028  module=create_module(str);
1029  len=0;
1030  flag=TRUE;
1031 
1032  /* RM: Sep 21 1993 */
1033  /* Change the type function if required */
1034  c=read_char();
1035  if SYMBOL(c)
1036  f=symbolic;
1037  put_back_char(c);
1038  }
1039  else
1040  if (flag) {
1041  if (store)
1042  if (len==STRLEN) {
1043  warningline("name too long, extra ignored (%E).\n");
1044  store=FALSE;
1045  }
1046  else
1047  str[len++]=c;
1048  }
1049  else
1050  put_back_char(c);
1051  } while(flag);
1052 
1053  if(module && len==0) { /* RM: Feb 3 1993 */
1054  strcpy(str,module->module_name);
1055  len=strlen(str);
1056  put_back_char('#');
1057  module=NULL;
1058  }
1059 
1060  str[len]=0;
1061 
1062  tok->type=typ;
1063 
1064  if(typ==constant) {
1065  /* printf("module=%s\n",module->module_name); */
1066  tok->type=update_symbol(module,str); /* RM: Feb 3 1993 */
1067  tok->value_3=NULL;
1068 
1069  TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
1070 
1071  /* PVR 4.2.94 for correct level incrementing */
1072  if (tok->type->type_def==(def_type)global_it) {
1074  }
1075  if (FALSE /*tok->type->type==global_it && tok->type->global_value*/) {
1076  /* RM: Nov 10 1993 */
1077 
1078  /* Remove this for Bruno who didn't like it, and doesn't like
1079  to use "print_depth" */
1080 
1081  /* RM: Feb 9 1993 */
1082  /* Add into the variable tree */
1084  n=find(STRCMP,tok->type->keyword->symbol,var_tree);
1085  if (n==NULL) {
1086  /* The change is always trailed. */
1087  (void)bk2_stack_insert(STRCMP,
1088  tok->type->keyword->symbol,
1089  &var_tree,
1090  (GENERIC)tok->type->global_value);
1091  }
1092  }
1093 
1094  }
1095  else
1096  tok->value_3=(GENERIC)heap_copy_string(str);
1097 }
ptr_residuation resid
Definition: def_struct.h:189
ptr_module create_module(char *module)
ptr_module create_module(char *module)
Definition: modules.c:72
def_type type_def
Definition: def_struct.h:153
ptr_keyword keyword
Definition: def_struct.h:147
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:1005
ptr_node bk2_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
bk2_stack_insert
Definition: trees.c:377
char * symbol
Definition: def_struct.h:118
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
#define SYMBOL(C)
Definition: def_macro.h:57
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define STRCMP
indicates to use strcmp for comparison (c function)
Definition: def_const.h:963
ptr_definition constant
symbol in bi module
Definition: def_glob.h:235
ptr_psi_term global_value
Definition: def_struct.h:159
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
char * module_name
Definition: def_struct.h:106
ptr_psi_term coref
Definition: def_struct.h:188
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
long legal_in_name(long c)
legal_in_name
Definition: token.c:980
long symbolic(long c)
symbolic
Definition: token.c:967
#define STRLEN
Maximum size of file names and input tokens (which includes input strings) (Note: calculated tokens c...
Definition: def_const.h:162
void TOKEN_ERROR(ptr_psi_term p)
TOKEN_ERROR.
Definition: token.c:38
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
long read_char()
read_char
Definition: token.c:680
long var_occurred
???
Definition: def_glob.h:839
ptr_node attr_list
Definition: def_struct.h:187
void put_back_char(long c)
put_back_char
Definition: token.c:729
void read_number ( ptr_psi_term  tok,
long  c 
)

read_number

Parameters
tok- ptr_psi_term tok
c- long c

READ_NUMBER(c) Read in the number whose first character is c. Accepted syntax: digit+ [ . digit+ ] [ {e|E} {+|-|empty} digit* ] Negative numbers are dealt with in the parser.

Definition at line 1110 of file token.c.

References DIGIT, heap_alloc(), integer, put_back_char(), read_char(), REAL, real, wl_psi_term::type, and wl_psi_term::value_3.

1111 {
1112  long c2;
1113  REAL f,p;
1114  long /* sgn, */ pwr,posflag;
1115 
1116  /* if (sgn=(c=='-')) c=read_char(); */
1117 
1118  /* tok->type=integer; RM: Mar 8 1993 */
1119 
1120  f=0.0;
1121  do { f=f*10.0+(c-'0'); c=read_char(); } while (DIGIT(c));
1122 
1123  if (c=='.') {
1124  c2=read_char();
1125  if DIGIT(c2) {
1126  /* tok->type=real; RM: Mar 8 1993 */
1127  p=10.0;
1128  while (DIGIT(c2)) { f=f+(c2-'0')/p; p=p*10.0; c2=read_char(); }
1129  put_back_char(c2);
1130  }
1131  else {
1132  put_back_char(c2);
1133  put_back_char(c);
1134  }
1135  }
1136  else
1137  put_back_char(c);
1138 
1139  c=read_char();
1140  if (c=='e' || c=='E') {
1141  c2=read_char();
1142  if (c2=='+' || c2=='-' || DIGIT(c2)) {
1143  tok->type=real;
1144  posflag = (c2=='+' || DIGIT(c2));
1145  if (!DIGIT(c2)) c2=read_char();
1146  pwr=0;
1147  while (DIGIT(c2)) { pwr=pwr*10+(c2-'0'); c2=read_char(); }
1148  put_back_char(c2);
1149  p=1.0;
1150  while (pwr>=100) { pwr-=100; if (posflag) p*=1e100; else p/=1e100; }
1151  while (pwr>=10 ) { pwr-=10; if (posflag) p*=1e10; else p/=1e10; }
1152  while (pwr>0 ) { pwr-=1; if (posflag) p*=1e1; else p/=1e1; }
1153  f*=p;
1154  }
1155  else {
1156  put_back_char(c2);
1157  put_back_char(c);
1158  }
1159  }
1160  else
1161  put_back_char(c);
1162 
1163  /* if (sgn) f = -f; */
1164  tok->value_3=heap_alloc(sizeof(REAL)); /* 12.5 */
1165  *(REAL *)tok->value_3=f;
1166 
1167  /* RM: Mar 8 1993 */
1168  if(f==floor(f))
1169  tok->type=integer;
1170  else
1171  tok->type=real;
1172 }
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
#define DIGIT(C)
Definition: def_macro.h:42
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
long read_char()
read_char
Definition: token.c:680
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
void put_back_char(long c)
put_back_char
Definition: token.c:729
void read_string ( ptr_psi_term  tok,
long  e 
)

read_string

Parameters
tok- ptr_psi_term tok
e- long e

READ_STRING(e) Read a string ending with character E, where E=" or '. Transform a double occurrence into a single one so that 'ab""cd' is the string 'ab"cd'.

Definition at line 859 of file token.c.

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

860 {
861  long c;
862  string str;
863  long len=0;
864  long store=TRUE;
865  long flag=TRUE;
866 
867  str[len]=0;
868 
869  do {
870  c=read_char();
871  if (c==EOF) {
872  store=FALSE;
873  flag=FALSE;
875  }
876  else if (e=='"' && c=='\\') {
877  c=read_char();
878  if (c==EOF) {
879  store=FALSE;
880  flag=FALSE;
881  put_back_char('\\');
883  }
884  else {
885  switch (c) {
886  case 'a': c='\a'; break;
887  case 'b': c='\b'; break;
888  case 'f': c='\f'; break;
889  case 'n': c='\n'; break;
890  case 'r': c='\r'; break;
891  case 't': c='\t'; break;
892  case 'v': c='\v'; break;
893  /* missing \ooo and \xhh */
894  case 'x':
895  {
896  int n;
897  c=read_char();
898  if (c==EOF) {
899  store=flag=FALSE;
901  break;
902  }
903  else if (!isxdigit(c)) {
904  store=flag=FALSE;
906  break;
907  }
908  else {
909  n = base2int(c);
910  }
911  c=read_char();
912  if (isxdigit(c)) n = 16*n+base2int(c);
913  else put_back_char(c);
914  c=n;
915  break;
916  }
917  default:
918  if (isoctal(c)) {
919  int n,i;
920  for(i=n=0;i<3&&isoctal(c);i++,c=read_char())
921  n = n*8 + base2int(c);
922  if (c!=EOF) put_back_char(c);
923  c=n;
924  break;
925  }
926  else break;
927  }
928  }
929  }
930  else
931  if (c==e) {
932  c=read_char();
933  if (c!=e) {
934  store=FALSE;
935  flag=FALSE;
936  put_back_char(c);
937  }
938  }
939  if (store)
940  if (len==STRLEN) {
941  warningline("string too long, extra ignored (%E).\n");
942  store=FALSE;
943  }
944  else {
945  str[len++]=c;
946  str[len]=0;
947  }
948  } while(flag);
949 
950  if (e=='"')
951  tok->value_3=(GENERIC)heap_copy_string(str);
952  else {
953  tok->type=update_symbol(NULL,str); /* Maybe no_module would be better */
954  tok->value_3=NULL;
955  TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
956  }
957 }
int base2int(int n)
base2int
Definition: token.c:816
#define NULL
Definition: def_const.h:533
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
void read_string_error(int n)
read_string_error
Definition: token.c:796
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
#define isoctal(c)
Definition: token.c:847
#define STRLEN
Maximum size of file names and input tokens (which includes input strings) (Note: calculated tokens c...
Definition: def_const.h:162
void TOKEN_ERROR(ptr_psi_term p)
TOKEN_ERROR.
Definition: token.c:38
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
long read_char()
read_char
Definition: token.c:680
void put_back_char(long c)
put_back_char
Definition: token.c:729
void read_string_error ( int  n)

read_string_error

Parameters
n- int n

Definition at line 796 of file token.c.

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

797 {
799  else
800  switch (n) {
801  case 0:
802  Syntaxerrorline("end of file reached before end of string (%E).\n");
803  break;
804  case 1:
805  Syntaxerrorline("Hexadecimal digit expected (%E).\n");
806  break;
807  }
808 }
long parse_ok
indicates whether there was a syntax error
Definition: def_glob.h:765
void Syntaxerrorline(char *format,...)
Syntaxerrorline.
Definition: error.c:557
#define FALSE
Standard boolean.
Definition: def_const.h:275
long stringparse
Definition: def_glob.h:859
void read_token ( ptr_psi_term  tok)

read_token

Parameters
tok- ptr_psi_term tok

READ_TOKEN Read in one token from the input stream, represented as a psi_term. Return the psi_term 'end_of_file' if that is the case.

Used in the parser Set prompt to the 'partial input' prompt

Definition at line 1186 of file token.c.

References read_token_main(), and TRUE.

1187 { read_token_main(tok, TRUE); }
void read_token_main(ptr_psi_term tok, long for_parser)
read_token_main
Definition: token.c:1207
#define TRUE
Standard boolean.
Definition: def_const.h:268
void read_token_b ( ptr_psi_term  tok)

read_token_b

Parameters
tok- ptr_psi_term tok

Used as a built-in Prompt is unchanged

Definition at line 1197 of file token.c.

References FALSE, and read_token_main().

1198 { read_token_main(tok, FALSE); }
void read_token_main(ptr_psi_term tok, long for_parser)
read_token_main
Definition: token.c:1207
#define FALSE
Standard boolean.
Definition: def_const.h:275
void read_token_main ( ptr_psi_term  tok,
long  for_parser 
)

read_token_main

Parameters
tok- ptr_psi_term tok
for_parser- long for_parser

Definition at line 1207 of file token.c.

References wl_psi_term::attr_list, 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(), wl_psi_term::flags, 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(), wl_psi_term::resid, saved_psi_term, SINGLE, stack_psi_term(), wl_psi_term::status, STRCMP, SYMBOL, symbolic(), TOKEN_ERROR(), TRUE, wl_psi_term::type, update_symbol(), UPPER, wl_psi_term::value_3, var_occurred, var_tree, and variable.

1208 {
1209  long c, c2;
1210  ptr_node n;
1211  char p[2];
1212 
1213  if (for_parser && (saved_psi_term!=NULL)) {
1214  *tok= *saved_psi_term;
1217  }
1218  else {
1219  tok->type=nothing;
1220 
1221  do {
1222  c=read_char();
1223  } while(c!=EOF && (c<=32));
1224 
1225  if (for_parser) psi_term_line_number=line_count;
1226 
1227  switch(c) {
1228  case EOF:
1229  tok->type=eof;
1230  tok->value_3=NULL;
1231  break;
1232  case '%':
1233  read_comment(tok);
1234  break;
1235  case '"':
1236  read_string(tok,c);
1237  tok->type=quoted_string;
1238  break;
1239  case 39: /* The quote symbol "'" */
1240  read_string(tok,c);
1241  break;
1242 
1243  default:
1244 
1245  /* Adding this results in problems with terms like (N-1) */
1246  /* if (c=='-' && (c2=read_char()) && DIGIT(c2)) {
1247  put_back_char(c2);
1248  read_number(tok,c);
1249  }
1250  else */
1251 
1252  if(c=='.' || c=='?') { /* RM: Jul 7 1993 */
1253  c2=read_char();
1254  put_back_char(c2);
1255  /*printf("c2=%d\n",c2);*/
1256  if(c2<=' ' || c2==EOF) {
1257  if(c=='.')
1258  tok->type=final_dot;
1259  else
1260  tok->type=final_question;
1261 
1262  tok->value_3=NULL;
1263  }
1264  else
1265  read_name(tok,c,symbolic,constant);
1266  }
1267  else
1268  if DIGIT(c)
1269  read_number(tok,c);
1270  else
1271  if UPPER(c) {
1273  }
1274  else
1275  if LOWER(c) {
1277  }
1278  else
1279  if SYMBOL(c) {
1280  read_name(tok,c,symbolic,constant);
1281  }
1282  else /* RM: Jul 7 1993 Moved this */
1283  if SINGLE(c) {
1284  p[0]=c; p[1]=0;
1286  tok->value_3=NULL;
1287  TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
1288  }
1289  else {
1290  Errorline("illegal character %d in input (%E).\n",c);
1291  }
1292  }
1293 
1294  if (tok->type==variable) {
1295  if (tok->value_3) {
1296  /* If the variable read in has name "_", then it becomes 'top' */
1297  /* and is no longer a variable whose name must be remembered. */
1298  /* As a result, '@' and '_' are synonyms in the program input. */
1299  if (!strcmp((char *)tok->value_3,"_")) {
1300  p[0]='@'; p[1]=0;
1302  tok->value_3=NULL;
1303  TOKEN_ERROR(tok); /* RM: Feb 1 1993 */
1304  }
1305  else {
1306  /* Insert into variable tree, create 'top' value if need be. */
1308  n=find(STRCMP,(char *)tok->value_3,var_tree);
1309  if (n==NULL) {
1311  /* The change is always trailed. */
1312  (void)bk2_stack_insert(STRCMP,(char *)tok->value_3,&var_tree,(GENERIC)t); /* 17.8 */
1313  tok->coref=t;
1314  }
1315  else
1316  tok->coref=(ptr_psi_term)n->data;
1317  }
1318  }
1319  /* else do nothing */
1320  }
1321  }
1322 
1323  if (tok->type==comment)
1324  read_token(tok);
1325 
1326  if (tok->type!=variable)
1327  tok->coref=NULL;
1328 
1329  tok->attr_list=NULL;
1330  tok->status=0;
1331  tok->flags=FALSE; /* 14.9 */
1332  tok->resid=NULL;
1333 
1334  if (tok->type==cut) /* 12.7 */
1336 
1337  do {
1338  c=read_char();
1339  if (c==EOLN) {
1340  if (for_parser) put_back_char(c);
1341  c=0;
1342  }
1343  else if (c<0 || c>32) {
1344  put_back_char(c);
1345  c=0;
1346  }
1347  } while(c && c!=EOF);
1348 
1349  if (for_parser) prompt="| ";
1350 }
ptr_residuation resid
Definition: def_struct.h:189
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
ptr_definition final_question
symbol in syntax module
Definition: def_glob.h:615
#define UPPER(C)
Definition: def_macro.h:44
long psi_term_line_number
Definition: def_glob.h:909
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
ptr_definition comment
symbol in bi module
Definition: def_glob.h:227
#define DIGIT(C)
Definition: def_macro.h:42
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:1005
ptr_node bk2_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
bk2_stack_insert
Definition: trees.c:377
void read_name(ptr_psi_term tok, long ch, long(*f)(long), ptr_definition typ)
read_name
Definition: token.c:1002
void read_string(ptr_psi_term tok, long e)
read_string
Definition: token.c:859
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
#define LOWER(C)
Definition: def_macro.h:46
#define SYMBOL(C)
Definition: def_macro.h:57
long line_count
Definition: def_glob.h:1015
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define EOLN
End of line.
Definition: def_const.h:309
ptr_definition variable
symbol in bi module
Definition: def_glob.h:438
void read_number(ptr_psi_term tok, long c)
read_number
Definition: token.c:1110
ptr_definition final_dot
symbol in syntax module
Definition: def_glob.h:608
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define STRCMP
indicates to use strcmp for comparison (c function)
Definition: def_const.h:963
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
ptr_definition constant
symbol in bi module
Definition: def_glob.h:235
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
GENERIC value_3
Definition: def_struct.h:186
ptr_psi_term coref
Definition: def_struct.h:188
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
long legal_in_name(long c)
legal_in_name
Definition: token.c:980
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
void read_comment(ptr_psi_term tok)
read_comment
Definition: token.c:779
char * prompt
Definition: def_glob.h:1018
long symbolic(long c)
symbolic
Definition: token.c:967
#define SINGLE(C)
Definition: def_macro.h:52
void TOKEN_ERROR(ptr_psi_term p)
TOKEN_ERROR.
Definition: token.c:38
ptr_definition type
Definition: def_struct.h:181
long read_char()
read_char
Definition: token.c:680
long var_occurred
???
Definition: def_glob.h:839
ptr_node attr_list
Definition: def_struct.h:187
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_choice_point choice_stack
Definition: def_glob.h:1026
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
void read_token(ptr_psi_term tok)
read_token
Definition: token.c:1186
void put_back_char(long c)
put_back_char
Definition: token.c:729
void restore_parse_state ( ptr_parse_block  pb)

restore_parse_state

Parameters
pb- ptr_parse_block pb

Definition at line 444 of file token.c.

References wl_parse_block::ef, eof_flag, wl_parse_block::lc, line_count, old_saved_char, old_saved_psi_term, wl_parse_block::osc, wl_parse_block::ospt, saved_char, saved_psi_term, wl_parse_block::sc, wl_parse_block::sol, wl_parse_block::spt, and start_of_line.

445 {
446  if (pb) {
447  line_count = pb->lc;
448  start_of_line = pb->sol;
449  saved_char = pb->sc;
450  old_saved_char = pb->osc;
451  saved_psi_term = pb->spt;
452  old_saved_psi_term = pb->ospt;
453  eof_flag = pb->ef;
454  }
455 }
ptr_psi_term ospt
Definition: def_struct.h:377
long eof_flag
Definition: def_glob.h:853
long old_saved_char
Definition: def_glob.h:850
long saved_char
Definition: def_glob.h:849
long line_count
Definition: def_glob.h:1015
long start_of_line
???
Definition: def_glob.h:846
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
ptr_psi_term spt
Definition: def_struct.h:376
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
void restore_state ( ptr_psi_term  t)

restore_state

Parameters
t- ptr_psi_term t

Restore global state from an existing file state psi-term t

Definition at line 334 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.

335 {
336  // long i;
337  char *str;
338 
339 
340  input_stream = (FILE *) ((ptr_psi_term)get_attr(t,STREAM))->value_3;
341  str = (char*) ((ptr_psi_term)get_attr(t,INPUT_FILE_NAME))->value_3;
342  strcpy(input_file_name,str);
343  /* for (i=0;i++;i<=strlen(str)) input_file_name[i]=str[i]; */
344  line_count = *(REAL *) ((ptr_psi_term)get_attr(t,LINE_COUNT))->value_3;
345  saved_char = *(REAL *) ((ptr_psi_term)get_attr(t,SAVED_CHAR))->value_3;
347 
350 
353 
356 
357 
358  /* RM: Jan 27 1993
359  set_current_module(
360  find_module(((ptr_psi_term)get_attr(input_state,
361  CURRENT_MODULE))->value_3));
362  */
363 }
#define LINE_COUNT
feature name
Definition: def_const.h:890
long eof_flag
Definition: def_glob.h:853
string input_file_name
Definition: def_glob.h:1016
#define SAVED_PSI_TERM
feature name
Definition: def_const.h:918
#define OLD_SAVED_CHAR
feature name
Definition: def_const.h:911
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
long old_saved_char
Definition: def_glob.h:850
#define NULL
Definition: def_const.h:533
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
long saved_char
Definition: def_glob.h:849
ptr_psi_term null_psi_term
Used to represent an empty parse token.
Definition: def_glob.h:656
long line_count
Definition: def_glob.h:1015
#define STREAM
feature name
Definition: def_const.h:876
#define START_OF_LINE
feature name
Definition: def_const.h:897
FILE * input_stream
Definition: def_glob.h:1014
long start_of_line
???
Definition: def_glob.h:846
#define INPUT_FILE_NAME
feature name
Definition: def_const.h:883
#define OLD_SAVED_PSI_TERM
feature name
Definition: def_const.h:925
GENERIC get_attr(ptr_psi_term t, char *attrname)
get_attr
Definition: token.c:265
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
#define EOF_FLAG
feature name
Definition: def_const.h:932
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
#define SAVED_CHAR
feature name
Definition: def_const.h:904
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
void save_parse_state ( ptr_parse_block  pb)

save_parse_state

Parameters
pb- ptr_parse_block pb

Definition at line 425 of file token.c.

References wl_parse_block::ef, eof_flag, wl_parse_block::lc, line_count, old_saved_char, old_saved_psi_term, wl_parse_block::osc, wl_parse_block::ospt, saved_char, saved_psi_term, wl_parse_block::sc, wl_parse_block::sol, wl_parse_block::spt, and start_of_line.

426 {
427  if (pb) {
428  pb->lc = line_count;
429  pb->sol = start_of_line;
430  pb->sc = saved_char;
431  pb->osc = old_saved_char;
432  pb->spt = saved_psi_term;
433  pb->ospt = old_saved_psi_term;
434  pb->ef = eof_flag;
435  }
436 }
ptr_psi_term ospt
Definition: def_struct.h:377
long eof_flag
Definition: def_glob.h:853
long old_saved_char
Definition: def_glob.h:850
long saved_char
Definition: def_glob.h:849
long line_count
Definition: def_glob.h:1015
long start_of_line
???
Definition: def_glob.h:846
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
ptr_psi_term spt
Definition: def_struct.h:376
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
void save_state ( ptr_psi_term  t)

save_state

Parameters
t- ptr_psi_term t

Save global state into an existing file state psi-term t

Definition at line 293 of file token.c.

References wl_psi_term::attr_list, 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.

294 {
295  ptr_node n;
296  ptr_psi_term t1;
297 
299  t1=(ptr_psi_term)n->data;
301 
302  /* RM: Jan 27 1993
303  heap_mod_str_attr(t,CURRENT_MODULE,current_module->module_name);
304  */
305 
310 
313 
316 
317  t1=heap_psi_term(4);
320 
321  t1=heap_psi_term(4);
324 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
#define LINE_COUNT
feature name
Definition: def_const.h:890
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
long eof_flag
Definition: def_glob.h:853
void heap_mod_int_attr(ptr_psi_term t, char *attrname, long value)
heap_mod_int_attr
Definition: token.c:116
string input_file_name
Definition: def_glob.h:1016
#define SAVED_PSI_TERM
feature name
Definition: def_const.h:918
ptr_psi_term heap_psi_term(long stat)
heap_psi_term
Definition: lefun.c:75
#define OLD_SAVED_CHAR
feature name
Definition: def_const.h:911
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
long old_saved_char
Definition: def_glob.h:850
long saved_char
Definition: def_glob.h:849
ptr_psi_term null_psi_term
Used to represent an empty parse token.
Definition: def_glob.h:656
long line_count
Definition: def_glob.h:1015
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define STREAM
feature name
Definition: def_const.h:876
#define START_OF_LINE
feature name
Definition: def_const.h:897
void heap_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
heap_add_psi_attr
Definition: token.c:226
FILE * input_stream
Definition: def_glob.h:1014
GENERIC value_3
Definition: def_struct.h:186
long start_of_line
???
Definition: def_glob.h:846
#define INPUT_FILE_NAME
feature name
Definition: def_const.h:883
#define OLD_SAVED_PSI_TERM
feature name
Definition: def_const.h:925
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
#define EOF_FLAG
feature name
Definition: def_const.h:932
void heap_mod_str_attr(ptr_psi_term t, char *attrname, char *str)
heap_mod_str_attr
Definition: token.c:191
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
#define SAVED_CHAR
feature name
Definition: def_const.h:904
ptr_node attr_list
Definition: def_struct.h:187
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
void stack_add_int_attr ( ptr_psi_term  t,
char *  attrname,
long  value 
)

stack_add_int_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
value- long value

Definition at line 94 of file token.c.

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

95 {
96  ptr_psi_term t1;
97 
98  t1=stack_psi_term(4);
99  t1->type=integer;
100  t1->value_3=heap_alloc(sizeof(REAL)); /* 12.5 */
101  *(REAL *)t1->value_3 = (REAL) value;
102 
103  (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
104 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
Definition: trees.c:337
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
void stack_add_psi_attr ( ptr_psi_term  t,
char *  attrname,
ptr_psi_term  g 
)

stack_add_psi_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
g- ptr_psi_term g

Definition at line 239 of file token.c.

References wl_psi_term::attr_list, FEATCMP, heap_copy_string(), and stack_insert().

240 {
241  (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) g);
242 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
Definition: trees.c:337
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
ptr_node attr_list
Definition: def_struct.h:187
void stack_add_str_attr ( ptr_psi_term  t,
char *  attrname,
char *  str 
)

stack_add_str_attr

Parameters
t- ptr_psi_term t
attrname- char *attrname
str- char *str

Definition at line 170 of file token.c.

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

171 {
172  ptr_psi_term t1;
173 
174  t1=stack_psi_term(4);
175  t1->type=quoted_string;
177 
178  (void)stack_insert(FEATCMP,heap_copy_string(attrname),&(t->attr_list),(GENERIC) t1);
179 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
Definition: trees.c:337
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
char * stack_copy_string(char *s)
stack_copy_string
Definition: trees.c:184
void stdin_cleareof ( )

stdin_cleareof

Clear EOF if necessary for stdin

Definition at line 51 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.

52 {
53  if (eof_flag && stdin_terminal) {
54  clearerr(stdin);
58  saved_char=0;
61  }
62 }
long eof_flag
Definition: def_glob.h:853
long old_saved_char
Definition: def_glob.h:850
#define NULL
Definition: def_const.h:533
long saved_char
Definition: def_glob.h:849
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
long start_of_line
???
Definition: def_glob.h:846
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
long stdin_terminal
set in init_io in lib.c to true - never changed - used in token.c
Definition: def_glob.h:832
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
long symbolic ( long  c)

symbolic

Parameters
c- long c

SYMBOLIC(character) Tests if character is a symbol (see macro).

Definition at line 967 of file token.c.

References SYMBOL.

968 {
969  return SYMBOL(c);
970 }
#define SYMBOL(C)
Definition: def_macro.h:57
void TOKEN_ERROR ( ptr_psi_term  p)

TOKEN_ERROR.

Parameters
p- ptr_psi_term p

Definition at line 38 of file token.c.

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

39 {
40  if(p->type==error_psi_term->type) {
41  Syntaxerrorline("Module violation (%E).\n");
42  }
43 }
void Syntaxerrorline(char *format,...)
Syntaxerrorline.
Definition: error.c:557
ptr_psi_term error_psi_term
symbol in bi module
Definition: def_glob.h:118
ptr_definition type
Definition: def_struct.h:181

Variable Documentation

long inchange
static

Definition at line 478 of file token.c.

ptr_psi_term old_state =NULL

Definition at line 480 of file token.c.

FILE* out
static

Definition at line 479 of file token.c.

long outchange
static

Definition at line 478 of file token.c.

long trace_input =FALSE

Definition at line 12 of file token.c.