Esempio n. 1
0
builtin_used ()
{
  int rule, alt, mem;
  for (rule = root; rule != laststdpred; rule = BROTHER (rule))
    for (alt = SON (rule); alt != nil; alt = BROTHER (alt))
      for (mem = SON (alt); mem != nil; mem = BROTHER (mem))
        if ((builtin == DEF (mem)) && !(TERMINAL (mem)))
          return true;
  return false;
}
Esempio n. 2
0
alias_used_builtins ()
{
  int rule, one_builtin_used = false;
  brother = laststdpred;
  for (builtin = laststdpred; builtin != nil; builtin = BROTHER (builtin))
    if ((builtin != cut) && (builtin != nestarset) &&
        (!mystrcmp (REPR (builtin), "select")) &&
        (builtin != tltraditionalterm) &&
        (builtin != transformlatticeterm) &&
        (builtin != tltraditional) &&
        (builtin != transformlattice) &&
        (builtin != skip) &&
        (builtin != explintersect) &&
        (builtin != getip) &&
        (builtin != falseip) &&
        (builtin != restoreip) &&
        (builtin != evalmeta) &&
        (builtin != initmeta) &&
        (builtin != evalmeta) && (builtin != resetinputptr) && (builtin != nestaralt) && (builtin != where))
    {
      int mem, alt;
      char *n, *m = REPR (builtin);
      if (!builtin_used ())
        continue;
      one_builtin_used = true;
      if (det_flag)
        if ((builtin == tltraditional) || (builtin == tltraditionalterm)
            || (mystrcmp (REPR (builtin), "select")) || (mystrcmp (REPR (builtin), "delete")))
          continue;
      make_new_rule (brother);
      new_rule = brother;

      n = (char *) malloc (strlen (m) + 7);
      if (n == NULL)
        fprintf (stderr, "glammar: Out of memory.\n"), exit (-1);
      strcpy (n, "built_"), strcpy (n + 6, m);
      REPR (new_rule) = n;
      SET (new_rule, external);
      PART (new_rule) = PART (root);
      for (rule = root; rule != laststdpred; rule = BROTHER (rule))
        for (alt = SON (rule); alt != nil; alt = BROTHER (alt))
          for (mem = SON (alt); mem != nil; mem = BROTHER (mem))
            if ((builtin == DEF (mem)) && !(TERMINAL (mem)))
            {
              DEF (mem) = new_rule;
              REPR (mem) = n;
            }
    }
  if (!one_builtin_used)
    return;
  for (rule = root; BROTHER (rule) != laststdpred; rule = BROTHER (rule));
  BROTHER (rule) = new_rule;
}
Esempio n. 3
0
static void outsym( PSYMBOL s ) { /* output a symbol or pick a rule */
	PPRODUCTION p;
	int pcount;
	int pnum;

	if (TERMINAL(s)) {
		outspacesym( s, 1, ' ' );
		outsymbol( s );
	} else { /* nonterminal symbol */

		/* how many alternatives are there? */
		pcount = 0;
		for (p = s->data; p != NULL; p = p->next) pcount++;

		/* pick an alternative */
		p = s->data;
		for (pnum = random() % pcount; pnum > 0; pnum--) {
			p = p->next;
		}

		/* output that alternative */
		outprod( p );
	}
}
Esempio n. 4
0
//                                                                           *
//---------------------------------------------------------------------------*

#define TERMINAL(t)     ((t)+1)
#define NONTERMINAL(nt) ((-nt)-1)
#define END_PRODUCTION  (0)

static const PMSInt16 gProductions [] = {
// At index 0 : <cfg_start>, in file 'cfg_syntax.ggs', line 38
  NONTERMINAL (3) // <select_cfg_5F_syntax_0>
, END_PRODUCTION
// At index 2 : <cfg_attrs>, in file 'cfg_syntax.ggs', line 104
, NONTERMINAL (4) // <select_cfg_5F_syntax_1>
, END_PRODUCTION
// At index 4 : <interrupts>, in file 'cfg_syntax.ggs', line 116
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken_interrupts) // $interrupts$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__5B_) // $[$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken_uint) // $uint$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__5D_) // $]$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__7B_) // ${$
, NONTERMINAL (5) // <select_cfg_5F_syntax_2>
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__7D_) // $}$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__3B_) // $;$
, END_PRODUCTION
//---- Added productions from 'select' and 'repeat' instructions
// At index 13 : <select_cfg_5F_syntax_0>, in file 'cfg_syntax.ggs', line 50
, END_PRODUCTION
// At index 14 : <select_cfg_5F_syntax_0>, in file 'cfg_syntax.ggs', line 50
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken_tp_5F_ns_5F_per_5F_counter_5F_tick) // $tp_ns_per_counter_tick$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken__3D_) // $=$
, TERMINAL (C_Lexique_cfg_5F_lexique::kToken_uint) // $uint$
Esempio n. 5
0
void deempty() { /* eliminate references to the empty symol */

	/* handles used in list traversals */
	PSYMBOL s;
	PPRODUCTION p;

	if (emptypt == NULL) {
		errormsg( "EMPTY SYMBOL MUST BE DEFINED", -1 );
		return; /* quit if no analysis possible */
	}

	/* apply initial markings on all symbols */
	for (s = symlist; s != NULL; s = s->next) {
		if (TERMINAL(s)) {
			/* most terminals are nonempty */
			s->state = NONEMPTY;
		} else {
			/* nonterminals and rules are empty until proven not */
			s->state = ISEMPTY;
			for (p = s->data; p != NULL; p = p->next) {
				p->state = ISEMPTY;
			}
		}
	}
	/* the distinguished empty symbol is the exceptional terminal */
	emptypt->state = ISEMPTY; 

	do { /* keep trying until no change is made to the grammar */
		change = false;

		for (s = symlist; s != NULL; s = s->next) if (NONTERMINAL(s)) {
			/* for each nonterminal symbol s */

			checkempty( s );
		}
	} while (change);

	/* now use the markup to rewrite rules accounting for emptyness */
	for (s = symlist; s != NULL; s = s->next) if (NONTERMINAL(s)) {
		/* for each nonterminal symbol s */

		cleanempty( s );
	}

	/* finally, deal with possible empty distinguished symbol */
	if (head->state == ISEMPTY) {
		/* eliminate the distinguished symbol and the empty symbol! */
		head = NULL;
		emptypt = NULL;
	} else if (head->state == CANBEEMPTY) {
		/* we eliminated a bit too much, put it back! */
		p = NEWPRODUCTION;
		p->data = NEWELEMENT;
		p->data->next = NULL;
		p->data->data = emptypt;
		p->next = head->data;
		head->data = p;
		/* do not eliminate the empty symbol! */
	} else /* head->state == NONEMPTY */ {
		/* eliminate the empty symbol! */
		emptypt = NULL;
	}
}