diff --git a/Makefile b/Makefile index 11061ac..92b7bfa 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ build/utils/buffer.o: src/utils/buffer.c @$(ECHO) "CC\t\t"$< @$(CC) $(CFLAGS) $< -c -o $@ $(LIBS) +run: all + @$(OUT) tests/program.pinky + clean: @$(ECHO) "Cleaning..." @$(RM) -f $(FILES) $(OUT) diff --git a/src/lexer.c b/src/lexer.c index 83d6967..e1b284d 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -79,9 +79,7 @@ add_token (enum token_type type, struct lexer *l) if (!l) return; - unsigned int size = l->cur - l->start; - char *lexeme = calloc (size, sizeof (char)); - strncpy (lexeme, buffer_get (l->source) + l->start, size); + char *lexeme = buffer_slice (l->start, l->cur, l->source); vector_push_back (token_create_heap (type, l->line, lexeme), &l->tokens); free (lexeme); @@ -293,6 +291,9 @@ lexer_lex (struct lexer *l) handle_string (c, l); else if (isalpha (c) || c == '_') handle_identifier (l); + else + fprintf (stderr, "lexer_lex: unexpected character `%c' at line %d\n", + c, l->line); } } diff --git a/tests/program.pinky b/tests/program.pinky index 2e4a792..423399f 100644 --- a/tests/program.pinky +++ b/tests/program.pinky @@ -1,7 +1,7 @@ -- initialise variables pi := 3.141592 -x := 8.23 +x := 8.23 - -3.5 if x >= 0 then println ("x is positive")