-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAST.h
More file actions
48 lines (36 loc) · 1.79 KB
/
Copy pathAST.h
File metadata and controls
48 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef AST_H
#define AST_H
typedef enum{
AST_DECLARATION, //for decleration statement
AST_ASSIGNMENT, //for assignment statement
AST_INCREMENT, //for increment statement
AST_DECREMENT, //for decrement statement
AST_WRITE, //for write statement
AST_WRITE_ELEMENT, //for elements that will be written
AST_LOOP, //for loop statement
AST_CODEBLOCK, //for statement list in loop
AST_VARIABLE, //for variable
AST_LITERAL, //for number or string constants
AST_NEWLINE, //for new line
AST_PROGRAM //for program statements
}ASTtype;
//the structure that stores the statement
typedef struct AST {
ASTtype type;
int line ;
union {
struct { char* name; char* value;} declaration; // number x; or number x := value;
struct { char* name; struct AST* value; } assignment; // x += value;
struct { char* name; struct AST* value; } increment; // x += value;
struct { char* name; struct AST* value; } decrement; // x -= value;
struct { struct AST** elements; int count; } write; // write a and "b" and newline;
struct { char* value; } string_literal; // "Hello!"
struct { char* value; } number_literal; // max 100 digit number
struct { char* value; } newLine; // new line character
struct { char* name; } variable; // x, y, z
struct { struct AST* times; struct AST* body; } loop; // repeat N times <stmt|block>
struct { struct AST** statements; int count; int position;} codeblock; // { ... }
struct { struct AST** statements; int count; int position; } programStatements; //All statements
};
} AST;
#endif