Ejemplo n.º 1
0
int   PG::Main (int na, char** arg)
{
      if (Start (na, arg))
		{
			PGParser::initialize (optn[MAX_SYM]);
			if (PGParser::parse (input_start) > 0)
			{
				PrintGrammar();
				PrintHtml();
				if (CheckGrammar())
				{
					OutputLexicalSymbols();
					if (BuildLR1())  
					{
						if (ComputeLA())
						{
							if (OptimizeStates())
							{
								PrintStates();
								CreateTables();
								PG::Terminate (0);
								return 1;
							} 
						}
			      }
				}
			}
		}
		return 0;
}
Ejemplo n.º 2
0
int   LGCheckGrammar::CheckGrammar ()
{
	  	if (optn[LG_VERBOSE] > 2) printf ("Checking grammar for problems ...\n");	  

      C_LENG ();
      C_NULLS ();																	
      C_HEADSYM ();																	
		CHECK_LEXICALS ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for unreachable symbols ...\n");
      P_UNREACHABLES ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for undefined symbols ...\n");
      P_UNDEFINED ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for useless productions ...\n");
      P_USELESS_PROD ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for null tokens ...\n");
      P_NULL_TOKENS ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for unreducible symbols ...\n");
      P_UNREDUCIBLES ();
		if (n_errors) return 0;

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Checking for cycles in grammar ...\n");
		C_CYCLES();
		if (n_errors) return 0;

		FREE (head_sym, n_heads); // Free this, DO_BACK_SUB changes n_heads.

      prt_log ("Grammar  %7d rules, ", n_prods);
		prt_log ("%d terminals, ", max_char_set); 
      prt_log ("%d nonterminals.\n", n_heads);

      PrintGrammar ();
		if (n_errors > 0) return (0);

		FREE (head_type, n_heads);
		FREE (head_line, n_heads);
		FREE (prod_type, n_prods);
		FREE (prod_line, n_prods);
		FREE (term_line, n_terms);

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Doing back-substitutions for null symbols ...\n");

	  	DO_BACK_SUB ();

	  	if (optn[LG_VERBOSE] > 2)
	  	printf ("Done with back-substitutions !!!\n");
      if (optn[LG_VERBOSE] > 2) PrintGrammar (); // Printing grammar for 2nd time?
      return (1);
}