98 lines
3.0 KiB
C
98 lines
3.0 KiB
C
#ifndef _AST_EXPR_EXPR_H_
|
|
#define _AST_EXPR_EXPR_H_
|
|
|
|
#include "../ctx.h"
|
|
#include "../node.h"
|
|
|
|
#include <blue/core/queue.h>
|
|
|
|
struct ivy_ast_node;
|
|
struct ivy_ast_msg_node;
|
|
|
|
enum expr_type {
|
|
EXPR_TYPE_NONE = 0,
|
|
/* if-else, while/for, match, etc (any expression that ends with an
|
|
* 'end' keyword */
|
|
EXPR_TYPE_STMT,
|
|
/* arithmetic and message-sending expressions (any expression that ends
|
|
* implicitly or with an expression separator */
|
|
EXPR_TYPE_ARITH,
|
|
};
|
|
|
|
enum expr_subtype {
|
|
EXPR_SUBTYPE_NONE = 0,
|
|
/* generic parenthesis-enclosed arithmetic expressions */
|
|
EXPR_SUBTYPE_PAREN,
|
|
/* keyword messages */
|
|
EXPR_SUBTYPE_KEYWORD_MSG,
|
|
/* expression delimited by labels */
|
|
EXPR_SUBTYPE_KEYWORD_ARG,
|
|
/* complex messages */
|
|
EXPR_SUBTYPE_COMPLEX_MSG,
|
|
};
|
|
|
|
enum expr_component {
|
|
EXPR_CMP_NONE = 0,
|
|
EXPR_CMP_OPERATOR,
|
|
EXPR_CMP_OPERAND,
|
|
EXPR_CMP_MSG,
|
|
};
|
|
|
|
struct expr_parser_state {
|
|
struct parser_state s_base;
|
|
enum expr_type s_type;
|
|
/* for arithmetic expressions, this records whether the previous
|
|
* component (either a token or parenthesised group of tokens) is an
|
|
* operator, operand, or message */
|
|
enum expr_component s_prev_component;
|
|
/* the token type/keyword type/symbol type of the last token that was
|
|
* encountered */
|
|
unsigned int s_prev_token;
|
|
/* if this is an arithmetic expression, this variable is the depth
|
|
* of parentheses that this sub-expression is at */
|
|
unsigned int s_paren_depth;
|
|
|
|
/* when this is set, the expression will be terminated when the
|
|
* specified token is encountered. the token that terminated the
|
|
* expression will not be consumed. */
|
|
unsigned int s_terminator;
|
|
|
|
/* all sub-expressions (i.e. those conatained within brackets,
|
|
* keyword-messages and keyword-message args, etc) will have this set/ */
|
|
enum expr_subtype s_subexpr;
|
|
|
|
b_queue s_output_queue;
|
|
b_queue s_operator_stack;
|
|
|
|
/* these variables are for keyword-message expressions */
|
|
struct ivy_ast_node *s_recipient;
|
|
struct ivy_ast_msg_node *s_msg;
|
|
b_queue s_labels;
|
|
b_queue s_args;
|
|
};
|
|
|
|
extern void arith_push_operator(
|
|
struct expr_parser_state *state, struct ivy_ast_node *node);
|
|
extern void arith_push_operand(
|
|
struct expr_parser_state *state, struct ivy_token *tok);
|
|
|
|
extern enum ivy_status arith_add_child(
|
|
struct parser_state *parent, struct ivy_ast_node *child);
|
|
|
|
extern struct token_parse_result arith_parse_ident(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_operand(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_operator(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_label(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_left_paren(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_right_paren(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
extern struct token_parse_result arith_parse_dot(
|
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
|
|
|
#endif
|