diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-19 21:13:19 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-19 21:13:19 +0200 |
| commit | 2bdbf387261285d07e4b62d1e23c9e43efb14604 (patch) | |
| tree | 92b81d300f3c17d072f2a30362dafd815e57a758 /redes/syntax.h | |
| parent | 6a391a1180766ac5717c40efa70d46cacca83f91 (diff) | |
restructure dir, create makefile
Diffstat (limited to 'redes/syntax.h')
| -rw-r--r-- | redes/syntax.h | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/redes/syntax.h b/redes/syntax.h new file mode 100644 index 0000000..8404d15 --- /dev/null +++ b/redes/syntax.h @@ -0,0 +1,167 @@ +# pragma once + +#include "utils.h" + + +// Stage 1 + +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; + IntVec open_fds; + 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; + + + +// Stage 2 + + +typedef enum { + REDIR_FILE_IN, + REDIR_FILE_OUT, + REDIR_FDS, +} RedirectKind; + +typedef struct { + RedirectKind kind; + union { + char* filename; + struct{int from; int to;} fds; + } as; +} Redirect; + +DECLARE_VEC(Redirect, RedirectVec) + +typedef struct { + char** args; + RedirectVec redirects; +} SimpleCommand; + +DECLARE_VEC(SimpleCommand, SimpleCommandVec) +DECLARE_VEC(SimpleCommand*, SimpleCommandPtrVec) + + +typedef enum { + CONN_PIPE, + CONN_EOL, +} Connector; + +typedef struct { + SimpleCommand* cmd; + SimpleCommandPtrVec deps; + Connector conn; +} PlCommand; + +DECLARE_VEC(PlCommand, PlCommandVec) + +typedef struct { + SimpleCommandVec commands; + PlCommandVec pipeline; +} ExecTree; + + + +// Stage 3 + +typedef struct { + int redirected; + int to; +} FdRedirect; + +DECLARE_VEC(FdRedirect, FdRedirectVec) + +typedef struct { + char** args; + FdRedirectVec redirects; + int stdin_fd, stdout_fd; + IntVec open_fds; +} ExecutableCommand; |
