Fixed some things.
This commit is contained in:
parent
aae8402403
commit
6f283c1d12
@ -8,20 +8,20 @@
|
|||||||
|
|
||||||
// What the lexer is currently looking at.
|
// What the lexer is currently looking at.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LEXER_STATE_CONFUSED, // Can't decide what it's looking at (also initial
|
LEXER_STATE_CONFUSED, // Can't decide what it's looking at (also initial
|
||||||
// state).
|
// state).
|
||||||
LEXER_STATE_NUM, // Looking at a number.
|
LEXER_STATE_NUM, // Looking at a number.
|
||||||
LEXER_STATE_CALL, // Looking at a call.
|
LEXER_STATE_CALL, // Looking at a call.
|
||||||
} LexerState;
|
} LexerState;
|
||||||
|
|
||||||
// Lexer: converts text to tokens.
|
// Lexer: converts text to tokens.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* src; // The source text.
|
char* src; // The source text.
|
||||||
size_t srcl; // The number of source chars.
|
size_t srcl; // The number of source chars.
|
||||||
char* cchar; // The current character.
|
char* cchar; // The current character.
|
||||||
Token** tokens; // The tokens produced.
|
Token** tokens; // The tokens produced.
|
||||||
size_t ntokens; // The number of tokens.
|
size_t ntokens; // The number of tokens.
|
||||||
LexerState state; // What the lexxer is looking at.
|
LexerState state; // What the lexxer is looking at.
|
||||||
} Lexer;
|
} Lexer;
|
||||||
|
|
||||||
// Create a lexer.
|
// Create a lexer.
|
||||||
|
@ -10,21 +10,4 @@
|
|||||||
// - Expression 1
|
// - Expression 1
|
||||||
// - Expression 2
|
// - Expression 2
|
||||||
|
|
||||||
typedef enum OpType {
|
|
||||||
OPTYPE_PLUS,
|
|
||||||
OPTYPE_MINUS
|
|
||||||
} optype_t;
|
|
||||||
|
|
||||||
typedef union Exp {
|
|
||||||
typedef struct Op {
|
|
||||||
optype_t type;
|
|
||||||
Exp* exp1;
|
|
||||||
Exp* exp2;
|
|
||||||
} op_t;
|
|
||||||
|
|
||||||
int n;
|
|
||||||
} exp_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
#ifndef UTIL_H
|
|
||||||
#define UTIL_H
|
|
||||||
|
|
||||||
// Utilies.
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// Exit with an error. Returns int for ease of use, but should be treated as void.
|
|
||||||
int die(char* msg);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +1,3 @@
|
|||||||
#include "include/util.h"
|
#include "include/util.h"
|
||||||
|
|
||||||
int is_even(int n) {
|
int is_even(int n) { return !(n % 2); }
|
||||||
return !(n%2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user