8 #include "parser.tab.h"
11 extern void print_node ();
12 static void print_symbol ();
13 static void print_string ();
14 static void print_number ();
15 static void print_const ();
16 static void print_declare ();
17 static void print_func ();
18 static void print_proc ();
19 static void print_call ();
20 static void print_expr ();
21 static void print_args ();
22 static void print_arglist ();
23 static void print_statement ();
24 static void print_return ();
25 static void print_variable ();
26 static void print_initialized_variable ();
27 static void print_initial_list ();
28 static void print_assign (struct node *nodep, int indent);
29 static void print_if ();
30 static void print_while ();
31 static void print_switchon (struct node *nodep, int indent);
32 static void print_case (struct node *nodep, int indent);
33 static void print_repeatuntil (struct node *nodep, int indent);
34 static void print_get (struct node *nodep, int indent);
35 static void print_block (struct node *nodep, int indent);
37 static struct debug_entry *get_entry ();
48 struct debug_entry debug_table[] =
50 { OP_DECLARE, "declare", print_declare },
51 { OP_MANIFEST, "manifest", print_node },
52 { OP_CONST, "const", print_const },
53 { OP_GLOBAL, "global", print_node },
54 { OP_STATIC, "static", print_node },
55 { OP_FUNCTION, "func", print_func },
56 { OP_PROCEDURE, "proc", print_proc },
57 { OP_ARGS, "args", print_arglist },
58 { OP_PLUSOP, "+", print_expr },
59 { OP_SUBOP, "-", print_expr },
60 { OP_MULTOP, "*", print_expr },
61 { OP_DIVOP, "/", print_expr },
62 { OP_GT, "<", print_expr },
63 { OP_LT, ">", print_expr },
64 { OP_GE, "<=", print_expr },
65 { OP_LE, ">=", print_expr },
66 { OP_AND, "&", print_expr },
67 { OP_OR, "|", print_expr },
68 { OP_EQUAL, "=", print_expr },
69 { OP_VECIS, "!", print_expr },
71 { OP_STATEMENT, "- ", print_statement },
72 { OP_CALL, "Call", print_call },
73 { OP_RETURN, "return", print_return },
74 { OP_VALOF, "valof", print_node },
75 { OP_VARIABLE, "var", print_variable },
76 { OP_INITIALVAR, "initvar", print_initialized_variable },
77 { OP_SET, "assign", print_assign },
78 { OP_IF, "if", print_if },
79 { OP_WHILE, "whlie", print_while },
80 { OP_SWITCHON, "switchon", print_switchon },
81 { OP_CASE, "case", print_case },
82 { OP_CASECONT, "case", print_case },
83 { OP_REPEATUNTIL, "repeatuntil", print_repeatuntil },
84 { OP_GET, "GET", print_get },
85 { OP_BLOCK, "BLOCK", print_block },
87 { TK_SYMBOL, "symbol", print_symbol },
88 { TK_STRING, "string", print_string },
89 { TK_NUMBER, "number", print_number },
94 static struct debug_entry *
103 for (i = 0; debug_table[i].type != 0; i++)
105 if (nodep->type == debug_table[i].type)
107 return (&debug_table[i]);
119 for (i = 0; i < n; i++)
127 debug_print (struct node *nodep, int indent)
129 struct debug_entry *entp, *p;
134 entp = get_entry (nodep);
138 (entp->f)(nodep, indent);
143 print_node (struct node *nodep, int indent)
145 struct debug_entry *entp, *p;
150 entp = get_entry (nodep);
151 print_space (indent);
152 printf ("[%s]\n", entp->nicname);
153 if (p = get_entry (nodep->head))
155 (p->f)(nodep->head, indent + 2);
158 if (p = get_entry (nodep->body))
160 (p->f)(nodep->body, indent + 2);
163 if (p = get_entry (nodep->next))
165 (p->f)(nodep->next, indent + 2);
171 print_symbol (struct symbol *symbolp, int indent)
173 print_space (indent);
174 printf ("<%s>", symbolp->value);
179 print_string (struct string *strp, int indent)
181 print_space (indent);
182 printf ("<string>\"%s\"", strp->value);
186 print_number (struct number *nump, int indent)
188 print_space (indent);
189 printf ("%d", nump->value);
194 print_declare (struct node *nodep, int indent)
200 print_space (indent);
201 printf ("[declare]\n");
202 debug_print (nodep->head, indent + 10);
205 print_declare (nodep->next, indent);
210 print_const (struct node *nodep, int indent)
217 print_space (indent);
218 printf ("[const]\t%s,%d\n", sp->value, np->value);
221 print_const (nodep->next, indent);
226 print_func (struct node *nodep, int indent)
236 print_space (indent);
237 printf ("[function] %s\n", sp->value);
238 debug_print ((void *)argp, indent + 2);
239 debug_print ((void *)exp, indent + 2);
240 /* printf ("\n"); ** */
244 print_proc (struct node *nodep, int indent)
254 print_space (indent);
255 printf ("[procedure] %s\n", sp->value);
256 debug_print ((void *)argp, indent + 2);
257 debug_print ((void *)body, indent + 2);
262 print_call (struct node *nodep, int indent)
270 print_space (indent);
271 printf ("[call] %s(", sp->value);
272 print_args ((void *)argp, indent + 2);
278 print_arglist (struct node *nodep, int indent)
280 print_space (indent);
282 print_args (nodep, indent);
288 print_args (struct node *nodep, int indent)
298 if (sp->type == TK_SYMBOL)
300 printf ("%s", sp->value);
304 debug_print ((struct node *)sp, 0);
310 print_args (argp, indent);
315 print_expr (struct node *nodep, int indent)
317 struct debug_entry *entp;
318 struct node *ex1, *ex2;
322 entp = get_entry (nodep);
324 print_space (indent);
325 printf ("(%s", entp->nicname);
329 debug_print (ex1, 0);
334 debug_print (ex2, 0);
341 print_statement (struct node *nodep, int indent)
343 struct debug_entry *entp;
344 struct node *body, *next;
348 entp = get_entry (nodep);
350 print_space (indent);
361 debug_print (body, indent);
365 debug_print (body, 0);
372 debug_print (next, indent);
378 print_variable (struct node *nodep, int indent)
380 struct debug_entry *entp;
386 entp = get_entry (nodep);
388 print_space (indent);
392 if (body->type == TK_SYMBOL)
394 printf ("%s", body->value);
398 debug_print ((struct node *)body, 0);
404 print_args (next, 0);
410 print_assign (struct node *nodep, int indent)
412 struct node *body, *head;
416 print_space (indent);
417 printf ("[assign] ");
420 debug_print (head, 0);
427 debug_print (body, 0);
433 print_return (struct node *nodep, int indent)
438 print_space (indent);
439 printf ("[return] ");
442 debug_print (body, 0);
448 print_initialized_variable (struct node *nodep, int indent)
450 struct node *body, *next;
455 print_space (indent);
458 print_variable (body, 0);
464 print_initial_list (next);
470 print_initial_list (struct node *nodep)
478 if (nump->type == TK_NUMBER)
480 printf ("%d", nump->value);
484 print_node ((struct node *)nump, 0);
490 print_initial_list (nodep->next);
495 print_if (struct node *nodep, int indent)
497 struct node *head, *body;
502 debug_print ((struct node *)head, 0);
504 debug_print ((struct node *)body, indent + 4);
509 print_while (struct node *nodep, int indent)
511 struct node *head, *body;
513 printf ("[WHILE] ( ");
516 debug_print ((struct node *)head, 0);
518 debug_print ((struct node *)body, indent + 4);
523 print_switchon (struct node *nodep, int indent)
525 struct node *expr, *caselist;
527 printf ("[SWITCHON] ( ");
529 caselist = nodep->body;
531 debug_print (expr, 0);
533 debug_print (caselist, indent + 4);
538 print_case (struct node *nodep, int indent)
540 print_space (indent);
541 printf ("[CASE] ( ");
542 debug_print (nodep->head, 0);
544 debug_print (nodep->body, indent + 8);
547 print_case (nodep->next, indent);
552 print_repeatuntil (struct node *nodep, int indent)
554 struct node *head, *body;
556 printf ("[REEATUNTIL] ( ");
559 debug_print ((struct node *)body, 0);
561 debug_print ((struct node *)head, indent + 4);
565 print_get (struct node *nodep, int indent)
567 print_space (indent);
569 debug_print ((struct node *)nodep->body, 0);
574 print_block (struct node *nodep, int indent)
576 printf ("[BLOCK]\n");
577 debug_print ((struct node *)nodep->head, indent + 4);