# pragma once #include "utils.h" typedef enum { PLUS, MINUS, MULT, DIV, } BinOp; typedef enum { ARITHM_INT_LIT, ARITHM_BINOP, } ArithmNodeKind; typedef struct ArithmNode ArithmNode; struct ArithmNode { ArithmNodeKind kind; union { int lit_val; struct { BinOp op; ArithmNode* left; ArithmNode* right; } binop; } as; }; DECLARE_VEC(ArithmNode, ArithmNodeVec) typedef struct { ArithmNodeVec nodes; ArithmNode* root; } ArithmAst; typedef enum { UN_Q, SINGLE_Q, DOUBLE_Q, } QuotationMode; typedef enum { CHUNK_LIT, CHUNK_VAR, CHUNK_CMDSUB, CHUNK_ARITHM, } ChunkKind; typedef struct { QuotationMode qmode; ChunkKind kind; union { char* lit_str; char* varname; ArithmAst arithm_expr; // TODO: CHUNK_CMDSUB } as; } Chunk; DECLARE_VEC(Chunk, Word) typedef enum { TOK_WORD, TOK_SPEC, TOK_SUB_IN, TOK_SUB_OUT, } TokenKind; typedef enum { SPEC_PIPE, SPEC_REDIR_W_TRUNC, SPEC_REDIR_W_APPEND, SPEC_REDIR_R, SPEC_EOL, } SpecialToken; typedef struct Token Token; DECLARE_VEC(Token*, TokenPtrVec) struct Token { TokenKind kind; union { Word word; SpecialToken spec; TokenPtrVec procsub_toks; } as; }; DECLARE_VEC(Token, TokenVec) typedef struct { TokenVec token_pool; TokenPtrVec top_tokens; } Ast;