Пример #1
0
void  LGCheckGrammar::p_prod (int p, int dot, char *before)
{
      int t, u, d;
		if (p < 0)
		{
			p = -p;
	      prt_log ("%s%s -> ", before, head_name [head_sym [p]]);
		}
		else
		{
			prt_log ("%s%5d %s -> ", before, p, head_name [head_sym [p]]);
		}
      t = f_tail [p];
      u = l_tail [p];
      d = t + dot;
      if (dot == -1) d = u;
      for (;;)
      {
         if (t == d) prt_sta (". ");
         if (t >= u) break;
         p_sym (tail [t], " ");
         t++;
      }
      prt_log ("\n");
}
Пример #2
0
void  PGPrintStates::PrintStates ()
{
      int t, h, s, n, x, p, i;

      if (optn[PG_STATELIST] > 1) return; // Already output once!

      prt_sta ("\nSTATE MACHINE LISTING:\n\n");
      if (!optn[PG_STATELIST])
		{
	      prt_sta ("'s' option was not specified.\n");
			return;
		}
      prt_sta ("      +=>  Shift and goto next state.\n");
      prt_sta ("      +<=  Shift and reduce.\n");
      prt_sta ("       <=  Reduce.\n\n");

      for (s = 0; s < n_states; s++)
      {
         PRT_STA (s);
         prt_sta ("\n");
         if (optn[PG_TRANSITIONS])
         {
				int na = 0;
            for (i = tt_start[s]; i < tt_start[s+1]; i++)
            {
					if (tt_action[i] != 0)
					{
						na++;
						x = tt_action [i];
						t = tt_symb [i];
						P_SYMBOL (t);
						if (x > 0) prt_sta (" +=> %4d\n", x);
					  	else       prt_sta (" +<= %4d\n", -x);
					}
            }
            if (optn[PG_NONDETER])
            {
               for (i = nd_start[s]; i < nd_start[s+1]; i++)
               {
						na++;
                  t = nd_term[i];
                  P_SYMBOL (t);
                  x = nd_action[i];
                  if (x > 0)
                  {
                     if (x > opt_states) prt_sta (" +<= %4d  nondeterministic\n",  x-opt_states);
                     else                prt_sta (" +=> %4d  nondeterministic\n",  x);
                  }
						else prt_sta ("  <= %4d  nondeterministic\n", -x);
               }
            }
            if (la_start != NULL)
            {
               for (i = la_start[s]; i < la_start[s+1]; i++)
               {
						na++;
                  t = la_symb [i];
                  P_SYMBOL (t);
                  x = la_red [i];
                  prt_sta ("  <= %4d\n", x);
               }
            }

				if (D_red == NULL)
				{
					for (int f = f_final[s]; f < f_final[s+1]; f++)
					{
						na++;
						p = item [final[f]].prod;
		            P_SYMBOL (-32767); // default
			         prt_sta ("  <= %4d\n", p);
					}
				}
				else
				{
					if ((p = D_red[s]) >= 0)
					{
						na++;
						P_SYMBOL (-32767); // default
						prt_sta ("  <= %4d\n", p);
					//	p_prod (p, -1, "", "\n");
					}
					else
					{
					// P_SYMBOL (-32768); // error
					// prt_sta ("\n");
					}
				}
				if (na > 0) prt_sta ("\n");

            n = 0;
            for (i = ntt_start[s]; i < ntt_start[s+1]; i++)
            {
					if (ntt_action[i] != 0)
					{
						n++;
						x = ntt_action [i];
						h = ntt_symb [i];
						P_HEAD (h);
						if (x > 0) prt_sta (" +=> %4d\n", x);
						else       prt_sta (" +<= %4d\n", -x);
					}
            }
				if (n > 0) prt_sta ("\n");

				if (f_camefrom[s+1] > f_camefrom[s])
				{
					prt_sta ("Came from:");
					for (i = f_camefrom[s]; i < f_camefrom[s+1]; i++)
					{
	               prt_sta (" %d", camefrom[i]);
					}
					prt_sta ("\n\n");
				}
         }
      }