Ejemplo n.º 1
0
// Returns the next token in the character stream.
// If no next token can be identified, an error
// is emitted and we return the error token.
Token
Lexer::scan()
{
  // Consume any white space here.
  space();

  switch (peek()) {
    case 0: return eof();

    case '(': return lparen();
    case ')': return rparen();

    case '-':
      if (peek(1) == '>')
        return arrow();
      else
        return error();

    default:
      if (Token tok = identifier())
        return tok;
      else
        return error();
  }
}
Ejemplo n.º 2
0
static void do_stmt(void) {
	int	ls, lb, lc;

	Token = scan();
	ls = label();
	pushbrk(lb = label());
	pushcont(lc = label());
	genlab(ls);
	stmt();
	match(WHILE, "'while'");
	lparen();
	genlab(lc);
	rexpr();
	genbrtrue(ls);
	genlab(lb);
	rparen();
	semi();
	Bsp--;
	Csp--;
}
Ejemplo n.º 3
0
static void if_stmt(void) {
	int	l1, l2;

	Token = scan();
	lparen();
	rexpr();
	clear();
	rparen();
	l1 = label();
	genbrfalse(l1);
	stmt();
	if (ELSE == Token) {
		l2 = label();
		genjump(l2);
		genlab(l1);
		l1 = l2;
		Token = scan();
		stmt();
	}
	genlab(l1);
}
Ejemplo n.º 4
0
static void for_stmt(void) {
	int	ls, lbody, lb, lc;

	Token = scan();
	ls = label();
	lbody = label();
	pushbrk(lb = label());
	pushcont(lc = label());
	lparen();
	if (Token != SEMI) {
		rexpr();
		clear();
	}
	semi();
	genlab(ls);
	if (Token != SEMI) {
		rexpr();
		clear();
		genbrfalse(lb);
	}
	genjump(lbody);
	semi();
	genlab(lc);
	if (Token != RPAREN) {
		rexpr();
		clear();
	}
	genjump(ls);
	rparen();
	genlab(lbody);
	stmt();
	genjump(lc);
	genlab(lb);
	Bsp--;
	Csp--;
}
Ejemplo n.º 5
0
// Returns the next token in the character stream.
// If no next token can be identified, an error
// is emitted and we return the error token.
Token
Lexer::scan()
{
  // Keep consuming characters until we find
  // a token.
  while (true) {
    space();

    // Update the position of the current source location.
    // This denotes the beginning of the current token.
    loc_ = in_.location();

    switch (peek()) {
      case 0: return eof();

      case '{': return lbrace();
      case '}': return rbrace();
      case '(': return lparen();
      case ')': return rparen();
      case '[': return lbrack();
      case ']': return rbrack();
      case ',': return comma();
      case ':': return colon();
      case ';': return semicolon();
      case '.': return dot();
      case '+': return plus();
      case '-': return minus();
      case '*': return star();

      case '/':
        get();
        if (peek() == '/') {
          comment();
          continue;
        } else {
          return slash();
        }

      case '%': return percent();
      case '=': return equal();
      case '!': return bang();
      case '<': return langle();
      case '>': return rangle();
      case '&': return ampersand();
      case '|': return bar();
      case '^': return hat();

      case '0':
        // if the next character is a 'b' then this
        // is a binary literal
        if (peek(1) == 'b')
          return binary_integer();
        // if the next character is an 'x' then this
        // is a hexadecimal integer
        if (peek(1) == 'x')
          return hexadecimal_integer();
        // otherwise proceed to regular integer lexing
      case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        return integer();

      case 'a': case 'b': case 'c': case 'd': case 'e':
      case 'f': case 'g': case 'h': case 'i': case 'j':
      case 'k': case 'l': case 'm': case 'n': case 'o':
      case 'p': case 'q': case 'r': case 's': case 't':
      case 'u': case 'v': case 'w': case 'x': case 'y':
      case 'z':
      case 'A': case 'B': case 'C': case 'D': case 'E':
      case 'F': case 'G': case 'H': case 'I': case 'J':
      case 'K': case 'L': case 'M': case 'N': case 'O':
      case 'P': case 'Q': case 'R': case 'S': case 'T':
      case 'U': case 'V': case 'W': case 'X': case 'Y':
      case 'Z':
      case '_':
        return word();

      case '\'': return character();
      case '"': return string();

      default:
        return error();
    }
  }
}
Ejemplo n.º 6
0
static void act15()
{ 
		NLA = ENTRY_OPEN;
		lparen ();   
	}