sic

The sic programming language, compiler and tools (WIP)
Log | Files | Refs

lexer.c (361B)


      1 #include "lexer.h"
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 static void
      6 add_token(Lexer *l, Token t)
      7 {
      8 	if (l->count >= l->cap) {
      9 		l->cap *= 2;
     10 		l->tokens = realloc(l->tokens, l->cap * sizeof(Token));
     11 	}
     12 
     13 	l->tokens[l->count++] = t;
     14 }
     15 
     16 Lexer *
     17 lexer_lex(Lexer *l)
     18 {
     19 	Token tok = { 0 };
     20 	l->tokens = calloc(250, sizeof(Token));
     21 	add_token(l, tok);
     22 	return l;
     23 }