コード例 #1
0
ファイル: lib.c プロジェクト: alexanderkyte/sparse
static struct symbol_list *sparse_tokenstream(struct token *token)
{
	// Preprocess the stream
	token = preprocess(token);

	if (preprocess_only) {
		while (!eof_token(token)) {
			int prec = 1;
			struct token *next = token->next;
			const char *separator = "";
			if (next->pos.whitespace)
				separator = " ";
			if (next->pos.newline) {
				separator = "\n\t\t\t\t\t";
				prec = next->pos.pos;
				if (prec > 4)
					prec = 4;
			}
			printf("%s%.*s", show_token(token), prec, separator);
			token = next;
		}
		putchar('\n');

		return NULL;
	}

	// Parse the resulting C code
	while (!eof_token(token))
		token = external_declaration(token, &translation_unit_used_list);
	return translation_unit_used_list;
}
コード例 #2
0
ファイル: token.c プロジェクト: alexrvincent/CMPS-12B
token *new_token (FILE *file) {
   token *this = malloc (sizeof (token));
   assert (this != NULL);
   this->file = file;
   this->capacity = INIT_CAPACITY;
   this->buffer = malloc (this->capacity);
   assert (this->buffer != NULL);
   this->buffer[0] = '\0';
   this->size = 0;
   this->token = 0;
   DEBUGS ('t', show_token (this));
   return this;
}
コード例 #3
0
ファイル: lib.c プロジェクト: alexanderkyte/sparse
struct token *expect(struct token *token, int op, const char *where)
{
	if (!match_op(token, op)) {
		static struct token bad_token;
		if (token != &bad_token) {
			bad_token.next = token;
			sparse_error(token->pos, "Expected %s %s", show_special(op), where);
			sparse_error(token->pos, "got %s", show_token(token));
		}
		if (op == ';')
			return skip_to(token, op);
		return &bad_token;
	}
	return token->next;
}