home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 357_01 / cstar1.exe / PAR.C < prev    next >
C/C++ Source or Header  |  1991-06-18  |  35KB  |  1,668 lines

  1. /*
  2.     C* -- Parser Part I  (statements)
  3.  
  4.     source:  par.c
  5.     started: October 22, 1985
  6.     version:
  7.         March 5, 1987
  8.         March 7, 1989
  9.  
  10.     PUBLIC DOMAIN SOFTWARE
  11.  
  12.     The CSTAR program was placed in    the public domain on June 15, 1991,
  13.     by its author and sole owner,
  14.  
  15.         Edward K. Ream
  16.         1617 Monroe Street
  17.         Madison, WI 53711
  18.         (608) 257-0802
  19.  
  20.     CSTAR may be used for any commercial or non-commercial purpose.
  21.  
  22.     See cstar.h or cstar.c for a DISCLAIMER OF WARRANTIES.
  23. */
  24. #include "cstar.h"
  25.  
  26. /*
  27.     Externally visible routines defined in this module:
  28. */
  29. void    mark_noneed    (struct node *p);
  30. void    need        (int token);
  31. bool    needend        (int token);
  32. void    pn_init        (void);
  33. void    program        (void);
  34.  
  35. /*
  36.     Internal routines:
  37. */
  38. static struct lab_node * gl_enter    (char * symbol);
  39. static void         gl_init    (void);
  40. static struct lab_node * gl_lookup    (char * symbol);
  41. static void         ll_check    (void);
  42. static struct lab_node * ll_enter    (char * symbol);
  43. static void         ll_init    (void);
  44. static struct lab_node * ll_lookup    (char * symbol);
  45.  
  46. static void    pn_append    (register struct node *p,
  47.                 struct node **last, struct node **head);
  48.  
  49. static struct node *    pn_break    (void);
  50. static struct fbody *    pn_body        (char * name);
  51. static struct node *    pn_case        (void);
  52. static struct node *    pn_continue    (void);
  53. static struct node *    pn_default    (void);
  54. static struct node *    pn_do        (void);
  55. static void        pn_err_need    (char * s);
  56. static struct node *    pn_for        (void);
  57. static struct node *    pn_goto        (void);
  58. static void        pn_head        (void);
  59. static struct node *    pn_if        (void);
  60. static struct node *    pn_label    (void);
  61. static struct node *    pn_list        (bool one_flag);
  62. static struct node *    pn_return    (void);
  63. static struct node *    pn_switch    (void);
  64. static struct node *    pn_while    (void);
  65. static struct node *    pn_x        (void);
  66. static struct node *    pn_x1        (int subtype);
  67. static struct node *    pn_xlab        (void);
  68. static struct node *    pn_z        (void);
  69. static struct node *    pn_z1        (int subtype);
  70.  
  71. /*
  72.     externals variables.
  73. */
  74. extern struct st_node * intrn_decl;
  75.  
  76. /*
  77.     D A T A    S T R U C T U R E S.
  78. */
  79.  
  80. /*
  81.     The brk_ref, cont_ref, sw_ref are back pointers to the parent
  82.     nodes for break, continue and default statements. 
  83.     Initialized by program().
  84. */
  85. static struct node *    brk_ref;    /* Current break reference.    */
  86. static struct node *    cont_ref;    /* Current continue reference.    */
  87. static struct node *    sw_ref;        /* Current switch reference.    */
  88.  
  89. /*
  90.     Define format of a label list node.
  91.     The spelling of the symbol is in lab_label -> c_labsym.
  92.  
  93.     WARNING: not yet and maybe never.
  94.     There are two user label tables--one local and one global.
  95.     Global labels are an extension to the C language and preclude
  96.     any occurence of a local label with the same spelling.
  97. */
  98. static struct lab_node {
  99.     struct lab_node *    lab_next;
  100.     bool            lab_defined;    /* Defined flag.    */
  101.     struct node *        lab_label;    /* culabel_node.    */
  102. };
  103. static struct lab_node ll_head;        /* Header for local label list.    */
  104. static struct lab_node gl_head;        /* Header for global label list. */
  105.  
  106. struct lab_node * ll_enter(), * ll_lookup();
  107. struct lab_node * gl_enter(), * gl_lookup();
  108.  
  109. /*
  110.     E X T E R N A L L Y    V I S I B L E    R O U T I N E S.
  111. */
  112.  
  113. /*
  114.     mark an outer statement or the product of an alist run as OPT_NONEED
  115.     this is also called by setype2 to mark arg1 of a comma
  116.  
  117.     the mark indicates that the actual result of the item will never
  118.     be used, so that, for example, x++ need not store the pre-value
  119.     of x in a temporary.
  120. */
  121. void
  122. mark_noneed(struct node *p)
  123. {
  124.     TRACEPB("mark_noneed", printf("(%p)\n", p));
  125.  
  126.     if (is_argop(p -> n_type)) {
  127.         p -> n_oflags |= OPT_NONEED;
  128.     }
  129.     else if (p -> n_type == SEPARATOR_TOK) {
  130.         mark_noneed(p -> n_car);
  131.         mark_noneed(p -> n_next);
  132.     }
  133.  
  134.     TICKX("mark_noneed");
  135. }
  136.  
  137. /*
  138.     Skip the current token if it is what we think it is.
  139. */
  140. void
  141. need(int token)
  142. {
  143.     TRACEP("need", printf("(%d = %s)\n", token, ps_tok(token)));
  144.  
  145.     if (t_type == token) {
  146.         get_token();
  147.         return;
  148.     }
  149.     else {
  150.         if (token) {
  151.             pn_err_need(ps_tok(token));
  152.         }
  153.         else {
  154.             pn_err_need("primitive");
  155.         }
  156.         return;
  157.     }
  158. }
  159.  
  160. /*
  161.     error message about needed symbol
  162. */
  163. static void
  164. pn_err_need(char *s)
  165. {
  166.     SL_DISABLE();
  167.  
  168.     switch(t_type) {
  169.     case ID_TOK:
  170.         t_3serr(NULL, s, " expected at: ", t_symbol);
  171.         break;
  172.     case Z_TOK:
  173.     case X_TOK:
  174.         t_3serr(NULL, s, " expected at keyword: ", t_symbol);
  175.         break;
  176.     default:
  177.         if (ps_tok(t_type)) {
  178.             t_3serr(NULL, s, " expected at: ", ps_tok(t_type));
  179.         }
  180.         else {
  181.             t_2error(s, " expected");
  182.         }
  183.     }
  184. }
  185.  
  186. /*
  187.     If the current token is tok, return TRUE and eat it.
  188.  
  189.     Otherwise find the next instance of tok, eat it, and
  190.     return false
  191.     -- BUT --
  192.     stop on and return an intervening semicolon or brace.
  193. */
  194. bool
  195. needend(int tok)
  196. {
  197.     TRACEP("needend", printf("(%d = %s)\n", tok, ps_tok(tok)));
  198.  
  199.     if (t_type == tok) {
  200.         get_token();
  201.         return TRUE;
  202.     }
  203.  
  204.     pn_err_need(ps_tok(tok));
  205.  
  206.     for(;;) {
  207.         switch(t_type) {
  208.         case SEMICOLON_TOK:
  209.         case LCURLY_TOK:
  210.         case RCURLY_TOK:
  211.         case EOF_TOK:
  212.         case EOP_TOK:
  213.             return FALSE;
  214.         }
  215.         get_token();
  216.         if (t_type == tok) {
  217.             get_token();
  218.             return FALSE;
  219.         }
  220.     }
  221. }
  222.  
  223. /*
  224.     Set up constants and so on.
  225. */
  226. void
  227. pn_init(void)
  228. {
  229.     TICKB("pn_init");
  230.  
  231.     scope.s_scope = FILE_SCOPE;
  232.     scope.s_snext = NULL;
  233.     scope.s_fntype = NULL;
  234.  
  235.     /* Initialize the label tables. */
  236.     gl_init();
  237.     ll_init();
  238.  
  239.     TICKX("pn_init");
  240. }
  241.  
  242.  
  243.  
  244. /*
  245.     This is the main routine of the parser.
  246.     It looks for external declarations and function definitions.
  247.     Anything else is ignored with a warning message.
  248. */
  249. void
  250. program(void)
  251. {
  252.     register struct st_node * id;
  253.  
  254.     /* Initialize chains of references. */
  255.  
  256.     TICKB("program");
  257.  
  258.     brk_ref  = NULL;
  259.     cont_ref = NULL;
  260.     sw_ref   = NULL;
  261.  
  262.     /* Put signature into file */
  263.     if (!nogen_flag) {
  264.         syssput("* ----- C Star compilation");
  265.         sysnlput();
  266.     }
  267.  
  268.     /* Get the first token of the program. */
  269.     get_token();
  270.  
  271.     for (;;) {
  272.     switch(t_type) {
  273.  
  274.     case EOP_TOK:
  275.     case EOF_TOK:
  276.         RETURN_VOID("program");
  277.  
  278.     case X_TOK:
  279.         (void) pn_x();
  280.         break;
  281.  
  282.     case Z_TOK:
  283.         (void) pn_z();
  284.         break;
  285.  
  286.     case ID_TOK:
  287.  
  288.         /* Do character-oriented lookahead. */
  289.         skip_bl();
  290.         if (ch == ':') {
  291.             /* External label--extension to C. */
  292.             pn_label();
  293.             break;
  294.         }
  295.         /* must be decl or function definition or error */
  296.         pn_head();
  297.         break;
  298.  
  299.     case RCURLY_TOK:
  300.         t_warning("check program structure");
  301.         fatal("one } too many");
  302.     
  303.     case LCURLY_TOK:
  304.         t_warning("check program structure");
  305.         fatal("{ in outer context");
  306.  
  307.     default:
  308.         if (is_kdecl(t_type)) {
  309.             pn_head();
  310.         }
  311.         else {
  312.             t_error("declaration or pseudo-op expected in outer context");
  313.             fatal("program structure too confusing");
  314.         }
  315.         break;
  316.  
  317.     } /* End switch */
  318.     } /* End for    */
  319. }
  320.  
  321. /*
  322.     I N T E R N A L    R O U T I N E S.
  323. */
  324.  
  325. /*
  326.     Append list p to list whose last element and first element are given.
  327.     Update *last and *head.
  328. */
  329. static void
  330. pn_append(register struct node *p, struct node **last, struct node **head)
  331. {
  332.     TRACEPB("pn_append", printf("(%p, %p, %p)\n", p, last, head));
  333.  
  334.     if (p == NULL) {
  335.         RETURN_VOID("pn_append");
  336.     }
  337.  
  338.     /* enter p on the list */
  339.     if (*head == NULL) {
  340.         *head = p;
  341.     }
  342.     else {
  343.         (*last) -> n_next = p;
  344.     }
  345.  
  346.     while (p -> n_next != NULL) {
  347.         p = p -> n_next;
  348.     }
  349.  
  350.     *last = p;
  351.  
  352.     TRACEPX("pn_append",
  353.         printf("returns: %p->%p, *last %p, *head %p\n",
  354.         p, p -> n_cltype, *last, *head));
  355. }
  356.  
  357. /*
  358.     Parse a declaration, which may lead into a function body.
  359.  
  360.     This routine calls code().
  361.  
  362.     This routine releases the local symbol table; code() does
  363.     not do that any longer.
  364. */
  365. static void
  366. pn_head(void)
  367. {
  368.     unsigned long f_size;
  369.     struct fbody * fn_body;
  370.     register struct type_node *t, *tf;
  371.     register struct node *p;
  372.     register struct st_node *id;
  373.     struct type_node *head_x;
  374.  
  375.     TICKB("pn_head");
  376.  
  377.     scope.s_scope = FILE_SCOPE;
  378.  
  379.     /* fndef sees that there were explicit parentheses in some tail */
  380.     /* head_x only makes sense for singular call ... */
  381.     t = pd_stmt(DELEMENT_TYPE, FALSE, &head_x);
  382.  
  383.     if (t && (is_kdecl(t_type) || t_type == LCURLY_TOK)) {
  384.  
  385.         TRACE("pn_head",
  386.           printf("pn_head: apparent function definition: type=%p\n",t));
  387.  
  388.         if (!pd_is1func(t)) {
  389.             t_error("declaration leads into a function definition");
  390.             fatal("program structure too confusing");
  391.         }
  392.         if (head_x -> t_typtok == FUNCTION_TYPE) {
  393.             t_error("this way of defining a function is too cute");
  394.         }
  395.  
  396.         if (id = t -> t_parent) {
  397.             switch(id -> st_sclass) {
  398.             case CODE_CLASS:
  399.             case SCODE_CLASS:
  400.                 break;
  401.             default:
  402.                 t_error("invalid storage class");
  403.                 id -> st_sclass = GLOBAL_CLASS;
  404.             }
  405.         }
  406.         else {
  407.             fatal("pn_head: internal: no parent");
  408.         }
  409.  
  410.         tf = t -> t_link;    /* function-returning node itself */
  411.                     /* t is the delement node */
  412.         TRACEP("pn_head",
  413.             printf("leads into function %s, type=%p\n",
  414.                 id -> st_name, tf));
  415.  
  416.         /* note: the formals are now attached to the function type */
  417.         
  418.         if(t_type != LCURLY_TOK) {
  419.             /* then it's a k_decl */
  420.             TRACE("pn_head", printf("formal declarations\n"));
  421.             scope.s_scope = FNDEF_SCOPE;
  422.             (void) pd_stmt(NULL_TYPE, TRUE, NULL);
  423.             TRACE("pn_head", pr_type(tf);printf("\n"));
  424.         }
  425.  
  426.         /* clear the local allocations */
  427.         regs_clear();
  428.         gen_init();
  429.  
  430.         /* size the formals and generate register moves */
  431.         f_size = pd_alloc(tf -> t_list, 0);
  432.  
  433.         /* may want to make a node to hold the size */
  434.         /* it does not belong in t_tsize */
  435.         scope.s_scope = BLOCK_SCOPE;
  436.         scope.s_fntype = tf;
  437.         
  438.         if (t_type != LCURLY_TOK) {
  439.             t_error("{ expected in function definition");
  440.             fatal("program structure too confusing");
  441.         }
  442.         else {
  443.             /* Parse the body of the function. */
  444.             fn_body = pn_body(id -> st_name);
  445.             fn_body -> fname = id -> st_alias;
  446.             fn_body -> formals = tf -> t_list;
  447.             fn_body -> fml_size = f_size;
  448.             fn_body -> ftype = tf;
  449.             fn_body -> fclass = id -> st_sclass;
  450.  
  451.             /* Check for referenced but not defined labels. */
  452.             ll_check();
  453.  
  454.             /* Generate code for the function !! */
  455.             gen_function(fn_body);
  456.         }
  457.  
  458.         /* clear the symbol table and release memory */
  459.         pd_orphan(tf -> t_list);
  460.         lst_init();
  461.         ll_init();
  462.         ml_release();
  463.         scope.s_scope = FILE_SCOPE;
  464.         scope.s_fntype = NULL;
  465.     }
  466.     else {
  467.         if (t_type == SEMICOLON_TOK) {
  468.             TRACE("decls",
  469.                 printf(">> Outer definition:\n");
  470.                 pr_type(t);
  471.                 printf("\n\n");
  472.             );
  473.  
  474.             /* Generate code for outer definiitions. */
  475.             out_decl(t);
  476.         }
  477.         need(SEMICOLON_TOK);
  478.     }
  479.  
  480.     TICKX("pn_head");
  481. }
  482.  
  483. /*
  484.     Parse a function body.  First declarations, then statements.
  485.     This is called in whatever SCOPE it is called in.
  486.     The body ends with the absorption of the terminal }.
  487.  
  488.     WARNING:
  489.     If declarations are found after the initial declarations,
  490.     t_error should be raised, and then they should be
  491.     parsed by pd_stmt(NULL_TYPE, TRUE, NULL).  Among other
  492.     things, this will cause a fatal error and a warning to
  493.     examine braces if one of the declarations looks like a
  494.     function definition.
  495.  
  496.     scope.s_fntype is the function type-node encompassing the body
  497.  
  498.     WARNING: return expressions are not checked yet
  499. */
  500. static struct fbody *
  501. pn_body(char *name)
  502. {
  503.     register struct st_node *id;
  504.     static struct fbody b;
  505.  
  506.     TRACEPB("pn_body", printf("(%s)\n", name));
  507.  
  508.     call_1arg = 0;
  509.  
  510.     /*
  511.         WARNING:
  512.         If blocks are implemented, this will get more complicated.
  513.     */
  514.  
  515.     if (t_type != LCURLY_TOK) {
  516.         fatal("pn_body: internal: called without opening {");
  517.     }
  518.     get_token();
  519.  
  520.     /* Parse the initial local definitions. */
  521.     if (t_type == ID_TOK) {
  522.         if (id = ast_lookup(t_symbol)) {
  523.             if (id -> st_sclass != TYPEDEF_CLASS) {
  524.                 id = NULL;
  525.             }
  526.         }
  527.     }
  528.     else {
  529.         id = NULL;
  530.     }
  531.  
  532.     if (is_kdecl(t_type) || id) {
  533.         b . locals = pd_stmt(DELEMENT_TYPE, TRUE, NULL);
  534.         b . lcl_size = pd_alloc(b . locals, 1);
  535.     }
  536.     else {
  537.         b . locals = 0;
  538.         b . lcl_size = 0;
  539.     }
  540.     intrn_decl = NULL;
  541.  
  542.     /* Parse the executable statements of the function body. */
  543.     b . parse = pn_list(FALSE);
  544.  
  545.     need(RCURLY_TOK);
  546.  
  547.     RETURN_PTR("pn_body", &b);
  548. }
  549.  
  550. /*
  551.     Parse an expression inside required parentheses
  552. */
  553. static struct node *
  554. parenexp(void)
  555. {
  556.     register struct node * p;
  557.  
  558.     TICKB("parenexp");
  559.  
  560.     need(LPAREN_TOK);
  561.     p = pe_expr();
  562.     (void) pe_check(p, XARITH_EXPR);
  563.     (void) needend(RPAREN_TOK);
  564.  
  565.     RETURN_PTR("parenexp", p);
  566. }
  567.  
  568.  
  569. /*
  570.     Parse a single statement--either one statement, terminated by ;
  571.     or else a {} enclosed group.
  572.  
  573.     Typically this statement is the consequence of a conditional.
  574.     In pl/68k, it must be a compound statement.
  575. */
  576. static struct node *
  577. pn_1stat(void)
  578. {
  579.     register struct node *p;
  580.  
  581.     TICKB("pn_1stat");
  582.  
  583.     if (t_type == LCURLY_TOK) {
  584.         get_token();
  585.         p = pn_list(FALSE);
  586.         need(RCURLY_TOK);
  587.         RETURN_PTR("pn_1stat", p);
  588.     }
  589.     else {
  590.         if (!full_c) {
  591.             need(LCURLY_TOK);
  592.         }
  593.         RETURN_PTR("pn_1stat", pn_list(TRUE));
  594.     }
  595. }
  596.  
  597. /*
  598.     Parse a single statement--either one statement, terminated by ;
  599.     or else a {} enclosed group.
  600. */
  601. static struct node *
  602. pn_1astat(void)
  603. {
  604.     register struct node *p;
  605.  
  606.     TICKB("pn_1astat");
  607.  
  608.     if (t_type == LCURLY_TOK) {
  609.         get_token();
  610.         p = pn_list(FALSE);
  611.         need(RCURLY_TOK);
  612.         RETURN_PTR("pn_1astat", p);
  613.     }
  614.     else {
  615.         if (!full_c) {
  616.             switch(t_type) {
  617.             case K_FOR:
  618.             case K_DO:
  619.             case K_WHILE:
  620.             case K_SWITCH:
  621.                 break;
  622.             default:
  623.                 need(LCURLY_TOK);
  624.             }
  625.         }
  626.         RETURN_PTR("pn_1astat", pn_list(TRUE));
  627.     }
  628. }
  629.  
  630. /*
  631.     Parse a list of statements, not including '{' and '}'.
  632.     This does NOT include a function argument list!!!
  633. */
  634. static struct node *
  635. pn_list(bool one_flag)
  636. {
  637.     register struct node * p;
  638.     struct node * head, * last;
  639.     char *s;
  640.  
  641.     /* No statements have been seen yet. */
  642.  
  643.     TRACEPB("pn_list", printf("(%d)\n", one_flag));
  644.  
  645.     last = NULL;
  646.     head = NULL;
  647.     p    = NULL;
  648.     goto around;
  649.  
  650. linkit:
  651.     TRACEP("pn_list", printf("last: %p head: %p\n", last, head));
  652.     pn_append(p, &last, &head);
  653.     TRACEP("pn_list", printf("last: %p head: %p\n", last, head));
  654.  
  655. next:
  656.     if (one_flag) {
  657.         RETURN_PTR("pn_list", head);
  658.     }
  659.  
  660. around:
  661.     switch(t_type) {
  662.  
  663.     case EOF_TOK:
  664.     case EOP_TOK:
  665.     case RCURLY_TOK:
  666.         RETURN_PTR("pn_list", head);
  667.  
  668.     case LCURLY_TOK:
  669.         p = pn_1stat();
  670.         goto linkit;
  671.  
  672.     case SEMICOLON_TOK:
  673.         get_token();
  674.         goto next;
  675.  
  676.     case K_BREAK:     p = pn_break();        goto linkit;
  677.     case K_CASE:     p = pn_case();            goto linkit;
  678.     case K_CONTINUE: p = pn_continue();        goto linkit;
  679.     case K_DEFAULT:     p = pn_default();        goto linkit;
  680.     case K_DO:     p = pn_do();            goto linkit;
  681.     case K_FOR:     p = pn_for();            goto linkit;
  682.     case K_GOTO:     p = pn_goto();            goto linkit;
  683.     case K_IF:     p = pn_if();            goto linkit;
  684.     case K_RETURN:     p = pn_return();        goto linkit;
  685.     case K_SWITCH:     p = pn_switch();        goto linkit;
  686.     case K_WHILE:     p = pn_while();        goto linkit;
  687.  
  688.     case X_TOK:     p = pn_x();            goto linkit;
  689.     case Z_TOK:      p = pn_z();            goto linkit;
  690.  
  691.     case ID_TOK:
  692.         /* Do character-oriented lookahead. */
  693.         skip_bl();
  694.         if (ch == ':') {
  695.             p = pn_label();
  696.             goto linkit;
  697.         }
  698.         goto expression;
  699.  
  700.     default:
  701.         if (is_kdecl(t_type)) {
  702.             fatal("declaration in code: check brace structure");
  703.         }
  704.     expression:
  705.         TRACEP("pn_list", printf("presumed expression\n"));
  706.         p = pe_expr();
  707.         (void) pe_check(p, ASSIGN_EXPR);
  708.         if (!needend(SEMICOLON_TOK)) {
  709.             goto around;
  710.         }
  711.         mark_noneed(p);
  712.         goto linkit;
  713.     }
  714. }
  715.  
  716. /*
  717.     C O M P L E X    S T A T E M E N T S.
  718. */
  719.  
  720. /*
  721.     Parse the "do" statement.
  722. */
  723. static struct node *
  724. pn_do(void)
  725. {
  726.     register struct node * oldcont;
  727.     register struct node * oldbrk;
  728.     register struct node * p;
  729.  
  730.     /* Read the "do" */
  731.  
  732.     TICKB("pn_do");
  733.  
  734.     get_token();
  735.  
  736.     /* Allocate data structures.    */
  737.     p =  new_pnode(sizeof(struct do_node));
  738.     p -> n_type = K_DO;
  739.  
  740.     /* Update reference lists. */
  741.     oldcont  = cont_ref;    cont_ref = p;
  742.     oldbrk   = brk_ref;    brk_ref  = p;
  743.  
  744.     /* Parse. */
  745.     p -> n_dbdy = pn_1stat();
  746.     need(K_WHILE);
  747.     p -> n_dbool = parenexp();
  748.  
  749.     /* Restore reference lists. */
  750.     cont_ref = oldcont;
  751.     brk_ref  = oldbrk;
  752.  
  753.     RETURN_PTR("pn_do", p);
  754. }
  755.  
  756. /*
  757.     Parse the "for" statement.
  758. */
  759. static struct node *
  760. pn_for(void)
  761. {
  762.     register struct node * oldcont;
  763.     register struct node * oldbrk;
  764.     register struct node * p;
  765.  
  766.     /* Read the "for" */
  767.  
  768.     TICKB("pn_for");
  769.  
  770.     get_token();
  771.  
  772.     /* Allocate data structures.    */
  773.     p =  new_pnode(sizeof(struct for_node));
  774.     p -> n_type = K_FOR;
  775.  
  776.     /* Update reference lists. */
  777.     oldcont = cont_ref;    cont_ref = p;
  778.     oldbrk  = brk_ref;    brk_ref  = p;
  779.  
  780.     /* Parse. */
  781.     need(LPAREN_TOK);
  782.     mark_noneed(p -> n_f1list = pe_list(ASSIGN_EXPR));
  783.  
  784.     if (t_type == SEMICOLON_TOK) {
  785.         get_token();
  786.         p -> n_fbool = pe_expr();
  787.         if (t_type == SEMICOLON_TOK) {
  788.             get_token();
  789.             mark_noneed(p -> n_f2list = pe_list(ASSIGN_EXPR));
  790.         }
  791.         else {
  792.             t_error("missing ; in for");
  793.         }
  794.     }
  795.     else {
  796.         t_error("missing ; in for");
  797.     }
  798.  
  799.     (void) needend(RPAREN_TOK);
  800.     p -> n_fbdy  = pn_1astat();
  801.  
  802.     /* Restore reference lists. */
  803.     cont_ref = oldcont;
  804.     brk_ref  = oldbrk;
  805.  
  806.     RETURN_PTR("pn_for", p);
  807. }
  808.  
  809. /*
  810.     Parse the "if" statement.
  811. */
  812. static struct node *
  813. pn_if(void)
  814. {
  815.     register struct node * p;
  816.  
  817.     /* Skip the "if" */
  818.  
  819.     TICKB("pn_if");
  820.  
  821.     get_token();
  822.  
  823.     /* Allocate data structures. */
  824.     p =  new_pnode(sizeof(struct if_node));
  825.     p -> n_type = K_IF;
  826.  
  827.     /* Parse. */
  828.     p -> n_ibool = parenexp();
  829.     p -> n_ithen = pn_1astat();
  830.     if (t_type == K_ELSE) {
  831.         get_token();
  832.         if (t_type == K_IF) {
  833.             /* else if is like a new keyword. */
  834.             p -> n_ielse = pn_list(TRUE);
  835.         }
  836.         else {                      
  837.             p -> n_ielse = pn_1stat();
  838.         }
  839.     }
  840.     else {
  841.         p -> n_ielse = NULL;
  842.     }
  843.     RETURN_PTR("pn_if", p);
  844. }
  845.  
  846. /*
  847.     Parse the "switch" statement.
  848. */
  849. static struct node *
  850. pn_switch(void)
  851. {
  852.     register struct node * oldswitch;
  853.     register struct node * oldbrk;
  854.     register struct node *p;
  855.     register struct node *p1;
  856.  
  857.     /* Read the "switch" */
  858.  
  859.     TICKB("pn_switch");
  860.  
  861.     get_token();
  862.  
  863.     /* Allocate data structures.    */
  864.     p =  new_pnode(sizeof(struct switch_node));
  865.     p -> n_type  = K_SWITCH;
  866.  
  867.     /* Update reference lists. */
  868.     oldswitch = sw_ref;    sw_ref  = p;
  869.     oldbrk    = brk_ref;    brk_ref = p;
  870.  
  871.     /* Parse expression and statement */
  872.     p -> n_sval = p1 = parenexp();
  873.     if (p1 && p1 -> n_cltype -> t_mclass & LONG_MOD) {
  874.         t_error("switch variable is long");
  875.     }
  876.     switch(t_type) {
  877.     case K_FOR:
  878.     case K_WHILE:
  879.     case K_DO:
  880.         t_help("structure right after switch is never initialized");
  881.         break;
  882.     case K_CASE:
  883.     case LCURLY_TOK:
  884.         break;
  885.     default:
  886.         t_warning("code right after switch is unreachable");
  887.     }
  888.  
  889.     /* if there's more structures before the body, fine */
  890.     p -> n_sbdy  = pn_1stat();
  891.  
  892.     sw_ref  = oldswitch;
  893.     brk_ref = oldbrk;
  894.  
  895.     RETURN_PTR("pn_switch", p);
  896. }
  897.  
  898. /*
  899.     Parse the "while" statement.
  900. */
  901. static struct node *
  902. pn_while(void)
  903. {
  904.     register struct node * oldcont;
  905.     register struct node * oldbrk;
  906.     register struct node * p;
  907.  
  908.     /* Read the "while" */
  909.  
  910.     TICKB("pn_while");
  911.  
  912.     get_token();
  913.  
  914.     /* Allocate data structures.    */
  915.     p =  new_pnode(sizeof(struct while_node));
  916.     p -> n_type = K_WHILE;
  917.  
  918.     /* Update reference lists. */
  919.     oldcont = cont_ref;    cont_ref = p;
  920.     oldbrk  = brk_ref;    brk_ref  = p;
  921.  
  922.     /* Parse. */
  923.     p -> n_wbool = parenexp();
  924.     p -> n_wbdy  = pn_1stat();
  925.  
  926.     /* Restore reference lists. */
  927.     cont_ref = oldcont;
  928.     brk_ref  = oldbrk;
  929.  
  930.     RETURN_PTR("pn_while", p);
  931. }
  932.  
  933. /*
  934.     S U B O R D I N A T E    S T A T E M E N T S.
  935. */
  936.  
  937. /*
  938.     Parse the "break" statement.
  939. */
  940. static struct node *
  941. pn_break(void)
  942. {
  943.     register struct node * p;
  944.  
  945.     /* Read the "break" */
  946.  
  947.     TICKB("pn_break");
  948.  
  949.     get_token();
  950.  
  951.     /* Make sure the break appears in a switch, do, while or for. */
  952.     if (brk_ref == NULL) {
  953.         t_error("break does not match any statement");
  954.         RETURN_PTR("pn_break", NULL);
  955.     }
  956.  
  957.     /* Allocate a break/continue node. */
  958.     p =  new_pnode(sizeof(struct bc_node));
  959.     p -> n_type     = K_BREAK;
  960.     p -> n_bcparent = brk_ref;
  961.  
  962.     need(SEMICOLON_TOK);
  963.  
  964.     RETURN_PTR("pn_break", p);
  965. }
  966.  
  967. /*
  968.     Parse the "case" statement.
  969. */
  970. static struct node *
  971. pn_case(void)
  972. {
  973.     register struct node *p, *p1, *p2;
  974.     register long con;
  975.  
  976.     /* Read the "case" */
  977.  
  978.     TICKB("pn_case");
  979.  
  980.     get_token();
  981.  
  982.     p1 = pe_expr();
  983.     if (pe_number(p1)) {
  984.         pe_retype(0, p1, K_CASE);
  985.     }
  986.     else {
  987.         t_error("case constant is not constant");
  988.     }
  989.  
  990.     /*
  991.         SEE K&R p. 211; the expression will be folded to an INT
  992.         primitive if and only if it is proper.  Expressions using
  993.         unary & are not proper--and in almost all cases will not
  994.         fold.
  995.     */
  996.  
  997.     /* Make sure we are in a switch body */
  998.     if (sw_ref == NULL) {
  999.         t_error("case appears outside of any switch");
  1000.         need(COLON_TOK);
  1001.         RETURN_PTR("pn_case", NULL);
  1002.     }
  1003.  
  1004.     /* Allocate a new case node. */
  1005.     p =  new_pnode(sizeof(struct case_node));
  1006.     p -> n_type = K_CASE;
  1007.     p -> n_ccon = con = p1 -> n_const;
  1008.  
  1009.     /* Check the case list for duplicate entries -- and find its end */
  1010.     if (p1 = sw_ref -> n_slist) {
  1011.         do {
  1012.             TRACEP("pn_case",
  1013.                   printf("check %p for duplicate\n", p1));
  1014.             if (p1 -> n_ccon == con) {
  1015.                 t_3serr(p1, "duplicate case","","");
  1016.                 break;
  1017.             }
  1018.             p2 = p1;
  1019.         }
  1020.         while (p1 = p1 -> n_clist);
  1021.  
  1022.         p2 -> n_clist = p;
  1023.     }
  1024.     else {
  1025.         sw_ref -> n_slist = p;
  1026.     }
  1027.     need(COLON_TOK);
  1028.  
  1029.     RETURN_PTR("pn_case", p);
  1030. }
  1031.         
  1032. /*
  1033.     Parse the "continue" statement.
  1034. */
  1035. static struct node *
  1036. pn_continue(void)
  1037. {
  1038.     register struct node * p;
  1039.  
  1040.     /* Read the "continue" */
  1041.  
  1042.     TICKB("pn_continue");
  1043.  
  1044.     get_token();
  1045.  
  1046.     /* Make sure the continue appears in a do, while or for. */
  1047.     if (cont_ref == NULL) {
  1048.         t_error("continue appears outside do, while and if");
  1049.         RETURN_PTR("pn_continue", NULL);
  1050.     }
  1051.  
  1052.     /* Allocate a break/continue node. */
  1053.     p =  new_pnode(sizeof(struct bc_node));
  1054.     p -> n_type     = K_CONTINUE;
  1055.     p -> n_bcparent = cont_ref;
  1056.  
  1057.     need(SEMICOLON_TOK);
  1058.  
  1059.     RETURN_PTR("pn_continue", p);
  1060. }
  1061.  
  1062. /*
  1063.     Parse the "default" statement.
  1064. */
  1065. static struct node *
  1066. pn_default(void)
  1067. {
  1068.     register struct node * p;
  1069.  
  1070.     /* Read the "default:" */
  1071.  
  1072.     TICKB("pn_default");
  1073.  
  1074.     get_token();
  1075.  
  1076.     /* Make sure we are in a switch statement. */
  1077.     if (sw_ref == NULL) {
  1078.         t_error("default appears outside of a switch");
  1079.         RETURN_PTR("pn_default", NULL);
  1080.     }
  1081.     if (sw_ref -> n_sdef) {
  1082.         t_error("duplicate default statement ignored");
  1083.         RETURN_PTR("pn_default", NULL);
  1084.     }
  1085.  
  1086.     /* Allocate a new case node. */
  1087.     p =  new_pnode(sizeof(struct case_node));
  1088.     p -> n_type = K_DEFAULT;
  1089.  
  1090.     /* Link it as the default field of the parent switch. */
  1091.     sw_ref -> n_sdef = p;
  1092.  
  1093.     need(COLON_TOK);
  1094.  
  1095.     RETURN_PTR("pn_default", p);
  1096. }
  1097.  
  1098. /*
  1099.     L A B E L S,     G O T O S     A N D     R E T U R N S.
  1100. */
  1101.  
  1102. /*
  1103.     Parse the "goto" statement.
  1104. */
  1105. static struct node *
  1106. pn_goto(void)
  1107. {
  1108.     register struct node * p;
  1109.     register struct lab_node *q;
  1110.  
  1111.     /* Read the "goto" */
  1112.  
  1113.     TICKB("pn_goto");
  1114.  
  1115.     get_token();
  1116.  
  1117.     /* Allocate a new plabel node. */
  1118.     if (t_type == ID_TOK) {
  1119.         p =  new_pnode(sizeof(struct plabel_node));
  1120.         p -> n_type = K_GOTO;
  1121.  
  1122.         /*
  1123.             Get a pointer to the label node.
  1124.             Local symbols hide global symbols.
  1125.         */
  1126.         q = ll_lookup(t_symbol);
  1127.         if (q == NULL) {
  1128.             q = gl_lookup(t_symbol);
  1129.             if (q == NULL) {
  1130.                 /*
  1131.                     Allocate a referenced but not defined
  1132.                     local label node.  Thus, all GLOBAL labels
  1133.                     must be defined before they are referenced.
  1134.                 */
  1135.                 q = ll_enter(t_symbol);
  1136.             }
  1137.         }
  1138.         p -> n_plab = q -> lab_label;
  1139.     }
  1140.     else {
  1141.         need(ID_TOK);
  1142.     }
  1143.  
  1144.     /* Read the symbol */
  1145.     get_token();
  1146.  
  1147.     (void) needend(SEMICOLON_TOK);
  1148.  
  1149.     RETURN_PTR("pn_goto", p);
  1150. }
  1151.  
  1152. /*
  1153.     Parse a user defined label.
  1154. */
  1155. static struct node *
  1156. pn_label(void)
  1157. {
  1158.     register struct node *p;
  1159.     register struct lab_node *q;
  1160.  
  1161.     TICKB("pn_label");
  1162.     TRACEP("pn_label", printf("(t_symbol: %s)\n", t_symbol));
  1163.  
  1164.     /* Allocate a new parse label node. */
  1165.     p =  new_pnode(sizeof(struct plabel_node));
  1166.     p -> n_type = LABEL_TOK;
  1167.  
  1168.     /* The label should not exist. */
  1169.     if (scope.s_scope == FILE_SCOPE) {
  1170.         q = gl_lookup(t_symbol);
  1171.     }
  1172.     else {
  1173.         q = ll_lookup(t_symbol);
  1174.     }
  1175.     if (q != NULL && q -> lab_defined == TRUE) {
  1176.         t_2error("duplicate label definition for: ", t_symbol);
  1177.         p -> n_plab = 0L;
  1178.     }
  1179.     else if (q != NULL) {
  1180.         q -> lab_defined = TRUE;
  1181.         p -> n_plab = q -> lab_label;
  1182.     }
  1183.     else {
  1184.         /* Allocate a new label node. */
  1185.         q = ll_enter(t_symbol);
  1186.         q -> lab_defined = TRUE;
  1187.         p -> n_plab = q -> lab_label;
  1188.     }
  1189.  
  1190.     /* Skip over the label. */
  1191.     get_token();
  1192.  
  1193.     need(COLON_TOK);
  1194.  
  1195.     RETURN_PTR("pn_label", p);
  1196. }
  1197.  
  1198. /*
  1199.     Parse the "return" statement.
  1200. */
  1201. static struct node *
  1202. pn_return(void)
  1203. {
  1204.     register struct node * p;
  1205.     register struct type_node *t;
  1206.  
  1207.     /* Read the "return" */
  1208.  
  1209.     TICKB("pn_return");
  1210.  
  1211.     get_token();
  1212.  
  1213.     /* Allocate data structures */
  1214.     p =  new_pnode(sizeof(struct ret_node));
  1215.     p -> n_type = K_RETURN;
  1216.  
  1217.     /* Access the return type */
  1218.     t = scope.s_fntype -> t_link;
  1219.  
  1220.     /* Parse an optional expression */
  1221.     if (t_type != SEMICOLON_TOK) {
  1222.         p -> n_rval = pe_expr();
  1223.         (void) pe_check(p -> n_rval, ANY_EXPR);
  1224.     }
  1225.  
  1226.     /* Check the expression */
  1227.     if (p -> n_rval == NULL) {
  1228.         if (t -> t_typtok != VOID_TYPE) {
  1229.             t_error("no return-value for function which has one");
  1230.         }
  1231.     }
  1232.     else {
  1233.         TRACE("pn_return",
  1234.             printf("pn_return: enclosing function:\n");
  1235.             pr_type(t);
  1236.             printf("return data:\n");
  1237.             pr_type(p -> n_rval -> n_cltype));
  1238.  
  1239.         if (pe_number(p -> n_rval)) {
  1240.             pe_massage(t, p -> n_rval, ASSN_TOK);
  1241.         }
  1242.         if (!pd_teq(t, p -> n_rval -> n_cltype)) {
  1243.             if (t -> t_typtok == VOID_TYPE) {
  1244.                 t_error("return-value for void function");
  1245.             }
  1246.             else {
  1247.                 t_error("type mismatch: returned type");
  1248.             }
  1249.         }
  1250.     }
  1251.     need(SEMICOLON_TOK);
  1252.  
  1253.     RETURN_PTR("pn_return", p);
  1254. }
  1255.  
  1256. /*
  1257.     E X T E N S I O N S.
  1258. */
  1259.  
  1260. /*
  1261.     Parse all machine language instructions.
  1262.     This IS different from pn_z.
  1263. */
  1264. static struct node *
  1265. pn_x(void)
  1266. {
  1267.     register int subtype;
  1268.     register struct node * p;
  1269.  
  1270.     TRACEPB("pn_x", printf("(t_subtype: %d)\n", t_subtype));
  1271.  
  1272.     /* Remember the subtype. */
  1273.     subtype = t_subtype;
  1274.  
  1275.     /* Parse the beginning of the pseudo function. */
  1276.     /* KLUDGE: character lookahead */
  1277.     skip_bl();
  1278.     if (ch != '(') {
  1279.         t_2warning(t_symbol, " is a pseudo function name");    
  1280.         get_token();
  1281.         need(LPAREN_TOK);    /* do nothing in some sense */
  1282.         if (t_type == COLON_TOK) {
  1283.             get_token();
  1284.         }
  1285.         RETURN_PTR("pn_x", NULL);
  1286.     }
  1287.     get_token();    /* put the paren up */
  1288.     get_token();    /* put the char after the paren up */
  1289.  
  1290.     /* Parse the inner expressions. */
  1291.     p = pn_x1(subtype);
  1292.  
  1293.     /* Parse the end of the pseudo function. */
  1294.     need(RPAREN_TOK);
  1295.     need(SEMICOLON_TOK);
  1296.  
  1297.     RETURN_PTR("pn_x", p);
  1298. }
  1299.  
  1300. /*
  1301.     CAUTION: by and large, allocation information is not available when
  1302.     this routine is executed.  This implies that address-mode existence
  1303.     checks cannot be done at this time, but must be done by gen_x.  Doing
  1304.     those checks later allows register names to be abstracted out, among
  1305.     other things.
  1306. */
  1307. static struct node *
  1308. pn_x1(register int subtype)
  1309. {
  1310.     register struct node * p;
  1311.     register struct node *p1;
  1312.     register struct lab_node *q;
  1313.  
  1314.     TRACEPB("pn_x1", printf("(%d)\n", subtype));
  1315.  
  1316.     switch (subtype) {
  1317.  
  1318.     case X_JMP:
  1319.     case X_JSR:
  1320.  
  1321.         TRACE("pn_x1", printf("pn_x1: JMP or JSR\n"));
  1322.  
  1323.         /* Allocate a new xtok_node. */
  1324.         p = new_pnode(sizeof(struct xtok_node));
  1325.         p -> n_type  = X_TOK;
  1326.         p -> n_xtype = subtype;
  1327.  
  1328.         /* We may have either a label or an expression here. */
  1329.         if (t_type == ID_TOK && t_subtype == 0) {
  1330.             /* We assume it is a label. */
  1331.             p -> n_arg2 = pn_xlab();
  1332.         }
  1333.         else {
  1334.             /* Expression instead of label. */
  1335.             p -> n_xarg1 = pe_expr();
  1336.         }
  1337.         RETURN_PTR("pn_x1", p);
  1338.             
  1339.     case X_DBCC:    case X_DBCS:    case X_DBEQ:
  1340.     case X_DBF :    case X_DBGE:    case X_DBGT:
  1341.     case X_DBHI:    case X_DBLE:    case X_DBLS:
  1342.     case X_DBLT:    case X_DBMI:    case X_DBNE:
  1343.     case X_DBPL:    case X_DBT:    case X_DBVC:
  1344.     case X_DBVS:
  1345.  
  1346.         TRACE("pn_x1", printf("pn_x1: DBxx\n"));
  1347.  
  1348.         /* Allocate a new xtok_node. */
  1349.         p = new_pnode(sizeof(struct xtok_node));
  1350.         p -> n_type  = X_TOK;
  1351.         p -> n_xtype = subtype;
  1352.  
  1353.         /* Get the first argument (not a label). */
  1354.         p -> n_xarg1 = pe_expr();
  1355.         need(COMMA_TOK);
  1356.         p -> n_arg2 = pn_xlab();
  1357.         RETURN_PTR("pn_x1", p);
  1358.  
  1359.     case X_BRA:    case X_BSR:
  1360.     case X_BCC:    case X_BCS:    case X_BEQ:
  1361.     case X_BGE:    case X_BGT:    case X_BHI:
  1362.     case X_BLE:    case X_BLS:    case X_BLT:
  1363.     case X_BMI:    case X_BNE:    case X_BPL:
  1364.     case X_BVC:    case X_BVS:
  1365.  
  1366.         TRACE("pn_x1", printf("pn_x1: BRA or Bxx\n"));
  1367.  
  1368.         /* Allocate a new xtok_node. */
  1369.         p = new_pnode(sizeof(struct xtok_node));
  1370.         p -> n_type  = X_TOK;
  1371.         p -> n_xtype = subtype;
  1372.         p -> n_arg1  = pn_xlab();
  1373.         RETURN_PTR("pn_x1", p);
  1374.  
  1375.     default:
  1376.  
  1377.         TRACE("pn_x1", printf("pn_x1: default\n"));
  1378.  
  1379.         /* Allocate a new xtok_node. */
  1380.         p = new_pnode(sizeof(struct xtok_node));
  1381.         p -> n_type  = X_TOK;
  1382.         p -> n_xtype = subtype;
  1383.  
  1384.         /* Instruction not involving a label. */
  1385.         p1 = pe_list(ARG_EXPR);
  1386.  
  1387.         /* Separate the zero, one or two arguments. */
  1388.         if (p1 && p1 -> n_type == SEPARATOR_TOK) {
  1389.             p -> n_xarg1 = p1 -> n_car;
  1390.             p1 = p1 -> n_next;
  1391.             if (p1 && p1 -> n_type == SEPARATOR_TOK) {
  1392.                 t_error("too many arguments in pseudo function.");
  1393.                 RETURN_PTR("pn_x1", NULL);
  1394.             }
  1395.             else {
  1396.                 p -> n_xarg2 = p1;
  1397.             }
  1398.         }
  1399.         else if (p1) {
  1400.             p -> n_xarg1 = p1;
  1401.             
  1402.         }
  1403.         if (
  1404.             (p -> n_xarg1 && p -> n_xarg1 -> n_type != ID_TOK) ||
  1405.             (p -> n_xarg2 && p -> n_xarg2 -> n_type != ID_TOK) 
  1406.                                     ) {
  1407.             t_error("pseudo function argument not a location");
  1408.         }
  1409.         RETURN_PTR("pn_x1", p);
  1410.     }
  1411. }
  1412.  
  1413. static struct node *
  1414. pn_xlab(void)
  1415. {
  1416.     register struct lab_node *p;
  1417.  
  1418.     TICKB("pn_xlab");
  1419.  
  1420.     if (t_type != ID_TOK || t_subtype != 0) {
  1421.         t_error("label expected");
  1422.         RETURN_PTR("pn_xlab", NULL);
  1423.     }
  1424.  
  1425.     /* Get a pointer to the label node. */
  1426.     if (scope.s_scope == FILE_SCOPE) {
  1427.         p = gl_lookup(t_symbol);
  1428.         if (p == NULL) {
  1429.             p = gl_enter(t_symbol);
  1430.         }
  1431.     }
  1432.     else {
  1433.         p = ll_lookup(t_symbol);
  1434.         if (p == NULL) {
  1435.             p = ll_enter(t_symbol);
  1436.         }
  1437.     }
  1438.  
  1439.     /* Skip over the symbol. */
  1440.     get_token();
  1441.  
  1442.     /* Return pointer to culabel_node. */
  1443.  
  1444.     RETURN_PTR("pn_xlab", p -> lab_label);
  1445. }
  1446.  
  1447. /*
  1448.     Parse all pseudo operations.
  1449. */
  1450. static struct node *
  1451. pn_z(void)
  1452. {
  1453.     register struct node * p;
  1454.     register int subtype;
  1455.  
  1456.     TRACEPB("pn_z", printf("(t_subtype: %d)\n", t_subtype));
  1457.  
  1458.     /* Remember the subtype. */
  1459.     subtype = t_subtype;
  1460.  
  1461.     /* Parse the beginning of the pseudo op */
  1462.     /* KLUDGE: character lookahead */
  1463.     skip_bl();
  1464.     if (ch != '(') {
  1465.         t_2warning(t_symbol, " is a pseudo operation name");        
  1466.         get_token();
  1467.         need(LPAREN_TOK);
  1468.         if (t_type == COLON_TOK) {
  1469.             get_token();
  1470.         }
  1471.         RETURN_PTR("pn_z", NULL);
  1472.     }
  1473.     get_token();
  1474.     get_token();
  1475.  
  1476.     /* Parse the inner expressions. */
  1477.     p = pn_z1(subtype);
  1478.  
  1479.     /* Parse the end of the pseudo function. */
  1480.     need(RPAREN_TOK);
  1481.     need(SEMICOLON_TOK);
  1482.  
  1483.     RETURN_PTR("pn_z", p);
  1484. }
  1485.  
  1486. static struct node *
  1487. pn_z1(register int subtype)
  1488. {
  1489.     register struct node *p;
  1490.  
  1491.     TRACEPB("pn_z1", printf("(%d)\n", subtype));
  1492.  
  1493.     if (subtype == Z_BASE) {
  1494.         /* Set the f_base global but create no node. */
  1495.         if (is_areg(subtype)) {
  1496.             f_base = subtype;
  1497.         }
  1498.         else {
  1499.             t_error("sp or a-register expected");
  1500.             f_base = 0;
  1501.         }
  1502.         RETURN_PTR("pn_z1", NULL);
  1503.     }
  1504.     else if (subtype == Z_NOBASE) {
  1505.         f_base = 0;
  1506.         RETURN_PTR("pn_z1", NULL);
  1507.     }
  1508.  
  1509.     /* All other pseudo operations generate a parse node. */
  1510.     p = new_pnode(sizeof(struct ztok_node));
  1511.     p -> n_type  = Z_TOK;
  1512.     p -> n_ztype = subtype;
  1513.  
  1514.     switch(subtype) {
  1515.  
  1516.     case Z_BSS:    case Z_DATA:    case Z_TEXT:
  1517.  
  1518.         RETURN_PTR("pn_z1", p);
  1519.  
  1520.     case Z_ORG:    case Z_PUSH:    case Z_POP:
  1521.     case Z_ADDSP:    case Z_ADJSP:    case Z_SUBSP:
  1522.  
  1523.         p -> n_zarg1 = pe_expr();
  1524.         RETURN_PTR("pn_z1", p);
  1525.  
  1526.     case Z_DC:    case Z_DCB:    case Z_DCW:    case Z_DCL:
  1527.     case Z_DS:    case Z_DSB:    case Z_DSW:    case Z_DSL:
  1528.  
  1529.         p -> n_zarg1 = pe_list(CONST_EXPR);
  1530.         RETURN_PTR("pn_z1", p);
  1531.  
  1532.     default:
  1533.         fatal("pn_z: unknown pseudo type");
  1534.     }
  1535.  
  1536.     TICKX("pn_z1");
  1537. }
  1538.  
  1539. /*
  1540.     L A B E L    S Y M B O L    T A B L E    R O U T I N E S.
  1541. */
  1542.  
  1543. /*
  1544.     Enter a symbol in the global label list and mark it undefined.
  1545. */
  1546. static struct lab_node *
  1547. gl_enter(char * symbol)
  1548. {
  1549.     register struct lab_node * p;
  1550.  
  1551.     /* Make a new entry entry in the global label list. */
  1552.  
  1553.     TRACEPB("gl_enter", printf("(%s)\n", symbol));
  1554.  
  1555.     p = CAST(struct lab_node *) ml_alloc(sizeof(struct lab_node));
  1556.     p -> lab_defined   = FALSE;
  1557.     p -> lab_label     = new_culabel(symbol);
  1558.  
  1559.     /* Link it to the head of the list. */
  1560.     p -> lab_next      = gl_head.lab_next;
  1561.     gl_head.lab_next   = p;
  1562.  
  1563.     RETURN_PTR("gl_enter", p);
  1564. }
  1565.  
  1566. /*
  1567.     Initialize the global label list table.
  1568.     This must be done only once per program.
  1569. */
  1570. static void
  1571. gl_init(void)
  1572. {
  1573.     TICK("gl_init");
  1574.  
  1575.     gl_head.lab_next = 0L;
  1576. }
  1577.  
  1578. /*
  1579.     Look up a symbol in the global label list.
  1580. */
  1581. static struct lab_node *
  1582. gl_lookup(char * symbol)
  1583. {
  1584.     register struct lab_node * p;
  1585.  
  1586.     TRACEPB("gl_lookup", printf("(%s)\n", symbol));
  1587.  
  1588.     for (p = gl_head.lab_next; p != NULL; p = p -> lab_next) {
  1589.         if (str_eq(symbol, p -> lab_label -> c_labsym)) {
  1590.             RETURN_PTR("gl_lookup", p);
  1591.         }
  1592.     }
  1593.     RETURN_PTR("gl_lookup", NULL);
  1594. }
  1595.  
  1596. /*
  1597.     Check the local label list table to see if any labels
  1598.     have been referenced but not defined.
  1599.     This should be done at the end of each function.
  1600. */
  1601. static void
  1602. ll_check(void)
  1603. {
  1604.     register struct lab_node * p;
  1605.  
  1606.     TICK("ll_check");
  1607.  
  1608.     for (p = ll_head.lab_next; p; p = p -> lab_next) {
  1609.         if (p -> lab_defined == FALSE) {
  1610.             t_2error("undefined label: ",
  1611.                         p -> lab_label -> c_labsym);
  1612.         }
  1613.     }
  1614. }
  1615.  
  1616. /*
  1617.     Enter a symbol in the local label list and mark it undefined.
  1618. */
  1619. static struct lab_node *
  1620. ll_enter(char * symbol)
  1621. {
  1622.     register struct lab_node * p;
  1623.  
  1624.     /* Make a new entry entry in the local label list. */
  1625.  
  1626.     TRACEPB("ll_enter", printf("(%s)\n", symbol));
  1627.  
  1628.     p = CAST(struct lab_node *) ml_alloc(sizeof(struct lab_node));
  1629.     p -> lab_defined   = FALSE;
  1630.     p -> lab_label     = new_culabel(symbol);
  1631.  
  1632.     /* Link it to the head of the list. */
  1633.     p -> lab_next      = ll_head.lab_next;
  1634.     ll_head.lab_next   = p;
  1635.  
  1636.     RETURN_PTR("ll_enter", p);
  1637. }
  1638.  
  1639. /*
  1640.     Initialize the local label list table.
  1641.     This must be done at the beginning of every function.
  1642. */
  1643. static void
  1644. ll_init(void)
  1645. {
  1646.     TICK("ll_init");
  1647.  
  1648.     ll_head.lab_next = 0L;
  1649. }
  1650.  
  1651. /*
  1652.     Look up a symbol in the local label list.
  1653. */
  1654. static struct lab_node *
  1655. ll_lookup(char * symbol)
  1656. {
  1657.     register struct lab_node * p;
  1658.  
  1659.     TRACEPB("ll_lookup", printf("(%s)\n", symbol));
  1660.  
  1661.     for (p = ll_head.lab_next; p != NULL; p = p -> lab_next) {
  1662.         if (str_eq(symbol, p -> lab_label -> c_labsym)) {
  1663.             RETURN_PTR("ll_lookup", p);
  1664.         }
  1665.     }
  1666.     RETURN_PTR("ll_lookup", NULL);
  1667. }
  1668.