Finish Chapter 16
Implement basic parsing / scanner Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
6
include/compiler.h
Normal file
6
include/compiler.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef clox_compiler_h
|
||||
#define clox_compiler_h
|
||||
|
||||
void compile(const char *source);
|
||||
|
||||
#endif /* clox_compiler_h */
|
||||
62
include/scanner.h
Normal file
62
include/scanner.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef clox_scanner_h
|
||||
#define clox_scanner_h
|
||||
|
||||
typedef enum {
|
||||
// Single-character tokens.
|
||||
TOKEN_LEFT_PAREN,
|
||||
TOKEN_RIGHT_PAREN,
|
||||
TOKEN_LEFT_BRACE,
|
||||
TOKEN_RIGHT_BRACE,
|
||||
TOKEN_COMMA,
|
||||
TOKEN_DOT,
|
||||
TOKEN_MINUS,
|
||||
TOKEN_PLUS,
|
||||
TOKEN_SEMICOLON,
|
||||
TOKEN_SLASH,
|
||||
TOKEN_STAR,
|
||||
// One or two character tokens.
|
||||
TOKEN_BANG,
|
||||
TOKEN_BANG_EQUAL,
|
||||
TOKEN_EQUAL,
|
||||
TOKEN_EQUAL_EQUAL,
|
||||
TOKEN_GREATER,
|
||||
TOKEN_GREATER_EQUAL,
|
||||
TOKEN_LESS,
|
||||
TOKEN_LESS_EQUAL,
|
||||
// Literals.
|
||||
TOKEN_IDENTIFIER,
|
||||
TOKEN_STRING,
|
||||
TOKEN_NUMBER,
|
||||
// Keywords.
|
||||
TOKEN_AND,
|
||||
TOKEN_CLASS,
|
||||
TOKEN_ELSE,
|
||||
TOKEN_FALSE,
|
||||
TOKEN_FOR,
|
||||
TOKEN_FUN,
|
||||
TOKEN_IF,
|
||||
TOKEN_NIL,
|
||||
TOKEN_OR,
|
||||
TOKEN_PRINT,
|
||||
TOKEN_RETURN,
|
||||
TOKEN_SUPER,
|
||||
TOKEN_THIS,
|
||||
TOKEN_TRUE,
|
||||
TOKEN_VAR,
|
||||
TOKEN_WHILE,
|
||||
|
||||
TOKEN_ERROR,
|
||||
TOKEN_EOF
|
||||
} TokenType;
|
||||
|
||||
typedef struct {
|
||||
TokenType type;
|
||||
const char *start;
|
||||
int length;
|
||||
int line;
|
||||
} Token;
|
||||
|
||||
void initScanner(const char *source);
|
||||
Token scanToken();
|
||||
|
||||
#endif /* clox_scanner_h */
|
||||
@@ -21,7 +21,7 @@ typedef enum {
|
||||
void initVM();
|
||||
void freeVM();
|
||||
|
||||
InterpretResult interpret(Chunk *chunk);
|
||||
InterpretResult interpret(const char *source);
|
||||
void push(Value value);
|
||||
Value pop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user