source: liacs/coco/assignment4/types.h

Last change on this file was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 4.7 KB
Line 
1/*
2 * types.h - Various type definitions
3 *
4 * Part of the assignment of the Compiler Construction course
5 * LIACS, Leiden University
6 */
7
8#ifndef _TYPES_H_
9#define _TYPES_H_
10
11#include <string>
12
13using namespace std;
14
15// Return type of a node
16typedef enum __returntype {
17 RT_UNKNOWN, // Not (yet) known
18 RT_ERROR, // Error
19 RT_VOID, // Void
20 RT_INT, // Integer
21 RT_REAL, // Floating point
22 RT_BOOL // Boolean expression
23} ReturnType;
24
25
26// Type of a symbol
27typedef enum __symboltype {
28 ST_UNKNOWN, // Unknown (yet)
29 ST_ERROR, // Error
30 ST_VARIABLE, // Variable
31 ST_PARAMETER, // Function/Procedure parameter
32 ST_PROCEDURE, // Procedure
33 ST_FUNCTION, // Function
34 ST_PROGRAM, // Program body
35 ST_TEMPVAR, // Temporary variable (not used before assignment 3)
36 ST_LABEL // Label (not used before assignment 3)
37} SymbolType;
38
39
40// Type of a node in the syntax tree
41typedef enum __nodetype {
42 /* Meta */
43 NODE_UNKNOWN, // Unknown (yet)
44 NODE_ERROR, // Error
45
46 /* Statement list
47 left child One of: NODE_ASSIGNMENT, NODE_IF, NODE_WHILE,
48 NODE_PROCCALL, NODE_FUNCTIONCALL, NODE_STATEMENT_LIST.
49 right child One of: NODE_ASSIGNMENT, NODE_IF, NODE_WHILE,
50 NODE_PROCCALL, NODE_FUNCTIONCALL, NODE_STATEMENT_LIST, or
51 NODE_EMPTY if no more statements follow. */
52 NODE_STATEMENT_LIST,
53
54 /* Assignment
55 left child A NODE_ID that identifies the destination variable
56 right child A subtree representing an expression */
57 NODE_ASSIGNMENT,
58
59 /* If statement
60 left child A NODE_BOOLEXPR that provides the if condition
61 right child A NODE_IF_TARGETS subtree (if there is an else clause) or
62 a subtree consisting of statements (if there's no else) */
63 NODE_IF,
64
65 /* Targets of an if-else-statement
66 left child The statements that have to be executed when the condition
67 of the parent if-statement is true.
68 right child The statements that have to be executed when the condition
69 of the parent if-statement is false, that is, the else
70 part. */
71 NODE_IF_TARGETS,
72
73 /* While loop
74 left child A NODE_BOOLEXPR that provides the loop condition
75 right child A subtree consisting of statements */
76 NODE_WHILE,
77
78 /* Subprogram calls
79 left child A NODE_ID that identifies the called function/procedure
80 right child A NODE_EXPRLIST that specifies the actual arguments, or
81 NODE_EMPTY if no arguments required. */
82 NODE_PROCCALL,
83 NODE_FUNCTIONCALL,
84
85 /* Expression list
86 left child A subtree representing an expression
87 right child A subtree representing an expression, another
88 NODE_EXPRLIST, or NODE_EMPTY if no more expressions follow
89 in the expression list. */
90 NODE_EXPRLIST,
91
92 /* Boolean-like expression
93 child A subtree with any NODE_REL_ node as parent */
94 NODE_BOOLEXPR,
95
96 /* Relational operators
97 left child Left-hand side of the comparison
98 right child Right-hand side of the comparison */
99 NODE_REL_EQUAL, // = operator
100 NODE_REL_LT, // < operator
101 NODE_REL_GT, // > operator
102 NODE_REL_LTE, // <= operator
103 NODE_REL_GTE, // >= operator
104 NODE_REL_NOTEQUAL, // <> operator
105
106 /* Binary arithmetic & logic operations
107 left child Left-hand side of the operation
108 right child Right-hand side of the operation */
109 NODE_ADD, // Add
110 NODE_SUB, // Substract
111 NODE_OR, // OR operation
112 NODE_MUL, // Multiply
113 NODE_DIV, // Divide
114 NODE_IDIV, // Integer division
115 NODE_MOD, // Modulo
116 NODE_AND, // AND operation
117
118 /* Leafs
119 these nodes have no child nodes */
120 NODE_NUM_INT, // Integer number
121 NODE_NUM_REAL, // Real number
122 NODE_ID, // Identifier
123 NODE_EMPTY, // Empty leaf (terminates lists etc.)
124
125 /* Unary nodes
126 child The subtree to which the operation has to be applied */
127 NODE_NOT, // NOT operation
128 NODE_SIGNPLUS, // Unary plus
129 NODE_SIGNMINUS, // Unary minus
130 NODE_COERCION // Int to Real coercion
131} NodeType;
132
133
134/* Prototypes */
135char * ReturnTypeToString (ReturnType returntype);
136char * SymbolTypeToString (SymbolType symboltype);
137char * NodeTypeToString (NodeType nodetype);
138
139#endif
Note: See TracBrowser for help on using the repository browser.