expression parser skeleton (look for @expr_parser comments)

This commit is contained in:
Allen Webster
2021-09-01 21:12:55 -07:00
parent a2766a2e0c
commit 131876018a
2 changed files with 100 additions and 3 deletions
+30
View File
@@ -2968,6 +2968,36 @@ MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags)
return result;
}
//~ Expression Parsing
MD_FUNCTION void
MD_ExprOperatorPush(MD_Arena *arena, MD_ExprOperatorList *list,
MD_u32 op_id, MD_ExprOperatorKind kind,
MD_u64 precedence, MD_Node *md_node){
MD_ExprOperatorNode *node = MD_PushArray(arena, MD_ExprOperatorNode, 1);
MD_QueuePush(list->first, list->last, node);
list->count += 1;
node->op.op_id = op_id;
node->op.kind = kind;
node->op.precedence = precedence;
node->op.md_node = md_node;
}
MD_FUNCTION MD_ExprOperatorTable
MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOperatorList *list){
MD_ExprOperatorTable result = {0};
// TODO(allen): @expr_parser
return(result);
}
MD_FUNCTION MD_ExprNode*
MD_ExprParse(MD_Arena *arena, MD_ExprOperatorTable *op_table,
MD_Node *first, MD_Node *one_past_last){
MD_ExprNode *result = 0;
// TODO(allen): @expr_parser
return(result);
}
//~ String Generation
MD_FUNCTION_IMPL MD_String8List
+70 -3
View File
@@ -404,13 +404,15 @@ struct MD_String8List
MD_String8Node *last;
};
typedef struct MD_StringJoin{
typedef struct MD_StringJoin MD_StringJoin;
struct MD_StringJoin
{
MD_String8 pre;
MD_String8 mid;
MD_String8 post;
} MD_StringJoin;
};
// NOTE(rjf): @maintenance These three enums must not overlap, and must share a flag space.
// NOTE(rjf): @maintenance These three flag types must not overlap.
typedef MD_u32 MD_MatchFlags;
typedef MD_u32 MD_StringMatchFlags;
typedef MD_u32 MD_NodeMatchFlags;
@@ -676,6 +678,58 @@ struct MD_ParseResult
MD_MessageList errors;
};
//~ Expression Parsing
typedef enum MD_ExprOperatorKind
{
MD_ExprOperatorKind_Prefix,
MD_ExprOperatorKind_Postfix,
MD_ExprOperatorKind_Binary,
} MD_ExprOperatorKind;
typedef struct MD_ExprOperator MD_ExprOperator;
struct MD_ExprOperator
{
MD_u32 op_id;
MD_ExprOperatorKind kind;
MD_u32 precedence;
MD_Node *md_node;
};
typedef struct MD_ExprOperatorNode MD_ExprOperatorNode;
struct MD_ExprOperatorNode
{
struct MD_ExprOperatorNode *next;
MD_ExprOperator op;
};
typedef struct MD_ExprOperatorList MD_ExprOperatorList;
struct MD_ExprOperatorList
{
MD_ExprOperatorNode *first;
MD_ExprOperatorNode *last;
MD_u64 count;
};
typedef struct MD_ExprOperatorTable MD_ExprOperatorTable;
struct MD_ExprOperatorTable
{
// TODO(allen): @expr_parser fill this in however needed
int foo;
};
typedef struct MD_ExprNode MD_ExprNode;
struct MD_ExprNode
{
struct MD_ExprNode *parent;
struct MD_ExprNode *left;
struct MD_ExprNode *right;
MD_b32 is_op;
MD_u32 op_id;
MD_Node *md_node;
MD_Node *md_op_node;
};
//~ String Generation Types
typedef MD_u32 MD_GenerateFlags;
@@ -737,6 +791,7 @@ struct MD_FileIter
MD_u8 opaque[640];
};
//~ Basic Utilities
#define MD_Assert(c) if (!(c)) { *(volatile MD_u64 *)0 = 0; }
@@ -1033,6 +1088,18 @@ MD_FUNCTION void MD_PrintNodeMessageFmt(FILE *file, MD_Node *node, MD_MessageKin
MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags);
MD_FUNCTION MD_b32 MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags);
//~ Expression Parsing
MD_FUNCTION void MD_ExprOperatorPush(MD_Arena *arena, MD_ExprOperatorList *list,
MD_u32 op_id, MD_ExprOperatorKind kind,
MD_u64 precedence, MD_Node *md_node);
MD_FUNCTION MD_ExprOperatorTable MD_ExprBakeOperatorTableFromList(MD_Arena *arena,
MD_ExprOperatorList *list);
MD_FUNCTION MD_ExprNode* MD_ExprParse(MD_Arena *arena, MD_ExprOperatorTable *op_table,
MD_Node *first, MD_Node *one_past_last);
//~ String Generation
MD_FUNCTION MD_String8List MD_DebugStringListFromNode(MD_Arena *arena, MD_Node *node, int indent, MD_String8 indent_string, MD_GenerateFlags flags);