parsing prefix version (binary operators) of msph
This commit is contained in:
parent
7e5f080282
commit
17be15d7b5
12 changed files with 617 additions and 92 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "msph/err.h"
|
||||
|
||||
#define MSPH_IDENT_LEN 128
|
||||
#define MSPH_NAME_LEN 1024
|
||||
|
||||
struct msph_ctx {
|
||||
int err;
|
||||
|
@ -15,4 +16,10 @@ struct msph_ctx {
|
|||
int errline;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct msph_text_pos {
|
||||
unsigned int line;
|
||||
unsigned int col;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
#ifndef _MSPH_ERR_H
|
||||
#define _MSPH_ERR_H
|
||||
|
||||
#ifdef SPHO_DEBUG
|
||||
// #define SPHO_ENABLE_DEBUG_PRINT
|
||||
#endif
|
||||
|
||||
#include "spho/err.h"
|
||||
|
||||
|
||||
#define MSPH_ERR_SYS 0x0001
|
||||
|
||||
#define MSPH_ERR_INVAL 0x0002
|
||||
#define MSPH_ERR_TOOLONG 0x0003
|
||||
|
||||
#define MSPH_ERR_TOKEN_TOOLONG 0x1001
|
||||
#define MSPH_ERR_TOKEN_EOF 0x1002
|
||||
|
|
|
@ -69,15 +69,18 @@ enum msph_tok_type {
|
|||
TOK_IDENT, // identifiers
|
||||
TOK_INVAL, // special: invalid, use to mark invalid toks
|
||||
TOK_WSPACE, // special: whitespace
|
||||
TOK_END // special: denote end of array
|
||||
TOK_END // special: end of array/token stream
|
||||
};
|
||||
|
||||
#define MSPH_TAB_WIDTH 8
|
||||
|
||||
union msph_token_data {
|
||||
char str[MSPH_IDENT_LEN];
|
||||
};
|
||||
|
||||
struct msph_token {
|
||||
int type;
|
||||
struct msph_text_pos pos;
|
||||
union msph_token_data data;
|
||||
|
||||
SLIST_ENTRY(msph_token) entries;
|
||||
|
@ -110,21 +113,23 @@ union msph_token_src_data {
|
|||
|
||||
struct msph_token_src {
|
||||
int type;
|
||||
struct msph_text_pos pos;
|
||||
union msph_token_src_data inner;
|
||||
};
|
||||
|
||||
struct msph_token_stream {
|
||||
struct msph_ctx *ctx;
|
||||
|
||||
char name[MSPH_NAME_LEN];
|
||||
struct msph_token_src src;
|
||||
};
|
||||
|
||||
void msph_ctx_init(struct msph_ctx *);
|
||||
|
||||
struct msph_token_stream *msph_token_stream_file(struct msph_ctx *,
|
||||
FILE *);
|
||||
const char *, FILE *);
|
||||
struct msph_token_stream *msph_token_stream_frombuf(struct msph_ctx *,
|
||||
const char *, size_t);
|
||||
const char *, const char *, size_t);
|
||||
|
||||
int msph_token_stream_close(struct msph_token_stream*);
|
||||
|
||||
|
@ -135,8 +140,7 @@ int msph_token_stream_print(struct msph_token_stream *, FILE *);
|
|||
|
||||
ssize_t msph_token_str(char *, size_t, struct msph_token *);
|
||||
|
||||
struct msph_token * msph_token_create(struct msph_ctx *, int,
|
||||
union msph_token_data *);
|
||||
struct msph_token * msph_token_copy(struct msph_ctx *, struct msph_token *);
|
||||
|
||||
|
||||
#endif /* _MSPH_EXPR_H */
|
||||
|
|
|
@ -55,7 +55,8 @@
|
|||
* Trait ({ ... }, creates scoping)
|
||||
*/
|
||||
|
||||
#define MSPH_TREE_ROOT 0x0001
|
||||
#define MSPH_TREE_ROOT 0x0000
|
||||
#define MSPH_TREE_UNIT 0x0001
|
||||
|
||||
#define MSPH_TREE_BODY 0x0010
|
||||
|
||||
|
@ -83,11 +84,12 @@
|
|||
|
||||
|
||||
struct msph_tree {
|
||||
struct msph_tree *parent;
|
||||
int type;
|
||||
struct msph_tree *parent;
|
||||
};
|
||||
|
||||
struct msph_tree_root;
|
||||
struct msph_tree_text;
|
||||
struct msph_tree_body;
|
||||
struct msph_tree_dir;
|
||||
struct msph_tree_tpdef;
|
||||
|
@ -100,7 +102,21 @@ struct msph_tree_root {
|
|||
struct msph_tree tr;
|
||||
|
||||
struct msph_ctx *ctx;
|
||||
|
||||
STAILQ_HEAD(msph_tree_unit_l, msph_tree_unit) head;
|
||||
};
|
||||
|
||||
struct msph_tree_unit {
|
||||
struct msph_tree tr;
|
||||
|
||||
char name[MSPH_NAME_LEN];
|
||||
struct msph_tree_body *body;
|
||||
STAILQ_ENTRY(msph_tree_unit) entries;
|
||||
};
|
||||
|
||||
struct msph_tree_text {
|
||||
struct msph_tree tr;
|
||||
struct msph_text_pos pos;
|
||||
};
|
||||
|
||||
struct msph_tree_body {
|
||||
|
@ -236,4 +252,6 @@ struct msph_tree_root *msph_tree_makeroot(struct msph_ctx *);
|
|||
|
||||
int msph_tree_parse(struct msph_token_stream *, struct msph_tree_root *);
|
||||
|
||||
ssize_t msph_tree_fprint(FILE *, struct msph_tree *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
#define SPHO_PRECOND(cond)
|
||||
#define SPHO_ASSERT(cond)
|
||||
#define SPHO_POSTCOND(cond)
|
||||
|
||||
#define SPHO_DEBUG_PRINT(fmt, ...)
|
||||
|
||||
#endif /* SPHO_DEBUG */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue