AST — Abstract Syntax Tree
Node types, data structures, and construction helpers for the AST.
Abstract Syntax Tree definitions for the 42sh shell.
- Author
jguillem pulgamecanica
Defines
-
REDIR(node)
Convenience accessor: get t_redir* from a t_list node.
Enums
Functions
-
t_ast *ast_new_command(t_cmd *cmd)
AST construction helpers.
AST construction helpers.
- Parameters:
cmd – struct s_cmd
- Returns:
pointer on struct s_ast
-
t_ast *ast_new_binary(t_node_type type, t_ast *left, t_ast *right)
create and allocate new binary ast node
- Parameters:
type – enum e_node_type
left – struct s_ast pointer
right – struct s_ast pointer
- Returns:
struct s_ast pointer
-
t_ast *ast_new_group(t_node_type type, t_ast *child, t_list *redirs)
helper function for the parse_subshell function
- Parameters:
type – enum e_node_type
child – struct s_ast
redirs – struct s_list with a t_redir * as content
- Returns:
pointer on struct s_ast
-
t_redir *redir_new(t_token_type type, int fd, char *target)
Redirection helpers.
-
struct t_redir
- #include <ast.h>
Redirection data node.
Stored in t_cmd.redirs and t_group.redirs as t_list* (each node->content is a t_redir*). No *next field.
- Param fd:
source fd (-1 = default for the operator type).
- Param target:
raw filename or fd number string (unexpanded).
- Param heredoc_delim:
the delimiter word for << (raw, may be quoted).
- Param heredoc_stripped:
1 if leadling tab are stripped
- Param heredoc_content:
collected heredoc content (filled after parse, before exec).
- Param heredoc_quoted:
1 if delimiter was quoted (no expansion inside heredoc).
-
struct t_cmd
- #include <ast.h>
Simple command data.
- Param argv:
NULL-terminated array of raw/unexpanded argument strings.
- Param argc:
number of elements in argv (not counting the NULL terminator).
- Param assignments:
t_list* of char* “NAME=value” strings (detected by parser, unexpanded). Each node->content is a char*.
- Param redirs:
t_list* of t_redir* (in source order, applied left-to-right). Each node->content is a t_redir*.
-
struct t_binary
- #include <ast.h>
Binary operation data (pipe, &&, ||, ;)
-
struct t_group
- #include <ast.h>
Group data (subshell, block, background).
- Param redirs:
t_list* of t_redir* for redirections applied to the whole group, e.g. (cmd) > file or { cmd; } 2>&1.
-
struct t_ast
- #include <ast.h>
AST node - union-based for zero-overhead dispatch.