1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
|
/*
mmorph, MULTEXT morphology tool
Version 2.3, October 1995
Copyright (c) 1994,1995 ISSCO/SUISSETRA, Geneva, Switzerland
Dominique Petitpierre, <petitp@divsun.unige.ch>
*/
/*
procedures to handle symbol tables
there are Types with associated Attributes
there are Attributes with associated Values
there are rules with associated rule description
*/
#include <search.h>
#include "user.h"
/*
declarations to shutup "gcc -traditional -Wall", and lint
on SunOS 4.1.3
*/
#ifdef UNDEF
#ifndef STDC_HEADERS
extern char *tsearch();
extern char *tfind();
extern void twalk();
#endif
#endif
s_symbol_set symbol_set[SYM_TABLES_NUMBER]; /* independant symbols */
/* symbol kind names (should follow the order of e_symbol_kind enumeration) */
t_str symbol_kind_str[_last_symbol_kind + 1] = {
"attribute",
"pair",
"rule",
"spelling",
"type",
"value",
"variable",
"surface symbol",
"lexical symbol",
"lexical or surface symbol",
"surface symbol class",
"lexical symbol class",
"lexical or surface symbol class",
"lexical entry",
"alphabet",
""
};
/* rule kind names (should follow the order of e_rule_kind enumeration) */
static t_str rule_kind_str[_last_rule_kind + 1] = {
"goal",
"lexical",
"unary",
"binary",
"prefix",
"suffix",
/*
"compound",
"composite_prefix",
"composite_suffix",
*/
""
};
void
init_symbol_set(symbol_set, symbol_kind)
s_symbol_set *symbol_set;
e_symbol_kind symbol_kind;
{
symbol_set->kind = symbol_kind;
symbol_set->card = 0;
symbol_set->table = NULL;
symbol_set->ref = NULL;
}
void
init_symbol()
{
e_symbol_kind kind;
for (kind = FIRST_SYM_KIND; kind < SYM_TABLES_NUMBER; kind++) {
init_symbol_set(&symbol_set[kind], kind);
}
}
static int
#if defined(__STDC__)
sym_compare(const T_PTR sym1, const T_PTR sym2)
#else
sym_compare(sym1, sym2)
T_PTR sym1;
T_PTR sym2;
#endif
{
return (strcmp(((s_symbol *) sym1)->name, ((s_symbol *) sym2)->name));
}
#ifdef COMMENTED_OUT
/* TODO recurse through all pointers */
void
free_symbol(sym)
s_symbol *sym;
{
if (sym != NULL) {
if (sym->data != NULL)
MY_FREE(sym->data);
if (sym->name != NULL)
MY_FREE(sym->name);
MY_FREE(sym);
}
}
#endif /* COMMENTED_OUT */
int
reference_position(reference, item)
t_ptr *reference;
t_ptr item;
{
t_ptr *ref;
/* example: search for this attribute in the list associated to type */
/* TODO: sort attributes first */
ref = reference;
while ((*ref != NULL) && (*ref != item))
ref++;
if (*ref == NULL)
return (-1); /* not found */
else
return (ref - reference); /* return position */
}
t_ptr *current_ref = NULL; /* argument passed to action() */
/* one kind of action */
void
ref_is_item(item)
t_ptr item;
{
*current_ref = item;
current_ref++;
}
t_ptr *
new_ref(card, fill_reference, source, action)
int card;
void (*fill_reference) ();
t_ptr source;
void (*action) ();
{
t_ptr *ref;
MY_CALLOC(ref, card + 1, t_ptr);
ref[card] = (t_ptr) NULL; /* sentinel */
if (card > 0) {
current_ref = ref;
fill_reference(source, action);
}
return (ref);
}
/* extra argument passed to assign_reference */
static s_symbol_set *current_set;
/* Assign the reference pointer */
/*ARGSUSED2*/
static void
#if defined(__STDC__)
assign_reference(const T_PTR sym, VISIT order, int level)
#else
assign_reference(sym, order, level)
T_PTR sym;
VISIT order;
int level;
#endif
{
if (order == postorder || order == leaf)
if (sym != NULL)
if (*((s_symbol **) sym) != NULL) {
current_set->ref[(*((s_symbol **) sym))->ordinal]
= *((s_symbol **) sym);
}
}
void
make_symbol_reference(set)
s_symbol_set *set;
{
MY_CALLOC(set->ref, set->card + 1, s_symbol *);
set->ref[set->card] = NULL;
current_set = set;
twalk((T_PTR) set->table, assign_reference);
}
void
link_attribute(value_set, attribute_symbol)
s_symbol_set *value_set;
s_symbol *attribute_symbol;
{
t_index n;
for (n = 0; n < value_set->card; n++) {
value_set->ref[n]->data->value.attribute_link = attribute_symbol;
}
}
s_tfs *
new_tfs(type)
t_index type;
{
s_tfs *tfs;
t_index type_card;
MY_MALLOC(tfs, s_tfs);
tfs->type = type;
type_card = symbol_set[Type].ref[type]->data->type.card;
MY_CALLOC(tfs->att_list, type_card + 1, t_value);
tfs->att_list[type_card] = NO_BITS; /* sentinel */
tfs->var_map = NULL;
return (tfs);
}
static void
free_var_map(var_map)
s_var_map **var_map;
{
s_var_map **v;
if (var_map != NULL) {
for (v = var_map; *v != NULL; v++)
MY_FREE(*v);
MY_FREE(var_map);
}
}
void
free_tfs(tfs)
s_tfs *tfs;
{
if (tfs != NULL) {
MY_FREE(tfs->att_list);
MY_FREE(tfs);
/* use real_free if tfs->var_map needs to be freed */
}
}
#ifdef COMMENTED_OUT
void
real_free_tfs(tfs)
s_tfs *tfs;
{
if (tfs != NULL) {
MY_FREE(tfs->att_list);
MY_FREE(tfs);
MY_FREE(tfs->var_map);
}
}
#endif /* COMMENTED_OUT */
void
fill_tfs_with_variables(tfs)
s_tfs *tfs;
{
s_type *type;
s_symbol **attribute_ref;
t_value *att_list;
t_value *last_att;
type = &(symbol_set[Type].ref[tfs->type]->data->type);
attribute_ref = type->attribute_ref;
att_list = tfs->att_list;
last_att = att_list + type->card;
/* fill the type feature structure with full value sets */
while (att_list < last_att)
*att_list++ =
FULL_SET((*attribute_ref++)->data->attribute.value_set.card);
}
static void
fill_var_index(variable_ref, tfs, member)
s_symbol **variable_ref;
s_tfs *tfs;
int member;
{
s_var_map **var_map;
if (tfs != NULL)
if (tfs->var_map != NULL)
for (var_map = tfs->var_map; *var_map != NULL; var_map++)
variable_ref[(*var_map)->foreign_index]->data->variable.tfs_index[member] =
(*var_map)->local_index;
}
static void
direct_var_map(variable_ref, tfs, member)
s_symbol **variable_ref;
s_tfs *tfs;
int member;
{
s_var_map **var_map;
if (tfs->var_map != NULL)
for (var_map = tfs->var_map; *var_map != NULL; var_map++)
(*var_map)->foreign_index =
variable_ref[(*var_map)->foreign_index]
->data->variable.tfs_index[member];
}
static void
check_var_map(variable_ref, rule)
s_symbol **variable_ref;
s_rule_instance *rule;
{
s_symbol **ref;
t_index *tfs_index;
t_value *att_list[3];
t_boolean lonely_var;
t_boolean fully_specified;
int i;
int j;
int loop_bound;
t_value value;
att_list[0] = rule->lhs->att_list;
att_list[1] = rule->first->att_list;
if (rule->rule_kind == Binary) {
att_list[2] = rule->second->att_list;
loop_bound = 3;
}
else
/* Prefix and Suffix rules don't have variables in second */
loop_bound = 2; /* 1 would not check lonely var in first */
for (ref = variable_ref; *ref != NULL; ref++) {
tfs_index = (*ref)->data->variable.tfs_index;
lonely_var = TRUE;
fully_specified = FALSE;
/* unify circularly the values associated to variables */
for (i = 0, j = 1; i < loop_bound; i++, j = (j + 1) % loop_bound) {
if (tfs_index[i] != NO_INDEX && tfs_index[j] != NO_INDEX) {
lonely_var = FALSE;
value = (att_list[i][tfs_index[i]]
&= att_list[j][tfs_index[j]]);
if (value == NO_BITS)
fatal_error("variable $%s in rule \"%s\" %s",
(*ref)->name,
rule->rule_link->name,
"is inconsistent with itself");
att_list[j][tfs_index[j]] = value; /* identify */
/*
TODO: if the variable is assigned remove it from the
var_map. Currently dealt with by a user warning.
*/
if (has_unique_bit(value))
fully_specified = TRUE;
}
}
if (lonely_var)
fatal_error("variable $%s in rule \"%s\" %s",
(*ref)->name,
rule->rule_link->name,
"has no correspondant");
if (fully_specified)
print_warning("variable $%s in rule \"%s\" %s",
(*ref)->name,
rule->rule_link->name,
"is already fully specified");
}
}
void
adjust_var_map(variable_ref, rule)
s_symbol **variable_ref;
s_rule_instance *rule;
{
fill_var_index(variable_ref, rule->lhs, 0); /* TODO check necessity */
fill_var_index(variable_ref, rule->first, 1);
/* Prefix and Suffix rules are handled like Unary rules */
if (rule->rule_kind == Binary)
fill_var_index(variable_ref, rule->second, 2);
check_var_map(variable_ref, rule);
if (rule->rule_kind != Binary) {
/*
only one var map is needed. (First->var_map...foreign by
convention should point to second->att_list)
*/
direct_var_map(variable_ref, rule->lhs, 1);
free_var_map(rule->first->var_map);
rule->first->var_map = NULL;
}
/* binary rules will be taken care of in combine_rule() */
}
void
ident_var_map(tfs)
s_tfs *tfs;
{
s_var_map *v;
int n;
t_index type_card;
type_card = symbol_set[Type].ref[tfs->type]->data->type.card;
MY_CALLOC(v, type_card, s_var_map);
MY_CALLOC(tfs->var_map, type_card + 1, s_var_map *);
for (n = 0; n < type_card; n++) {
v[n].local_index = n;
v[n].foreign_index = n;
tfs->var_map[n] = &v[n];
}
tfs->var_map[type_card] = NULL; /* sentinel */
}
/* TODO: merge tfind and tsearch steps to avoid searching twice */
s_symbol **
new_symbol(name, set)
t_str name;
s_symbol_set *set;
{
s_symbol sym;
s_symbol *new_sym;
s_symbol **found_sym;
t_letter *letter_string;
if (set->table == NULL)
found_sym = NULL;
else {
sym.name = name;
found_sym = (s_symbol **) tfind((T_PTR) & sym, (T_PTR *) & (set->table),
sym_compare);
}
if (found_sym != NULL) {
switch (set->kind) {
case Surface_Letter:
/* surface and lexical alphabet share the set with pairs */
if ((*found_sym)->kind == Lexical_Letter) {
(*found_sym)->kind = Pair_Letter;
(*found_sym)->data->pair.surface =
(*found_sym)->data->pair.lexical;
break;
} /* else Surface_Letter or Pair_Letter: error */
/* FALLTHROUGH */
case Lexical_Letter: /* first one */
/* FALLTHROUGH */
case Pair_Class:
/* FALLTHROUGH */
case Attribute:
/* FALLTHROUGH */
case Type:
/* FALLTHROUGH */
case Rule:
/* FALLTHROUGH */
case Pair:
/* FALLTHROUGH */
case Spelling:
/* FALLTHROUGH */
case Value: /* declared twice */
fatal_error("%s identifier \"%s\" is already defined",
symbol_kind_str[set->kind], name);
break;
case Variable: /* TODO: update map */
break;
default:
break;
}
/* 17/01/96 Jordi <porta@crea.rae.es>
It's not possible to free now and use it after.
No pueden liberar y despues utilizar.
MY_FREE(name);
*/
}
else {
/* TODO: put most of this into a new_symbol() */
MY_MALLOC(new_sym, s_symbol);
new_sym->kind = set->kind;
new_sym->name = name;
new_sym->ordinal = set->card++;
found_sym = (s_symbol **) tsearch((T_PTR) new_sym,
(T_PTR *) & (set->table),
sym_compare);
switch (set->kind) {
case Surface_Letter:
/* FALLTHROUGH */
case Lexical_Letter:
if (new_sym->ordinal >= (t_card) LETTER_MAX)
fatal_error("symbol %s: %s (maximum=%d)",
new_sym->name,
"too many different alphabet symbols",
LETTER_MAX - 3); /* NUL, ANY, 2
BOUNDARIES */
MY_MALLOC(new_sym->data, s_pair);
MY_STRALLOC(letter_string, 2);
letter_string[0] = (t_letter) new_sym->ordinal;
letter_string[1] = NUL_LETTER;
new_sym->data->pair.pair_flags = BOTH_LETTERS;
if (set->kind == Surface_Letter) {
new_sym->data->pair.surface = letter_string;
new_sym->data->pair.lexical = NULL;
new_sym->data->pair.next = NULL; /* list empty */
}
else {
new_sym->data->pair.surface = NULL;
new_sym->data->pair.lexical = letter_string;
new_sym->data->pair.next = NULL; /* list empty */
}
break;
case Pair_Class:
MY_MALLOC(new_sym->data, s_class);
new_sym->data->class.pair_flags = BOTH_CLASSES;
new_sym->data->class.surface
= new_bitmap((long) alphabet_size);
new_sym->data->class.lexical = NULL;
new_sym->data->class.next = NULL; /* list empty */
break;
case Pair:
MY_MALLOC(new_sym->data, s_pair);
new_sym->data->pair.surface = NULL;
new_sym->data->pair.lexical = NULL;
new_sym->data->pair.next = NULL; /* list empty */
break;
case Attribute:
MY_MALLOC(new_sym->data, s_attribute);
init_symbol_set(&(new_sym->data->attribute.value_set), Value);
break;
case Rule:
MY_MALLOC(new_sym->data, s_rule);
init_symbol_set(&(new_sym->data->rule.variable_set),
Variable);
MY_MALLOC(new_sym->data->rule.instance, s_rule_instance);
new_sym->data->rule.instance->lhs = NULL;
new_sym->data->rule.instance->first = NULL;
new_sym->data->rule.instance->second = NULL;
new_sym->data->rule.instance->lex = NULL;
new_sym->data->rule.instance->rule_link = new_sym;
break;
case Spelling:
MY_MALLOC(new_sym->data, s_spelling);
MY_MALLOC(new_sym->data->spelling.instance, s_spell_instance);
/*
init_symbol_set(&(new_sym->data->rule.variable_set),
Variable);
*/
break;
case Type:
MY_MALLOC(new_sym->data, s_type);
new_sym->data->type.card = 0;
new_sym->data->type.project_card = 0;
new_sym->data->type.attribute_ref = NULL;
break;
case Value:
if (new_sym->ordinal >= MAXVAL) {
fatal_error("%s (max=%d, at value \"%s\")",
"too many values declared for this attribute",
MAXVAL, new_sym->name);
}
MY_MALLOC(new_sym->data, s_value);
break;
case Variable:
MY_MALLOC(new_sym->data, s_variable);
new_sym->data->variable.attribute_link = (s_symbol *) NULL;
new_sym->data->variable.tfs_index[0] = NO_INDEX;
new_sym->data->variable.tfs_index[1] = NO_INDEX;
new_sym->data->variable.tfs_index[2] = NO_INDEX;
break;
default:
break;
}
}
return (found_sym);
}
s_symbol **
find_symbol(name, set)
t_str name;
s_symbol_set *set;
{
s_symbol sym;
s_symbol **found_sym;
sym.name = name;
found_sym = (s_symbol **) tfind((T_PTR) & sym,
(T_PTR *) & (set->table), sym_compare);
if (found_sym == NULL)
fatal_error("%s identifier \"%s\" is not defined",
symbol_kind_str[set->kind], name);
MY_FREE(name);
return (found_sym);
}
static t_boolean
print_value(file, attribute, value, record_field_mode)
FILE *file;
s_symbol *attribute;
t_value value;
t_boolean record_field_mode;
{
s_symbol_set *value_set;
char *format;
int n;
t_boolean first;
value_set = &attribute->data->attribute.value_set;
if (value_set->card > 1 && FULL_SET(value_set->card) == value)
return (FALSE); /* don't print variables */
else {
print(file, "%s=", attribute->name);
first = TRUE;
if (record_field_mode)
format = "!%s";
else
format = "|%s";
for (n = 0; n < value_set->card; n++)
if (TEST_BIT(value, n)) {
if (first) {
print(file, "%s", value_set->ref[n]->name);
first = FALSE;
}
else
print(file, format, value_set->ref[n]->name);
}
return (TRUE);
}
}
void
print_tfs1(file, tfs, print_var_map, print_projection, record_field_mode)
FILE *file;
s_tfs *tfs;
t_boolean print_var_map;
t_boolean print_projection;
t_boolean record_field_mode;
{
int i;
s_symbol *symbol;
s_symbol **attribute_ref;
t_index type_card;
if (tfs != NULL) {
symbol = symbol_set[Type].ref[tfs->type];
attribute_ref = symbol->data->type.attribute_ref;
if (print_projection)
type_card = symbol->data->type.project_card;
else
type_card = symbol->data->type.card;
print(file, "%s[ ", symbol->name);
for (i = 0; i < type_card; i++) {
if (print_value(file, attribute_ref[i], tfs->att_list[i],
record_field_mode))
print(file, " ");
}
if (record_field_mode)
print(file, "]");
else
print(file, "]\n");
if (tfs->var_map != NULL && print_var_map) {
for (i = 0; tfs->var_map[i] != NULL; i++)
print(file, "map att %s = %d\n",
attribute_ref[tfs->var_map[i]->local_index]->name,
tfs->var_map[i]->foreign_index);
}
}
}
void
print_tfs(tfs)
s_tfs *tfs;
{
print_tfs1(logfile, tfs, FALSE, FALSE, FALSE);
}
void
print_tfs_proj(tfs)
s_tfs *tfs;
{
print_tfs1(outfile, tfs, FALSE, TRUE, FALSE);
}
void
print_tfs_proj_tbl(tfs)
s_tfs *tfs;
{
print_tfs1(outfile, tfs, FALSE, TRUE, TRUE);
}
static void
print_labeled_tfs(tfs, label)
s_tfs *tfs;
t_str label;
{
if (tfs != NULL) {
print_log("%s", label);
print_tfs1(logfile, tfs, TRUE, FALSE, FALSE);
}
}
static void
print_class(class)
s_bitmap *class;
{
long letter_index;
print_log("{");
FOR_EACH_BIT(class, letter_index)
print_log(" %s", symbol_set[Pair].ref[letter_index]->name);
print_log(" }");
}
static void
print_symbol_string(letter_string)
t_letter *letter_string;
{
if (letter_string == letter_any)
print_log("?");
else if (strlen((char *) letter_string) == 1)
print_log("%s", symbol_set[Pair].ref[*letter_string]->name);
else { /* TODO print angle brackets */
print_log("\"");
print_string(logfile, letter_string);
print_log("\"");
}
}
static void
print_pair(pair)
s_pair *pair;
{
do {
print_log(" ");
if (pair->pair_flags & SURFACE_IS_CLASS)
print_class((s_bitmap *) pair->surface);
else
print_symbol_string(pair->surface);
print_log("/");
if (pair->pair_flags & LEXICAL_IS_CLASS)
print_class((s_bitmap *) pair->lexical);
else
print_symbol_string(pair->lexical);
pair = pair->next;
} while (pair != NULL);
print_log("\n");
}
static void
print_spell(spell)
s_spell_instance *spell;
{
if (spell->kind == Optional)
print_log("=>\n");
else if (spell->kind == Coerce)
print_log("<=\n");
else
print_log("<=>\n");
/* TO DO print reverse left context */
map_chain(spell->left_context, print_pair);
print_log("-");
map_chain(spell->focus, print_pair);
print_log("-");
map_chain(spell->right_context, print_pair);
map_chain(spell->constraint, print_tfs);
print_log("concatenation point: %d\n", spell->concat_pos);
}
void
print_symbols_by_ref(set)
s_symbol_set *set;
{
t_index n;
s_symbol *sym;
if (set == NULL)
return;
for (n = 0; n < set->card; n++) {
sym = set->ref[n];
print_log("\n%s %d\t%s\n",
symbol_kind_str[sym->kind],
sym->ordinal,
sym->name);
switch (sym->kind) {
case Attribute:
print_symbols_by_ref(&sym->data->attribute.value_set);
break;
case Rule:
print_log("rule kind %s\n",
rule_kind_str[sym->data->rule.instance->rule_kind]);
if (sym->data->rule.instance->lex != NULL) {
print_log("lex string ");
print_string(logfile, sym->data->rule.instance->lex);
print_log("\n");
}
print_symbols_by_ref(&sym->data->rule.variable_set);
print_labeled_tfs(sym->data->rule.instance->lhs, "lhs: ");
print_labeled_tfs(sym->data->rule.instance->first, "first: ");
print_labeled_tfs(sym->data->rule.instance->second,
"second: ");
break;
case Spelling:
print_spell((s_spell_instance *) sym->data->spelling.instance);
/*
print_symbols_by_ref(&sym->data->spelling.variable_set);
*/
break;
case Type:
{
s_symbol **psym;
for (psym = sym->data->type.attribute_ref;
*psym != NULL; psym++)
print_log("with attribute\t%s\n",
(*psym)->name);
}
break;
case Value:
print_log("of attribute\t%s\n",
sym->data->value.attribute_link->name);
break;
case Pair:
/* FALLTHROUGH */
case Surface_Letter:
/* FALLTHROUGH */
case Lexical_Letter:
/* FALLTHROUGH */
case Pair_Letter:
/* FALLTHROUGH */
case Surface_Class:
/* FALLTHROUGH */
case Lexical_Class:
/* FALLTHROUGH */
case Pair_Class:
/* FALLTHROUGH */
default:
break;
}
}
}
/* Print out symbols in alphabetical order */
/*ARGSUSED2*/
static void
#if defined(__STDC__)
print_sym(const T_PTR symptr, VISIT order, int level)
#else
print_sym(symptr, order, level)
T_PTR symptr;
VISIT order;
int level;
#endif
{
s_symbol *sym;
if (!(order == postorder || order == leaf) || symptr == NULL)
return;
sym = *((s_symbol **) symptr);
if (sym == NULL)
return;
switch (sym->kind) {
case Surface_Class:
/* FALLTHROUGH */
case Lexical_Class:
/* FALLTHROUGH */
case Pair_Class:
if (defined_kind == Pair_Class) {
print_log("\n%s %d\t%s\n",
symbol_kind_str[sym->kind],
sym->ordinal,
sym->name);
if (sym->kind == Surface_Class)
print_class(sym->data->class.surface);
else
print_class(sym->data->class.lexical);
print_log("\n");
}
break;
case Pair:
if (defined_kind == Pair) {
print_log("\n%s %d\t%s\n",
symbol_kind_str[sym->kind],
sym->ordinal,
sym->name);
print_pair((s_pair *) sym->data);
}
break;
default:
break;
}
}
/* used to print tables that don't have an associated reference array */
void
print_symbol_table(symbol_set)
s_symbol_set *symbol_set;
{
twalk((T_PTR) symbol_set->table, print_sym);
}
|