示例#1
0
static Token *op(int ch) {
    Token *t = &tok;
    int ch2;

    switch (ch) {
       case '/':
          outch(ch);
          ch2 = nextch();
          if (ch2 == '*' || ch2 == '/') {
             return cmt(ch2);
          }
          backch(ch2);
          break;
       case '+':
       case '-':
       case '*':
       case '%':
       case '=':
          outch(ch);
          break;
       default: 
          t->sym == ERROR;
          t->ival = 0;
          return t;
    }

    t->sym = OP;
    t->ival = ch;
    outch(0);
    return t;
}
示例#2
0
static Token *lit(int ch) {
    Token *t = &tok;
    int d = 0;
    int v = 0;
    int b = 10;

    outch(ch);
    v = hexval(ch);

    if (ch == '0') {
        b = 8;
        ch = nextch();
        if (ch == 'x') {
            b = 16; 
	    outch(ch);
        } else 
            backch(ch);
    }

    while (true) {
       ch = nextch();
       d  = hexval(ch);
       switch (codeof(ch)) {
          case '0': case '9':
             if (d < b) {
                 outch(ch);
                 v = v * b + d;
                 continue;
             }
          case 'Z':
             if (b == 16 && d < b) {
                 outch(ch);
                 v = v * b + d;
                 continue;
             }
          default: break;
       }
       backch(ch); 
       break;
    }

    t->sym = LIT;
    t->ival = v;
    outch(0);
    return t;
}
示例#3
0
static Token *id(int ch) {
    Token *t = &tok;

    outch(ch);
    while (true) {
       ch = nextch();
       switch (codeof(ch)) {
          case 'Z': case '0': case '9':
	     outch(ch);
             continue;
          default: break;
       }
       backch(ch); 
       break;
    }
    t->sym = ID;
    outch(0);
    return t;
}
示例#4
0
// Match closing fences against their partners, and if on screen, briefly light the cursor there.
int fmatch(int ch) {
	Dot odot;		// Original line pointer and offset.
	Line *toplp;		// Top line in current window.
	int count;		// Current fence level count.
	int opench;		// Open fence.
	int c;			// Current character in scan.
	WindFace *wfp = &curwp->w_face;

	// Skip this if executing a script or a keyboard macro.
	if((opflags & OPSCRIPT) || kmacro.km_state == KMPLAY)
		return rc.status;

	// First get the display update out there.
	if(update(false) != SUCCESS)
		return rc.status;

	// Save the original cursor position.
	odot = wfp->wf_dot;

	// Set up proper open fence for passed close fence.
	switch(ch) {
		case ')':
			opench = '(';
			break;
		case '}':
			opench = '{';
			break;
		default:	// ']'
			opench = '[';
		}

	// Get top line of window and set up for scan.
	toplp = lback(wfp->wf_toplnp);
	count = 1;
	(void) backch(1);

	// Scan back until we find it, or move past the top of the window.
	while(count > 0 && wfp->wf_dot.lnp != toplp) {
		(void) backch(1);
		if(wfp->wf_dot.off == lused(wfp->wf_dot.lnp))
			c = '\n';
		else
			c = lgetc(wfp->wf_dot.lnp,wfp->wf_dot.off);
		if(c == ch)
			++count;
		else if(c == opench)
			--count;
		if(wfp->wf_dot.lnp == lforw(curbp->b_hdrlnp) && wfp->wf_dot.off == 0)
			break;
		}

	// If count is zero, we have a match -- display the sucker.
	if(count == 0) {
		if(update(false) != SUCCESS)
			return rc.status;
		cpause(fencepause);
		}

	// Restore the previous position.
	wfp->wf_dot = odot;

	return rc.status;
	}