core: Add lexer + parser groundwork
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_LEXER_H
|
||||
#define CESCAL_LEXER_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "cescal/token.h"
|
||||
#include "cescal/state.h"
|
||||
|
||||
/*
|
||||
* Consume a single token from the input source file
|
||||
*
|
||||
* @state: Compiler state
|
||||
* @res: Token result is written here
|
||||
*
|
||||
* Returns zero on success
|
||||
*/
|
||||
int lexer_nom(struct cescal_state *state, struct token *res);
|
||||
|
||||
#endif /* !CESCAL_LEXER_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_PARSER_H
|
||||
#define CESCAL_PARSER_H 1
|
||||
|
||||
#include "cescal/state.h"
|
||||
|
||||
/*
|
||||
* Begin parsing the input source file
|
||||
*
|
||||
* @state: Compiler state
|
||||
*
|
||||
* Returns zero on success
|
||||
*/
|
||||
int parser_parse(struct cescal_state *state);
|
||||
|
||||
#endif /* !CESCAL_PARSER_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_TOKEN_H
|
||||
#define CESCAL_TOKEN_H 1
|
||||
|
||||
/*
|
||||
* Represents valid source file token types
|
||||
*/
|
||||
typedef enum {
|
||||
TT_NONE, /* [none] */
|
||||
TT_IDENT, /* [identifier] */
|
||||
TT_INTLIT, /* [0-9]+ */
|
||||
TT_LPAREN, /* '(' */
|
||||
TT_RPAREN, /* '( */
|
||||
TT_COMMA, /* ',' */
|
||||
TT_RETURN, /* 'return' */
|
||||
TT_PUB, /* 'pub' */
|
||||
TT_PROC, /* 'proc' */
|
||||
TT_BEGIN, /* 'begin' */
|
||||
TT_END, /* 'end' */
|
||||
} tt_t;
|
||||
|
||||
/*
|
||||
* Represents a source file token
|
||||
*
|
||||
* @type: Token type
|
||||
*/
|
||||
struct token {
|
||||
tt_t type;
|
||||
union {
|
||||
char c;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* !CESCAL_TOKEN_H */
|
||||
Reference in New Issue
Block a user