lexer finished?
This commit is contained in:
parent
52dc4618c7
commit
2119791961
3
Makefile
3
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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user