25 |
#include "symtab.h" |
#include "symtab.h" |
26 |
#include "options.h" |
#include "options.h" |
27 |
#include "lex.h" |
#include "lex.h" |
|
#include "xalloc.h" |
|
28 |
#include "complain.h" |
#include "complain.h" |
29 |
#include "gram.h" |
#include "gram.h" |
30 |
#include "quote.h" |
#include "quote.h" |
36 |
bucket *symval; |
bucket *symval; |
37 |
int numval; |
int numval; |
38 |
|
|
39 |
static int unlexed; /* these two describe a token to be reread */ |
/* these two describe a token to be reread */ |
40 |
static bucket *unlexed_symval; /* by the next call to lex */ |
static token_t unlexed = tok_undef; |
41 |
|
/* by the next call to lex */ |
42 |
|
static bucket *unlexed_symval = NULL; |
43 |
|
|
44 |
|
|
45 |
void |
void |
46 |
init_lex (void) |
lex_init (void) |
47 |
{ |
{ |
48 |
obstack_init (&token_obstack); |
obstack_init (&token_obstack); |
49 |
unlexed = -1; |
unlexed = tok_undef; |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
void |
54 |
|
lex_free (void) |
55 |
|
{ |
56 |
|
obstack_free (&token_obstack, NULL); |
57 |
} |
} |
58 |
|
|
59 |
|
|
322 |
|
|
323 |
|
|
324 |
void |
void |
325 |
unlex (int token) |
unlex (token_t token) |
326 |
{ |
{ |
327 |
unlexed = token; |
unlexed = token; |
328 |
unlexed_symval = symval; |
unlexed_symval = symval; |
365 |
/* Just to make sure. */ |
/* Just to make sure. */ |
366 |
token_buffer = NULL; |
token_buffer = NULL; |
367 |
|
|
368 |
if (unlexed >= 0) |
if (unlexed != tok_undef) |
369 |
{ |
{ |
370 |
|
token_t res = unlexed; |
371 |
symval = unlexed_symval; |
symval = unlexed_symval; |
372 |
c = unlexed; |
unlexed = tok_undef; |
373 |
unlexed = -1; |
return res; |
|
return c; |
|
374 |
} |
} |
375 |
|
|
376 |
c = skip_white_space (); |
c = skip_white_space (); |
426 |
case '\'': |
case '\'': |
427 |
/* parse the literal token and compute character code in code */ |
/* parse the literal token and compute character code in code */ |
428 |
|
|
|
translations = -1; |
|
429 |
{ |
{ |
430 |
int code, discode; |
int code, discode; |
431 |
|
|
453 |
case '\"': |
case '\"': |
454 |
/* parse the literal string token and treat as an identifier */ |
/* parse the literal string token and treat as an identifier */ |
455 |
|
|
|
translations = -1; |
|
456 |
{ |
{ |
457 |
int code; /* ignored here */ |
int code; /* ignored here */ |
458 |
|
|
470 |
} |
} |
471 |
|
|
472 |
case ',': |
case ',': |
473 |
|
token_buffer = ","; |
474 |
return tok_comma; |
return tok_comma; |
475 |
|
|
476 |
case ':': |
case ':': |
477 |
|
token_buffer = ":"; |
478 |
return tok_colon; |
return tok_colon; |
479 |
|
|
480 |
case ';': |
case ';': |
481 |
|
token_buffer = ";"; |
482 |
return tok_semicolon; |
return tok_semicolon; |
483 |
|
|
484 |
case '|': |
case '|': |
485 |
|
token_buffer = "|"; |
486 |
return tok_bar; |
return tok_bar; |
487 |
|
|
488 |
case '{': |
case '{': |
489 |
|
token_buffer = "{"; |
490 |
return tok_left_curly; |
return tok_left_curly; |
491 |
|
|
492 |
case '=': |
case '=': |
493 |
|
obstack_1grow (&token_obstack, c); |
494 |
do |
do |
495 |
{ |
{ |
496 |
c = getc (finput); |
c = getc (finput); |
497 |
|
obstack_1grow (&token_obstack, c); |
498 |
if (c == '\n') |
if (c == '\n') |
499 |
lineno++; |
lineno++; |
500 |
} |
} |
501 |
while (c == ' ' || c == '\n' || c == '\t'); |
while (c == ' ' || c == '\n' || c == '\t'); |
502 |
|
obstack_1grow (&token_obstack, '\0'); |
503 |
|
token_buffer = obstack_finish (&token_obstack); |
504 |
|
|
505 |
if (c == '{') |
if (c == '{') |
506 |
{ |
{ |
|
token_buffer = "={"; |
|
507 |
return tok_left_curly; |
return tok_left_curly; |
508 |
} |
} |
509 |
else |
else |
520 |
return parse_percent_token (); |
return parse_percent_token (); |
521 |
|
|
522 |
default: |
default: |
523 |
|
obstack_1grow (&token_obstack, c); |
524 |
|
obstack_1grow (&token_obstack, '\0'); |
525 |
|
token_buffer = obstack_finish (&token_obstack); |
526 |
return tok_illegal; |
return tok_illegal; |
527 |
} |
} |
528 |
} |
} |
533 |
static int |
static int |
534 |
option_strcmp (const char *left, const char *right) |
option_strcmp (const char *left, const char *right) |
535 |
{ |
{ |
536 |
const unsigned char *l, *r; |
const unsigned char *l, *r; |
537 |
int c; |
int c; |
538 |
|
|
539 |
assert(left != NULL && right != NULL); |
assert (left); |
540 |
l = (const unsigned char *)left; |
assert (right); |
541 |
r = (const unsigned char *)right; |
l = (const unsigned char *)left; |
542 |
while (((c = *l - *r++) == 0 && *l != '\0') |
r = (const unsigned char *)right; |
543 |
|| ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) |
while (((c = *l - *r++) == 0 && *l != '\0') |
544 |
l++; |
|| ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) |
545 |
return c; |
l++; |
546 |
|
return c; |
547 |
} |
} |
548 |
|
|
549 |
/* Parse a token which starts with %. |
/* Parse a token which starts with %. |
550 |
Assumes the % has already been read and discarded. */ |
Assumes the % has already been read and discarded. */ |
551 |
|
|
552 |
int |
token_t |
553 |
parse_percent_token (void) |
parse_percent_token (void) |
554 |
{ |
{ |
|
int c; |
|
555 |
const struct option_table_struct *tx; |
const struct option_table_struct *tx; |
556 |
|
|
557 |
c = getc (finput); |
int c = getc (finput); |
558 |
|
|
559 |
switch (c) |
switch (c) |
560 |
{ |
{ |
618 |
case tok_obsolete: |
case tok_obsolete: |
619 |
fatal (_("`%s' is no longer supported"), token_buffer); |
fatal (_("`%s' is no longer supported"), token_buffer); |
620 |
break; |
break; |
621 |
|
|
622 |
|
default: |
623 |
|
/* Other cases do not apply here. */ |
624 |
|
break; |
625 |
} |
} |
626 |
|
|
627 |
return tx->ret_val; |
return tx->ret_val; |