prefix notation type parser
This commit is contained in:
parent
9b24c8a496
commit
9ac779c1cf
14 changed files with 1217 additions and 151 deletions
|
@ -1,53 +1,11 @@
|
|||
#ifndef _MSPH_EXPR_H
|
||||
#define _MSPH_EXPR_H
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include "msph/common.h"
|
||||
|
||||
/*
|
||||
* TYPES:
|
||||
* Conj
|
||||
* Disj
|
||||
* Impl
|
||||
* Arrow
|
||||
* Box
|
||||
* (Sub)
|
||||
* Forall
|
||||
*
|
||||
* True
|
||||
* False
|
||||
* Var
|
||||
* Nominal
|
||||
*
|
||||
* Record
|
||||
*
|
||||
* DEFINITIONS/DIRECTIVES:
|
||||
* Type definition (type A[X..] = T)
|
||||
* Nominal definition (nominal N)
|
||||
* Member definition (member mname : T)
|
||||
*
|
||||
* {
|
||||
* member a: A
|
||||
* member b: B
|
||||
* }
|
||||
*
|
||||
* Subtyping check (check A <: B, checks if A <: B)
|
||||
*
|
||||
* EXTRA DEFINITIONS
|
||||
* Class definition (class C[...] { ... }, shorthand)
|
||||
*
|
||||
* EXPRESSIONS
|
||||
* Conj
|
||||
* Disj
|
||||
* Impl
|
||||
* Arrow
|
||||
* Box
|
||||
* (Sub)
|
||||
* Forall
|
||||
*
|
||||
* True
|
||||
* False
|
||||
* Var
|
||||
* Nominal
|
||||
*
|
||||
* Trait ({ ... }, creates scoping)
|
||||
*
|
||||
*
|
||||
* TOKENS
|
||||
|
@ -79,16 +37,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
struct msph_ctx {
|
||||
int err;
|
||||
int err_info;
|
||||
char errbuf[SPHO_ERR_BUF_LEN];
|
||||
|
||||
#ifdef SPHO_DEBUG
|
||||
char filebuf[SPHO_ERR_FILEBUF_LEN];
|
||||
int errline;
|
||||
#endif
|
||||
};
|
||||
|
||||
enum msph_tok_type {
|
||||
TOK_LBRACE, // {
|
||||
|
@ -99,6 +47,8 @@ enum msph_tok_type {
|
|||
TOK_RPAREN, // )
|
||||
TOK_COLON, // :
|
||||
TOK_EQUALS, // =
|
||||
TOK_COMMA, // ,
|
||||
TOK_DOT, // .
|
||||
|
||||
TOK_AMP, // &
|
||||
TOK_PIPE, // |
|
||||
|
@ -109,7 +59,7 @@ enum msph_tok_type {
|
|||
TOK_KW_TYPE, // type
|
||||
TOK_KW_NOMINAL, // nominal
|
||||
TOK_KW_MEMBER, // member
|
||||
TOK_KW_CHECK, // check
|
||||
TOK_KW_ASSERT, // assert
|
||||
TOK_KW_BOX, // box
|
||||
TOK_KW_FORALL, // forall
|
||||
|
||||
|
@ -117,23 +67,20 @@ enum msph_tok_type {
|
|||
TOK_CONST_FALSE, // False
|
||||
|
||||
TOK_IDENT, // identifiers
|
||||
TOK_INVAL, // special: invalid, use to mark invalid toks
|
||||
TOK_WSPACE, // special: whitespace
|
||||
TOK_END // special: denote end of array
|
||||
};
|
||||
|
||||
#define MSPH_TOKEN_BUF_LEN 128
|
||||
|
||||
struct token_s {
|
||||
char buf[MSPH_TOKEN_BUF_LEN];
|
||||
};
|
||||
|
||||
union token_data {
|
||||
struct token_s s;
|
||||
union msph_token_data {
|
||||
char str[MSPH_IDENT_LEN];
|
||||
};
|
||||
|
||||
struct msph_token {
|
||||
int type;
|
||||
union token_data d;
|
||||
union msph_token_data data;
|
||||
|
||||
SLIST_ENTRY(msph_token) entries;
|
||||
};
|
||||
|
||||
#define MSPH_FILE_NAME_LEN 1024
|
||||
|
@ -147,9 +94,6 @@ struct msph_token_src_file {
|
|||
size_t pos;
|
||||
size_t end;
|
||||
char buf[MSPH_FILE_BUF_LEN];
|
||||
|
||||
/* file path */
|
||||
char name[MSPH_FILE_NAME_LEN];
|
||||
};
|
||||
|
||||
#define MSPH_TOKEN_SRC_STR 2
|
||||
|
@ -178,17 +122,21 @@ struct msph_token_stream {
|
|||
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);
|
||||
|
||||
int msph_token_stream_close(struct msph_token_stream*);
|
||||
|
||||
ssize_t msph_token_stream_read_tok(struct msph_token *, size_t,
|
||||
ssize_t msph_token_stream_read(struct msph_token *, size_t,
|
||||
struct msph_token_stream *);
|
||||
int msph_token_stream_eof(struct msph_token_stream *);
|
||||
int msph_token_stream_print(struct msph_token_stream *, FILE *);
|
||||
|
||||
ssize_t msph_token_str(char *buf, size_t len, struct msph_token *tok);
|
||||
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 *);
|
||||
|
||||
|
||||
#endif /* _MSPH_EXPR_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue