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"$<
|
@$(ECHO) "CC\t\t"$<
|
||||||
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||||
|
|
||||||
|
run: all
|
||||||
|
@$(OUT) tests/program.pinky
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(ECHO) "Cleaning..."
|
@$(ECHO) "Cleaning..."
|
||||||
@$(RM) -f $(FILES) $(OUT)
|
@$(RM) -f $(FILES) $(OUT)
|
||||||
|
@ -79,9 +79,7 @@ add_token (enum token_type type, struct lexer *l)
|
|||||||
if (!l)
|
if (!l)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned int size = l->cur - l->start;
|
char *lexeme = buffer_slice (l->start, l->cur, l->source);
|
||||||
char *lexeme = calloc (size, sizeof (char));
|
|
||||||
strncpy (lexeme, buffer_get (l->source) + l->start, size);
|
|
||||||
|
|
||||||
vector_push_back (token_create_heap (type, l->line, lexeme), &l->tokens);
|
vector_push_back (token_create_heap (type, l->line, lexeme), &l->tokens);
|
||||||
free (lexeme);
|
free (lexeme);
|
||||||
@ -293,6 +291,9 @@ lexer_lex (struct lexer *l)
|
|||||||
handle_string (c, l);
|
handle_string (c, l);
|
||||||
else if (isalpha (c) || c == '_')
|
else if (isalpha (c) || c == '_')
|
||||||
handle_identifier (l);
|
handle_identifier (l);
|
||||||
|
else
|
||||||
|
fprintf (stderr, "lexer_lex: unexpected character `%c' at line %d\n",
|
||||||
|
c, l->line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
-- initialise variables
|
-- initialise variables
|
||||||
pi := 3.141592
|
pi := 3.141592
|
||||||
|
|
||||||
x := 8.23
|
x := 8.23 - -3.5
|
||||||
|
|
||||||
if x >= 0 then
|
if x >= 0 then
|
||||||
println ("x is positive")
|
println ("x is positive")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user