quip: Add initial lexer sources + example ref
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
19
include/frontend/lexer.h
Normal file
19
include/frontend/lexer.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef FRONTEND_LEXER_H
|
||||
#define FRONTEND_LEXER_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "frontend/token.h"
|
||||
#include "common/state.h"
|
||||
|
||||
/*
|
||||
* Scan for a single token within the source file
|
||||
*
|
||||
* @state: Quip state
|
||||
* @tokres: Token result is written here
|
||||
*
|
||||
* Returns zero on success
|
||||
*/
|
||||
int lexer_scan(struct quip_state *state, struct token *tokres);
|
||||
|
||||
#endif /* !FRONTEND_LEXER_H */
|
||||
36
include/frontend/token.h
Normal file
36
include/frontend/token.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* Provided under the BSD-3 clause
|
||||
*
|
||||
* Abstract:
|
||||
* This file defines the list of valid tokens.
|
||||
* Author:
|
||||
* Ian M. Moffett <ian@mirocom.org>
|
||||
*/
|
||||
|
||||
#ifndef FRONTEND_TOKEN_H
|
||||
#define FRONTEND_TOKEN_H 1
|
||||
|
||||
/*
|
||||
* Represents valid token types
|
||||
*/
|
||||
typedef enum {
|
||||
TT_NONE, /* [none] */
|
||||
TT_NAME, /* [name] */
|
||||
TT_NEWLINE, /* [newline] */
|
||||
TT_COLON, /* ':' */
|
||||
} tt_t;
|
||||
|
||||
/*
|
||||
* Represents a lexical token
|
||||
*
|
||||
* @type: Token type
|
||||
*/
|
||||
struct token {
|
||||
tt_t type;
|
||||
union {
|
||||
char c;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* !FRONTEND_TOKEN_H */
|
||||
Reference in New Issue
Block a user