Beispiel #1
0
struct lexer_book *lexer_init_book(int type, void *data, int line_number, int column_number)
{
    struct lexer_book *bk = malloc(sizeof(struct lexer_book));

    bk->line_number = line_number;
    bk->column_number = column_number;
    bk->column_numbers = list_create(0);

    bk->stream = NULL;
    bk->buffer = NULL;
    bk->eof = 0;

    bk->lexeme = calloc(BUFFER_CHUNK_SIZE, sizeof(char));
    bk->lexeme_size = 0;
    bk->lexeme_max = BUFFER_CHUNK_SIZE;

    bk->token_queue = list_create(0);

    bk->buffer = calloc(2 * BUFFER_CHUNK_SIZE, sizeof(char));
    if(!bk->buffer)
        fatal("Could not allocate memory for input buffer.\n");

    bk->lexeme_end = (bk->buffer + 2 * BUFFER_CHUNK_SIZE - 2);

    if(type == STREAM) {
        bk->stream = (FILE *) data;

        bk->chunk_last_loaded = 2;	// Bootstrap load_chunk to load chunk 1.
        lexer_load_chunk(bk);
    } else {
        lexer_load_string(bk, (char *) data);
    }

    return bk;
}
Beispiel #2
0
struct lexer *lexer_create(int type, void *data, int line_number, int column_number)
{
	struct lexer *lx = malloc(sizeof(struct lexer));

	lx->line_number = line_number;
	lx->column_number = column_number;
	lx->column_numbers = list_create(0);

	lx->stream = NULL;
	lx->buffer = NULL;
	lx->eof = 0;

	lx->depth = 0;

	lx->lexeme = calloc(BUFFER_CHUNK_SIZE, sizeof(char));
	lx->lexeme_size = 0;
	lx->lexeme_max = BUFFER_CHUNK_SIZE;

	lx->token_queue = list_create(0);

	lx->buffer = calloc(2 * BUFFER_CHUNK_SIZE, sizeof(char));
	if(!lx->buffer)
		fatal("Could not allocate memory for input buffer.\n");

	lx->lexeme_end = (lx->buffer + 2 * BUFFER_CHUNK_SIZE - 2);

	if(type == STREAM) {
		lx->stream = (FILE *) data;

		lx->chunk_last_loaded = 2;	// Bootstrap load_chunk to load chunk 1.
		lexer_load_chunk(lx);
	} else {
		lexer_load_string(lx, (char *) data);
	}

	return lx;
}