33
44#include <token/def.h>
55
6- struct Statement {
7- char * (* token_literal )(struct Token * tok );
8- void (* statement_node )(struct Statement * self );
9- };
10-
6+ /**
7+ * Represents an expression in the program.
8+ *
9+ * An expression is a syntactic unit that produces a value when evaluated.
10+ * It can be a literal value, a variable reference, an arithmetic operation,
11+ * a function call, or other constructs. Expressions are used to compute values
12+ * and perform operations in programming languages.
13+ */
1114struct Expression {
12- char * (* token_literal )(struct Token * tok );
13- void (* expression_node )(struct Expression * self );
14- };
15-
16- struct Program {
17- struct Statement * * statments ;
18- int statments_len ;
1915};
2016
17+ /**
18+ * Represents an identifier in the program.
19+ *
20+ * An identifier is a name used to identify a variable, function, or other entities
21+ * in a program. It is associated with an expression and a token that represents
22+ * the identifier's value or reference.
23+ *
24+ * This `struct Identifier` stores information about the associated expression,
25+ * the token representing the identifier, and the value of the identifier (if applicable).
26+ */
2127struct Identifier {
28+ /** The expression associated with the identifier. */
2229 struct Expression * expression ;
30+
31+ /** The token representing the identifier. */
2332 struct Token * token ;
33+
34+ /** The value of the identifier. */
2435 char * value ;
2536};
2637
27- struct Def_statement {
28- struct Statement * statement ;
38+ /**
39+ * Represents a statement in the program.
40+ *
41+ * A statement is a syntactic unit that performs an action or declares something.
42+ * It can be an expression, a variable declaration, a return statement, or other constructs.
43+ * In programming languages, statements are used to control the flow of execution and
44+ * manipulate data. They form the building blocks of programs.
45+ *
46+ * This `struct Statement` stores information about the type of statement, its mutability,
47+ * associated token, identifier (if applicable), and expression (if applicable).
48+ */
49+ struct Statement {
50+ /** Indicates the type of statement. */
51+ int type ;
52+
53+ /** Indicates whether the statement is mutable (1) or immutable (0). */
54+ int mut ;
55+
56+ /** Represents the token associated with the statement. */
2957 struct Token * token ;
30- struct Identifier * identifier ; // name
31- struct Expression * expression ; // value
58+
59+ /** Identifier associated with the statement (e.g., variable name). */
60+ struct Identifier * identifier ;
61+
62+ /** Expression associated with the statement (e.g., value assigned to a variable). */
63+ struct Expression * expression ;
64+
65+ /**
66+ * Converts a statement to a string representation.
67+ *
68+ * @param self The statement to convert.
69+ *
70+ * @return The string representation of the variable statement.
71+ */
72+ char * (* to_string )(struct Statement * self );
73+ };
74+
75+ /**
76+ * Represents a program in the source code.
77+ *
78+ * A program is the root container that holds all the statements of the program.
79+ * It serves as the top-level structure that encapsulates the entire code.
80+ * The `struct Program` maintains an array of statement pointers, along with
81+ * information about the capacity and current size of the array.
82+ */
83+ struct Program {
84+ /** An array of pointers to the statements in the program. */
85+ struct Statement * * statements ;
86+
87+ /** The capacity of the statement array. */
88+ int statements_capacity ;
89+
90+ /** The current size of the statement array. */
91+ int statements_size ;
92+
93+ /**
94+ * Converts a program to a string representation.
95+ *
96+ * @param self The program to convert.
97+ *
98+ * @return The string representation of the program.
99+ */
100+ char * (* to_string )(struct Program * self );
32101};
33102
34103#endif /* AST_DEFINITION_T */
0 commit comments