Пример #1
0
static void outprodgroup( PSYMBOL s ) { /* put out all rules with s on LHS */
	PPRODUCTION p;
	PELEMENT e;
	PSYMBOL ss;

	outline();
	outsymbol( s );
	outchar( ' ' );
	barcol = getoutcol() + 1; /* remember indent for next rule */
	outstring( RULESYM );
        contcol = getoutcol() + 1; /* remember indent for continuation */

	/* output first production on same line */
	p = s->data;
	outprod( p );

	while (p->next != NULL) { /* output successive productions */
		p = p->next;
		
		outline();
		outspaces( barcol );
		outstring( "| " );

		outprod( p );
	}

	if (s->starter != NULL) { /* output start set */
		outline();
		outchar( COMMENT );
		outstring( " start set:  " );
        	contcol = getoutcol() + 1; /* remember indent */

		for (e = s->starter; e != NULL; e = e->next) {
			ss = e->data;
			outspacesym( ss, contcol, COMMENT );
			outsymbol( ss );
		}
	}
	if (s->follows != NULL) { /* output follow set */
		outline();
		outchar( COMMENT );
		outstring( " follow set: " );
        	contcol = getoutcol() + 1; /* remember indent */

		for (e = s->follows; e != NULL; e = e->next) {
			ss = e->data;
			outspacesym( ss, contcol, COMMENT );
			outsymbol( ss );
		}
	}
	if ((s->follows != NULL) || (s->starter != NULL)) {
		/* output blank line to separate from the next rule */
		outline();
	}
}
Пример #2
0
void mexFunction(
   int nlhs, mxArray *plhs[],
   int nrhs, const mxArray *prhs[])
{
   /* ***************** */
   /* Declare variables */
   /* ***************** */
   double *A, *Aptr, *V, *Vptr, *temp;
   mwSize m, n, mm, mn, m1, i, N, j;
   /* ********************************************** */
   /* Determine input sizes and perform error checks */
   /* ********************************************** */
   if (nrhs<3 || nrhs>3)
     mexErrMsgTxt("Three arguments must be passed");
   if (nlhs>1)
     mexErrMsgTxt("ROWVECH produce only on  output");
   for (i=0; i<3; i++)
     if (!mxIsDouble(prhs[i]) || mxIsSparse(prhs[i]))
       mexErrMsgTxt("Inputs must be full double matrices");
   if (mxGetNumberOfElements(prhs[1])!=1)
     mexErrMsgTxt("m must be a scalar");
   if (mxGetNumberOfElements(prhs[2])!=1)
     mexErrMsgTxt("n must be a scalar");
   m=*mxGetPr(prhs[1]);
   n=*mxGetPr(prhs[2]);
   mm=m*m;
   mn=m*n;
   m1=m*(m+1)/2;
   if (mxGetN(prhs[0])!=mn)
     mexErrMsgTxt("Inputs are incompatible");
   N=mxGetM(prhs[0]);
   V=mxCalloc(N*m1,sizeof(double));
   A=mxCalloc(N*mn,sizeof(double));
   temp=mxCalloc(mm,sizeof(double));
   transpose(mxGetPr(prhs[0]),A,N,mn);  

   Vptr=V;
   Aptr=A;
   for(i=0; i<N; i++, Vptr+=m1, Aptr+=mn)
   {
     outprod(Aptr,temp,m,n);
     for (j=0; j<mm; j+=(m+1)) temp[j]/=2;
     vech(temp,Vptr,m,false);
   }
   mxFree(temp);
   mxFree(A);
   plhs[0]=mxCreateDoubleMatrix(N,m1,mxREAL);
   transpose(V,mxGetPr(plhs[0]),m1,N);
   mxFree(V);
}
Пример #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 );
	}
}