Source Documentation¶
-
class
array_symbol
: public symbol - #include <symtab.hh>
Derived symbol type, used for arrays.
Study the following declaration:
var arr : array[10] of real;
The type attribute (see above) in this case is an index to the name type
real
. We see that we also need an attribute,#array_cardinality
, which in this example would have the value10
. To be slightly more general, we also have an attribute,#index_type
, which at present can only point to the name type#integer_type
.Public Members
-
sym_index
index_type
Points to the index type in the symbol table.
-
int
array_cardinality
Note: cardinality = nr of elements,.
Protected Functions
-
virtual void
print
(ostream&)¶
-
sym_index
-
class
ast_add
: public ast_binaryoperation¶ - #include <ast.hh>
Plus node.
a + b
.Example:
-a + 5 * c
Public Functions
-
ast_add
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_and
: public ast_binaryoperation¶ - #include <ast.hh>
Logical AND node.
a AND b
.Public Functions
-
ast_and
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_assign
: public ast_statement¶ - #include <ast.hh>
Assignment node.
a := b
ora[i] = b
.Note that this class inherits ast_statement, and therefore does not return a value. Constructs of the type
a := (b := 2);
are not allowed in DIESEL.Public Functions
-
ast_assign
(position_information*, ast_lvalue*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_lvalue *
lhs
¶ The left hand side (lhs), ie, the variable being assigned to.
-
ast_expression *
rhs
¶ The right hand side (rhs), ie, the value being assigned.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_binaryoperation
: public ast_expression¶ - #include <ast.hh>
Base class for all binary operation nodes.
a + b
, etc. Note: the left and right operands are defined here instead of in the individual subclasses, making those rather trivial.Subclassed by ast_add, ast_and, ast_divide, ast_idiv, ast_mod, ast_mult, ast_or, ast_sub
Public Functions
-
ast_binaryoperation
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&) = 0¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
inline virtual ast_binaryoperation *
get_ast_binaryoperation
()¶
Public Members
-
ast_expression *
left
¶ Left child of the operation.
-
ast_expression *
right
¶ Right child of the operation.
-
-
class
ast_binaryrelation
: public ast_expression¶ - #include <ast.hh>
Base class for all binary relation nodes.
a < b
, etc.Always returns a integer value, where 0 (zero) means false and everything else means true.
Note: the left and right operands are defined here instead of in the individual subclasses, making those rather trivial.
Subclassed by ast_equal, ast_greaterthan, ast_lessthan, ast_notequal
Public Functions
-
ast_binaryrelation
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
left
¶ Left child of the operation.
-
ast_expression *
right
¶ Right child of the operation.
-
-
class
ast_cast
: public ast_expression¶ - #include <ast.hh>
A cast node.
This class represents type transformation, casting an integer to a real. It is inserted into the AST at appropriate places during type checking. See semantic.cc.
Public Functions
-
ast_cast
(position_information*, ast_expression*)¶
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
expr
¶ The expression to cast to real.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_divide
: public ast_binaryoperation¶ - #include <ast.hh>
Real division node.
a / b
, where at least one of a and b have real type.Public Functions
-
ast_divide
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&)¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
inline virtual ast_divide *
get_ast_binaryoperation
()¶
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_elsif
: public ast_node¶ - #include <ast.hh>
represents an
elsif
clause inside anif
-statement. The class is a bit special, so it inherits directly from ast_node.Public Functions
-
ast_elsif
(position_information*, ast_expression*, ast_stmt_list*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
condition
¶ The test condition; decides if we should execute the body.
-
ast_stmt_list *
body
¶ The body to execute if the condition evaluates to true.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_elsif_list
: public ast_node¶ - #include <ast.hh>
Contains a list of elsif clauses.
Public Functions
-
ast_elsif_list
(position_information*, ast_elsif*)¶ Constructor for the first element of a list.
-
ast_elsif_list
(position_information*, ast_elsif*, ast_elsif_list*)¶ Constructor to add a new elsif clause to the list.
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_elsif_list *
preceding
¶ Points to a list of the preceding elsif clauses. Is
NULL
when empty.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_equal
: public ast_binaryrelation¶ - #include <ast.hh>
Equality operator.
a = b
.Public Functions
-
ast_equal
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_expr_list
: public ast_node¶ - #include <ast.hh>
Contains a list of expressions. Currently only used for parameter lists.
Note: The parameters will be stored in reverse order! This is due to how the grammar is written, it’s easiest this way.
Public Functions
-
ast_expr_list
(position_information*, ast_expression*)¶ Constructor for the first element of a list.
-
ast_expr_list
(position_information*, ast_expression*, ast_expr_list*)¶ Constructor to add a new expression to the list.
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&)¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
virtual void
generate_parameter_list
(quad_list&, parameter_symbol*, int*)¶
Public Members
-
ast_expression *
last_expr
¶ Points to the last (last added) expression in the list.
-
ast_expr_list *
preceding
¶ Points to a list of the preceding expressions. Is
NULL
when empty.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_expression
: public ast_node¶ - #include <ast.hh>
The superclass for all DIESEL constructs that do return a value. It has a type attribute, which denotes the type of its value (real_type, integer_type, or void_type).
Subclassed by ast_binaryoperation, ast_binaryrelation, ast_cast, ast_functioncall, ast_integer, ast_lvalue, ast_not, ast_real, ast_uminus
Public Functions
-
ast_expression
(position_information*)¶
-
ast_expression
(position_information*, sym_index)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&) = 0¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
inline virtual ast_integer *
get_ast_integer
()¶
-
inline virtual ast_binaryoperation *
get_ast_binaryoperation
()¶
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_functioncall
: public ast_expression¶ - #include <ast.hh>
Represents a function call.
a = calc(foo);
If you wonder how the return value is handled, or where the function call is actually connected to the function body… Don’t worry. It will become clear later on. Remember that we parse one block at a time, so that the call of a function takes place on one lexical level higher (as in less deeply nested) than the execution of the function body, except in certain cases involving recursive function calls.
Public Functions
-
ast_functioncall
(position_information*, ast_id*, ast_expr_list*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expr_list *
parameter_list
¶ A list of actual parameters. If no parameters, this list is NULL.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_functionhead
: public ast_node¶ - #include <ast.hh>
A node used to transfer information about an environment. Used in parser.y for setting the proper return type of a function, and type checking. It is never part of a function body.
Public Functions
-
ast_functionhead
(position_information*, sym_index)¶
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&)¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
quad_list *
do_quads
(ast_stmt_list *s)¶ Starts the generation of a quad list for a program block pointed to by the argument. It then adds on the last label quad, and returns the list when it is done.
- Parameters
s – the function body to generate quads for.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_greaterthan
: public ast_binaryrelation¶ - #include <ast.hh>
Greater than operator.
a > b
.Public Functions
-
ast_greaterthan
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_id
: public ast_lvalue¶ - #include <ast.hh>
An identifier node. Can be the name of a variable, function, constant, etc…
Public Functions
-
ast_id
(position_information*)¶
-
ast_id
(position_information*, sym_index)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_idiv
: public ast_binaryoperation¶ - #include <ast.hh>
Integer division node.
a div b
, where both operands have integer type.Public Functions
-
ast_idiv
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_if
: public ast_statement¶ - #include <ast.hh>
An if clause. Has lots of children. if - then - elsif - else.
Example:
if a > b then c := a; else c := b; end;
Example:
if a > b then c := a elsif a = b then c := 0 elsif a < b then c := b else c := -1 end;
Public Functions
-
ast_if
(position_information*, ast_expression*, ast_stmt_list*, ast_elsif_list*, ast_stmt_list*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
condition
¶ The primary if-condition.
-
ast_stmt_list *
body
¶ The primary if-body, executed if condition evaluates to non-zero.
-
ast_elsif_list *
elsif_list
¶ A list of elsif clauses. May be NULL.
-
ast_stmt_list *
else_body
¶ The else body, executed if ‘condition’ evaluates to zero. May be NULL.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_indexed
: public ast_lvalue¶ - #include <ast.hh>
An array identifier node. Index must be of integer type.
Example:
a[a[1]] := a[2] + 3;
Public Functions
-
ast_indexed
(position_information*, ast_id*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
index
¶ The index expression. Must be of type integer.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_integer
: public ast_expression¶ - #include <ast.hh>
An integer node. Represents an integer number, like
5
.Public Functions
-
ast_integer
(position_information*, long)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&)¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
inline virtual ast_integer *
get_ast_integer
()¶
Public Members
-
long
value
¶ The integer value of the node.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_lessthan
: public ast_binaryrelation¶ - #include <ast.hh>
Less than operator.
a < b
.Public Functions
-
ast_lessthan
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_lvalue
: public ast_expression¶ - #include <ast.hh>
The superclass for all DIESEL constructs that can be assigned a value (i.e., which evaluate to a reference to a storage location). The name lvalue comes from the fact that it represents expressions that can appear on the left-hand side of an assignment (e.g.,
x := 2;
).Subclassed by ast_id, ast_indexed
Public Functions
-
ast_lvalue
(position_information*)¶
-
ast_lvalue
(position_information*, sym_index)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_mod
: public ast_binaryoperation¶ - #include <ast.hh>
Integer mod node.
a mod b
, where both operands have integer type.Public Functions
-
ast_mod
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_mult
: public ast_binaryoperation¶ - #include <ast.hh>
Multiplication node.
a * b
.Public Functions
-
ast_mult
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_node
¶ - #include <ast.hh>
The superclass of all other AST nodes. It is essentially an empty class, holding only position information, a tag (to help identify the node type when downcasting is needed), and methods for printing AST nodes; all of which are things common to all nodes.
Subclassed by ast_elsif, ast_elsif_list, ast_expr_list, ast_expression, ast_functionhead, ast_procedurehead, ast_statement, ast_stmt_list
Public Functions
-
ast_node
(position_information*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
position_information *
pos
¶ Holds line and column number for this node.
-
ast_node_type
tag
¶ Describes what kind of node this is. We need to be able to check this in a convenient way during AST optimization and C++ does not support reflective programming.
-
-
class
ast_not
: public ast_expression¶ - #include <ast.hh>
A logical negation node.
Public Functions
-
ast_not
(position_information*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
expr
¶ The expression being negated.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_notequal
: public ast_binaryrelation¶ - #include <ast.hh>
Not-equal operator.
a <> b
.Public Functions
-
ast_notequal
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_optimizer
¶ - #include <optimize.hh>
Public Functions
-
void
do_optimize
(ast_stmt_list *body)¶ Starts recursive (destructive) optimization of a block.
This method has already been written for you, and is rather trivial. It is the interface to parser.y.
- Parameters
body – a list of statements representing the block body to be optimized.
-
bool
is_binop
(ast_expression*)¶ Returns true if the argument is a subclass of ast_binaryoperation. It is needed to find out which nodes are eligible for optimization.
-
ast_expression *
fold_constants
(ast_expression*)¶ This is a convenient method used in optimize.cc. It has to be public so the ast_* nodes can access it. Another solution would be to make it a static method in the optimize.cc file… A matter of preference.
-
void
-
class
ast_or
: public ast_binaryoperation¶ - #include <ast.hh>
Logical OR node.
a OR b
.Public Functions
-
ast_or
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_procedurecall
: public ast_statement¶ - #include <ast.hh>
Represents a procedure call.
Example:
foo(1, 2+3, c);
Example:
fie(1);
Example:
if a > b then c := a; else c := b; end;
Public Functions
-
ast_procedurecall
(position_information*, ast_id*, ast_expr_list*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expr_list *
parameter_list
¶ A list of eventual parameters. If no parameters, this list is NULL.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_procedurehead
: public ast_node¶ - #include <ast.hh>
A node used to transfer information about an environment. Used in parser.y for setting the proper return type of a procedure. It is never part of a procedure body.
Public Functions
-
ast_procedurehead
(position_information*, sym_index)¶
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
-
virtual sym_index
generate_quads
(quad_list&)¶ Generate quads. See quads.cc for the method bodies. Like type checking, generate_quads should only be called in concrete AST nodes.
-
quad_list *
do_quads
(ast_stmt_list *s)¶ Starts the generation of a quad list for a program block pointed to by the argument. It then adds on the last label quad, and returns the list when it is done.
- Parameters
s – the procedure body to generate quads for.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_real
: public ast_expression¶ - #include <ast.hh>
A real node. Represents a real number, like
2.5
.Public Functions
-
ast_real
(position_information*, double)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
double
value
¶ The floating point value of the node.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_return
: public ast_statement¶ - #include <ast.hh>
A return statement, used both for procedures and functions. If no value is returned (i.e. in a procedure), ‘value’ should be set to NULL.
Note that the return statement itself has no value, i.e., it cannot stand on the right-hand side of an assignment since it inherits
ast_statement
.Public Functions
-
ast_return
(position_information*)¶ Constructor for no return value.
-
ast_return
(position_information*, ast_expression*)¶ Constructor with a return value.
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
value
¶ The return value.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_statement
: public ast_node¶ - #include <ast.hh>
The superclass for all DIESEL constructs that do not return a value.
Subclassed by ast_assign, ast_if, ast_procedurecall, ast_return, ast_while
Public Functions
-
ast_statement
(position_information*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_stmt_list
: public ast_node¶ - #include <ast.hh>
Contains a list of statements. The body of a program, for example, is represented by this class: Example:
begin a := 1; b := a; c := b; d := c; e := d; f := e; end;
Public Functions
-
ast_stmt_list
(position_information*, ast_statement*)¶ Constructor for the first element of a list.
-
ast_stmt_list
(position_information*, ast_statement*, ast_stmt_list*)¶ Constructor to add a new statement to the list.
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_statement *
last_stmt
¶ Points to the last (last added) statement in the list.
-
ast_stmt_list *
preceding
¶ Points to a list of the preceding statements. Is
NULL
when empty.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_sub
: public ast_binaryoperation¶ - #include <ast.hh>
Minus node.
a - b
.Public Functions
-
ast_sub
(position_information*, ast_expression*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_uminus
: public ast_expression¶ - #include <ast.hh>
A unary minus node.
Note that there is no unary plus.
Public Functions
-
ast_uminus
(position_information*, ast_expression*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Public Members
-
ast_expression *
expr
¶ The expression to negate.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
ast_while
: public ast_statement¶ - #include <ast.hh>
A while loop. Contains a test condition and a loop body.
Compare this to other conditional nodes (e.g.
ast_elsif
,ast_if
).Public Functions
-
ast_while
(position_information*, ast_expression*, ast_stmt_list*)¶
-
virtual sym_index
type_check
()¶ Perform type checking. See semantic.cc for the method bodies. Note that it’s an error to call type_check in this class. It should only be called in the concrete AST nodes, see below.
-
virtual void
optimize
()¶ Perform optimization. See optimize.cc for the method bodies. Just as with type checking, it’s an error to call optimize in this class. It should only be called in the concrete AST nodes.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
code_generator
¶ - #include <codegen.hh>
Private Functions
-
int
align
(int)¶ Aligns a stack frame on an 8-byte boundary.
-
void
prologue
(symbol*)¶ Generates code to create the activation record.
This includes the display area and allocating space for local variables and temporaries.
-
void
expand
(quad_list *q)¶ Translates a quad list to assembler code using the methods above. You will need to write code for expanding q_param and q_call quads.
-
void
find
(sym_index, int*, int*)¶ Returns the display register level and offset for a variable, array or parameter to the symbol table.
Note that parameters are stored in the caller’s activation record and therefore have positive offset while local and temporary variables have negative offset.
Also note that the method modifies its arguments, which is why they are passed as pointers.
-
void
fetch
(sym_index, const register_type)¶ Retrieves the value of a variable, parameter or constant to a given register.
-
void
fetch_float
(sym_index)¶ Pushes the value of a variable, paramters or constant to the FPU.
Note that this method will never generate code for constant integers but will for constant reals.
-
void
store
(const register_type, sym_index)¶ Stores the value of a register in a variable or parameter.
-
void
array_address
(sym_index, const register_type)¶ Retrieves the base address of an array to a register.
The method is called when expanding the quadruples q_lindex, q_irindex, and q_rrindex.
-
void
frame_address
(int level, const register_type)¶ Given a lexical level and a register, stores the base address of the corresponding frame from the display area.
-
int
-
class
constant_symbol
: public symbol - #include <symtab.hh>
Derived symbol type, used for constants.
Public Functions
-
constant_symbol
(const pool_index)¶
-
inline virtual constant_symbol *
get_constant_symbol
()¶
Public Members
-
constant_value
const_value
Value of a constant, can be int or float. The value is stored in a union; check the
#type
attribute to figure out if you should accessivar
orrvar
.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
function_symbol
: public symbol - #include <symtab.hh>
Derived symbol type, used for functions.
Public Functions
-
function_symbol
(const pool_index)¶
-
inline virtual function_symbol *
get_function_symbol
()¶
Public Members
-
int
ar_size
Activation record size.
Specifies the memory space that is needed to store the local variables belonging to the procedure/function on the runtime stack. A procedure that declares an array of ten integers, two reals and three integers requires (10+2+3)*8 bytes.
-
int
label_nr
The label number which is assigned to the procedure or function in assembler code.
-
parameter_symbol *
last_parameter
List of parameters. We store them in reverse order to make type-checking easier later on.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
nametype_symbol
: public symbol¶ - #include <symtab.hh>
Derived symbol type, used for nametypes. Since it contains no new data fields, we might as well use symbol directly. This subclass mainly exists for abstraction’s sake.
Public Functions
-
nametype_symbol
(const pool_index)¶
-
inline virtual nametype_symbol *
get_nametype_symbol
()¶
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
parameter_symbol
: public symbol - #include <symtab.hh>
Parameters require particular checking, as the formal parameters are to be bound to the actual ones. Assume the following declaration:
procedure p(i : integer; r : real);
which is then called with the following actual parameters:
p(22/7, 355/113);
To perform a semantic check, we must find the formal parameters (
i
andr
) in the symbol table and compare their type attributes with the actual parameters. In this example a type conflict occurs when the value of the expression22/7
(which is areal
) is to be bound to theinteger
variablei
.For this reason the formal parameters are linked together in the symbol table. The
preceding
attribute points to the previous parameter in the link chain. The procedure (or function) points to thelast
parameter. It might seem counter-intuitive that the parameters are stored backwards like this, but it will actually make life easier later on.The handling of parameters is actually one of the trickiest parts to understand correctly in this entire lab course. Some work has already been done for you, but you will have to do a lot of it yourself. Make sure to read the code comments carefully when dealing with parameters, and be sure to have this lab material handy as well. The order of the parameters will be flipped around during compiling more than once. Once you have that sequence clear, getting them to work will be a lot easier.
Public Functions
-
parameter_symbol
(const pool_index)¶
-
inline virtual parameter_symbol *
get_parameter_symbol
()¶
Public Members
-
int
size
Nr of bytes parameter needs.
-
parameter_symbol *
preceding
Link to preceding parameter, if any.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
procedure_symbol
: public symbol - #include <symtab.hh>
Derived symbol type, used for procedures.
Public Functions
-
procedure_symbol
(const pool_index)¶
-
inline virtual procedure_symbol *
get_procedure_symbol
()¶
Public Members
-
int
ar_size
Activation record size.
Specifies the memory space that is needed to store the local variables belonging to the procedure/function on the runtime stack. A procedure that declares an array of ten integers, two reals and three integers requires (10+2+3)*8 bytes.
-
int
label_nr
The label number which is assigned to the procedure or function in assembler code.
-
parameter_symbol *
last_parameter
List of parameters. We store them in reverse order to make type-checking easier later on.
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
class
quad_list
¶ - #include <quads.hh>
Public Members
-
int
last_label
¶
Private Functions
-
void
print
(ostream&)¶
-
int
-
class
quad_list_element
¶ - #include <quads.hh>
Public Functions
-
quad_list_element
(quadruple*, quad_list_element*)¶
-
-
class
quad_list_iterator
¶ - #include <quads.hh>
Public Functions
Private Members
-
quad_list_element *
current
¶
-
quad_list_element *
-
class
quadruple
¶ - #include <quads.hh>
Public Functions
-
quadruple
(quad_op_type, sym_index, sym_index, sym_index)¶
Private Functions
-
void
print
(ostream&)¶
-
-
class
semantic
¶ - #include <semantic.hh>
Public Functions
-
void
check_parameters
(ast_id*, ast_expr_list*)¶ Compare formal vs. actual parameters in function/procedure calls.
It is also responsible for making sure that parameters are type-checked. You will have to write this method yourself, and also figure out from where to call it.
-
void
do_typecheck
(symbol *env, ast_stmt_list *body)¶ Initiate type checking of a block of code.
Performs some initialisation before starting recursive type checking of a block.
The function has already been written for you.
- Parameters
env – the symbol representing the block to be checked (i.e., a function or procedure symbol)
body – an
ast_stmt_list
node representing the block body to be checked.
-
sym_index
check_binop1
(ast_binaryoperation*)¶
-
sym_index
check_binop2
(ast_binaryoperation*, string)¶
-
sym_index
check_binrel
(ast_binaryrelation*)¶
Private Functions
-
bool
chk_param
(ast_id*, parameter_symbol*, ast_expr_list*)¶
-
void
-
class
symbol
- #include <symtab.hh>
The symbol table consists of entries of subclasses to symbol. This class contains data that are common to all symbol types. This class is never used directly. Use the derived classes instead.
Subclassed by array_symbol, constant_symbol, function_symbol, nametype_symbol, parameter_symbol, procedure_symbol, variable_symbol
Public Functions
-
symbol
(pool_index)¶
-
inline virtual constant_symbol *
get_constant_symbol
()¶
-
inline virtual variable_symbol *
get_variable_symbol
()¶
-
inline virtual array_symbol *
get_array_symbol
()¶
-
inline virtual parameter_symbol *
get_parameter_symbol
()¶
-
inline virtual procedure_symbol *
get_procedure_symbol
()¶
-
inline virtual function_symbol *
get_function_symbol
()¶
-
inline virtual nametype_symbol *
get_nametype_symbol
()¶
Public Members
-
pool_index
id
Index to the string_pool, ie, its name.
The object’s identifier is stored in the string table (i.e. the spelling, see previous lab). Index to string table (called
id
in the lab skeleton) is a value denoting where an identifier starts in the string table. Example:The scanner from lab1 has created a string table that look like this (the number denotes the length of the following identifier):
7GLOBAL.4VOID7INTEGER...
The id to
GLOBAL.
is 0 because it starts on the first position in the string table (the index to the first position in an array in C++ is 0).
-
sym_type
tag
This field is only used to give us a way to differentiate between the various symbol classes when we need to do a safe downcast from the superclass. The default value of tag is
SYM_UNDEF
.
-
sym_index
type
In practice type is used only by constants, variables, arrays, parameters and functions; all other symbol types are of type void. The type field contains an index to a name type which in DIESEL only can be
integer_type
,real_type
, orvoid_type
. These will be preinstalled in the symbol table.
-
sym_index
hash_link
If the object you are searching for not is found immediately after the key transformation, you follow the hash link backwards in the table.
-
hash_index
back_link
This link points back to the hash table from the symbol table and can be used to speed up certain types of lookups. It is possible to complete the lab without using it, though.
-
block_level
level
The lexical level states how deeply nested the object is in the program. For example, an object on the first level is global. Eight levels is the maximum in Diesel.
-
int
offset
Offset specifies which relative position the object has in the memory space which has been reserved for a given lexical level on the runtime stack. This is used during code generation.
Protected Types
-
enum
format_types
¶ Values:
-
enumerator
LONG_FORMAT
¶
-
enumerator
SUMMARY_FORMAT
¶
-
enumerator
SHORT_FORMAT
¶
-
enumerator
-
typedef enum format_types
format_type
¶
Protected Functions
-
virtual void
print
(ostream&)¶
Protected Static Attributes
-
static format_type
output_format
= symbol::LONG_FORMAT¶
-
-
class
symbol_table
¶ - #include <symtab.hh>
Public Functions
-
symbol_table
()¶
-
long
ieee
(double)¶
-
pool_index
pool_install
(char*)¶ Install a string (an identifier or a string constant) in the string pool. Returns the index to the installed string.
-
char *
pool_lookup
(const pool_index)¶ Given a
pool_index
into the string pool, returns the string it points to.
-
bool
pool_compare
(const pool_index, const pool_index)¶ Compare two strings taking their respective
pool_index
as arguments. Returns true if they are identical, and false otherwise. Note that it is not enough to just check that the indices are identical. Why not?
-
pool_index
pool_forget
(const pool_index)¶ Remove last installed entry from the string pool. This will only be useful if you opt to implement shared strings.
-
char *
fix_string
(const char*)¶ Remove double
''
in strings constants.Internalizes a string constant. You hopefully use this method in several labs.
-
char *
capitalize
(const char*)¶ Capitalizes a string. You hopefully use this method in several labs.
-
hash_index
hash
(const pool_index)¶ Given a
pool_index
to a string, return its hash index.
-
sym_index
install_symbol
(const pool_index, const sym_type tag)¶ Installs a symbol in the symbol table and returns its index. This method installs a symbol in the symbol table and returns its index. If the symbol already existed at the same lexical level (i.e. two objects with the same identifi and value of the attribute level), the object will not be installed, and the index of the symbol that already exists is returned.
If a symbol is installed, its tag will be set to
SYM_UNDEF
(which is done by default in the symbol constructor). The appropriate tag will then be set in theenter_
method that calledsymbol_table::install_symbol
. In this way name collisions can be discovered. For instance: The variablem
is declared twice on the same lexical level, and that is of course not correct. When the firstm
is encountered the methodsymbol_table::enter_variable
will try to install the symbol in the symbol table. It callssymbol_table::install_symbol
which creates and install a symbol of the correct type. The symbol’s tag is now set toSYM_UNDEF
. Whensymbol_table::install_symbol
finishes, the execution continues insidesymbol_table::enter_variable
and the method checks if the recent installed symbol’s tag is set toSYM_UNDEF
, and if it’s true, it changes the tag toSYM_VAR
. When the secondm
is encountered the procedure is repeated, but this timesymbol_table::install_symbol
returns thesym_index
to the firstm
. When checking the tag of this symbol,symbol_table::enter_variable
gets the answerSYM_VAR
and notSYM_UNDEF
. Thereforesymbol_table::enter_variable
knows that a symbol with this name already exists in the symbol table at this lexical level and outputs an error message. The secondm
is never installed. Furthermore, the level attribute will be set to the current lexical level,symbol_table#current_level
(which is currently zero).Note that the first argument to
symbol_table::install_symbol
is an index to the string table (symbol_table#string_pool
). This is, of course, what the scanner outputs in theYYSTYPE::pool_p
field of theyylval
union. If you had problems understanding what it was for earlier, hopefully some of that has become more clear now!The second argument is the tag that the symbol should have, it denotes which symbol class should be used (
constant_symbol
,variable_symbol
, etc.).
-
sym_index
lookup_symbol
(const pool_index)¶ Look for a symbol with the same identifier as the argument specifies in the string table, and returns its symbol table index. The search is performed according to the scoping rules, i.e. from the current lexical level and outwards. Make sure you understand what this means! If the object is not found,
NULL_SYM
is returned.
-
void
print
(int)¶ Very useful method for dumping the symbol table to stdout. The value of the argument determines what info will be printed:
- 1
Print one line of info per symbol table entry.
- 2
Print (only) the string table, showing the current pool_pos.
- 3
Print (only) the non-zero elements in the hash table.
- any other
Print detailed information about every symbol in the symbol table. Watch out, though: this gets very long if you have more than a few symbols installed.
-
pool_index
get_symbol_id
(const sym_index)¶ Given a symbol table index, return its pool_index, or 0 (zero) if no such symbol existed.
-
sym_index
get_symbol_type
(const sym_index)¶ Given a symbol table index, returns its type (
void_type
,integer_type
, orreal_type
). If the symbol didn’t exist, returnsvoid_type
.
-
sym_type
get_symbol_tag
(const sym_index)¶ Given a symbol table index, returns its tag type (i.e., the tag marking which symbol class it is:
SYM_CONST
,SYM_VAR
).
-
void
set_symbol_type
(const sym_index, const sym_index)¶ Given a symbol table index to a symbol, and a symbol table index to a type (e.g.
integer_type
etc.), sets the symbol to that type. You shouldn’t need to use it in this lab.
-
long
get_next_label
()¶
-
sym_index
gen_temp_var
(sym_index)¶ Given a symbol table index to a type (e.g.,
integer_type
etc.), generates, installs and returns index to a temporary variable of that type. It is not meaningful to generate a temporary variable ofvoid_type
.Choose a method for giving the temporary variables names which can not collide with the user.
Note
The implementation used for the traces returns identifiers with exactly length
MAX_TEMP_VAR_LENGTH
. It pads the remainder of the identifier with spaces, giving temporary names such as:"$1 " "$2 " // ... "$1234 "
-
sym_index
enter_constant
(position_information*, const pool_index, const sym_index, const long)¶ Given position information, a
pool_index
to an identifier’s name, asym_index
to the desired type and an int representing the actual constant value, generate and install a constant of the desired type.
-
sym_index
enter_constant
(position_information*, const pool_index, const sym_index, const double)¶ Given position information, a
pool_index
to an identifier’s name, asym_index
to the desired type and an int representing the actual constant value, generate and install a constant of the desired type.
-
sym_index
enter_variable
(position_information*, const pool_index, const sym_index)¶ Given position information, a
pool_index
to an identifier’s name, and a sym_index to the desired type, generate and install a variable of the desired type.
-
sym_index
enter_variable
(const pool_index, const sym_index)¶ This convenience method is used for installing temporary variables for which position information is not relevant. See quads.cc (lab6).
-
sym_index
enter_array
(position_information*, const pool_index, const sym_index, const int)¶ Given position information, a
pool_index
to an identifier’s name, asym_index
to the desired type, and an array cardinality, generate and install an array of the desired type.
-
sym_index
enter_function
(position_information*, const pool_index)¶ Given position information, and a
pool_index
to an identifier’s name, generate and install a function.The type is set later on since it will not be known at symbol install time.
-
sym_index
enter_procedure
(position_information*, const pool_index)¶ Given position information, and a
pool_index
to an identifier’s name, generate and install a procedure.
-
sym_index
enter_parameter
(position_information*, const pool_index, const sym_index)¶ Given position information, a
pool_index
to an identifier’s name, and a sym_index to the desired type, generate and install a parameter of the desired type.
-
sym_index
enter_nametype
(position_information*, const pool_index)¶ Given position information, and a
pool_index
to an identifier’s name, generate and install a nametype of the desired type.Since DIESEL doesn’t allow user-defined types, you will never need to use this method. It is used from the symbol table class constructor to install the default types, though.
NOTE: Should perhaps be marked private?
-
sym_index
current_environment
()¶ Returns the symbol table index to the current environment, i.e., procedure/function.
-
void
open_scope
()¶ Opens a new lexical level.
The routine is called when the name of a procedure or function has been installed. Note that
proc
lies outside the lexical level thati
andloc
have, in this example:procedure proc(i : integer); var loc : integer; begin end;
The
#block_table
keeps track of the active blocks in the program. When we have treated the wholeproc
procedure above, we must make sure that theloc
variable is not “visible”. We shall soon see how this is achieved.
-
sym_index
close_scope
()¶ Closes the current lexical level and returns a symbol table index to the new lexical level.
The routine is called when we have finished with a procedure or function. The local variables that were there will then become “invisible”, i.e., the following program code can not reference them.
-
-
class
variable_symbol
: public symbol¶ - #include <symtab.hh>
Derived symbol type, used for variables.
Public Functions
-
variable_symbol
(const pool_index)¶
-
inline virtual variable_symbol *
get_variable_symbol
()¶
Protected Functions
-
virtual void
print
(ostream&)¶
-
-
struct
YYLTYPE
¶ - #include <scanner.hh>
For every token, these fields should be set to the correct position in the source code file.
-
union
YYSTYPE
¶ - #include <scanner.hh>
Public Members
-
pool_index
str
¶ Value of a string
T_STRINGCONST
-
pool_index
pool_p
¶ Value of an identifier
T_IDENT
-
pool_index
-
namespace
std
¶
-
file
ast.cc
- #include “ast.hh”
-
file
ast.hh
- #include “symtab.hh”#include “quads.hh”
Typedefs
-
typedef enum ast_node_types
ast_node_type
¶
Enums
-
enum
ast_node_types
¶ Values:
-
enumerator
AST_NODE
¶
-
enumerator
AST_STATEMENT
¶
-
enumerator
AST_EXPRESSION
¶
-
enumerator
AST_BINARYOPERATION
¶
-
enumerator
AST_BINARYRELATION
¶
-
enumerator
AST_LVALUE
¶
-
enumerator
AST_EXPR_LIST
¶
-
enumerator
AST_STMT_LIST
¶
-
enumerator
AST_ELSIF_LIST
¶
-
enumerator
AST_ID
¶
-
enumerator
AST_INDEXED
¶
-
enumerator
AST_ADD
¶
-
enumerator
AST_SUB
¶
-
enumerator
AST_OR
¶
-
enumerator
AST_AND
¶
-
enumerator
AST_MULT
¶
-
enumerator
AST_DIVIDE
¶
-
enumerator
AST_IDIV
¶
-
enumerator
AST_MOD
¶
-
enumerator
AST_EQUAL
¶
-
enumerator
AST_NOTEQUAL
¶
-
enumerator
AST_LESSTHAN
¶
-
enumerator
AST_GREATERTHAN
¶
-
enumerator
AST_PROCEDURECALL
¶
-
enumerator
AST_ASSIGN
¶
-
enumerator
AST_WHILE
¶
-
enumerator
AST_IF
¶
-
enumerator
AST_RETURN
¶
-
enumerator
AST_FUNCTIONCALL
¶
-
enumerator
AST_UMINUS
¶
-
enumerator
AST_NOT
¶
-
enumerator
AST_ELSIF
¶
-
enumerator
AST_INTEGER
¶
-
enumerator
AST_REAL
¶
-
enumerator
AST_FUNCTIONHEAD
¶
-
enumerator
AST_PROCEDUREHEAD
¶
-
enumerator
AST_PARAMETER
¶
-
enumerator
AST_CAST
¶
-
enumerator
Functions
-
ostream &
operator<<
(ostream&, ast_node*)
-
typedef enum ast_node_types
-
file
codegen.cc
- #include <iostream>#include <iomanip>#include <fstream>#include <stdio.h>#include <string.h>#include “symtab.hh”#include “quads.hh”#include “codegen.hh”
-
file
diesel_rts.c
- #include <stdio.h>
Functions
-
void
myputchar
(int ch)¶
-
void
-
file
error.cc
- #include <cstdlib>#include “error.hh”
Functions
-
ostream &
error
(string header)¶
-
ostream &
error
(position_information *pos)¶
-
void
fatal
(string msg)¶ Prints message, aborts compiling.
-
void
yyerror
(string msg)¶ This must be defined (for
flex
), but usingerror(pos) << "foo"
is preferable.
-
ostream &
type_error
()¶
-
ostream &
type_error
(position_information *pos)¶
-
ostream &
debug
(string header)¶
-
ostream &
debug
(position_information *pos)¶
Variables
-
int
error_count
= 0¶
-
ostream &
-
file
error.hh
- #include <iostream>#include <sstream>#include <ostream>
Functions
-
void
fatal
(string) Prints message, aborts compiling.
-
void
yyerror
(string) This must be defined (for
flex
), but usingerror(pos) << "foo"
is preferable.
-
ostream &
error
(string header = "Error: ")
-
ostream &
error
(position_information*)
-
ostream &
type_error
()
-
ostream &
type_error
(position_information*)
-
ostream &
debug
(string header = "Debug: ")
-
ostream &
debug
(position_information*)
-
void
-
file
main.cc
- #include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include “ast.hh”#include “parser.hh”
-
file
optimize.cc
- #include “optimize.hh”
Variables
-
ast_optimizer *
optimizer
= new ast_optimizer()¶
-
ast_optimizer *
-
file
optimize.hh
- #include “ast.hh”
Variables
-
ast_optimizer *
optimizer
-
ast_optimizer *
-
file
quads.cc
- #include <iostream>#include <iomanip>#include <stdio.h>#include “symtab.hh”#include “ast.hh”#include “quads.hh”
Defines
-
USE_Q
¶
-
-
file
quads.hh
- #include “ast.hh”
Enums
-
enum
quad_op_type
¶ Values:
-
enumerator
q_rload
¶
-
enumerator
q_iload
¶
-
enumerator
q_inot
¶
-
enumerator
q_ruminus
¶
-
enumerator
q_iuminus
¶
-
enumerator
q_rplus
¶
-
enumerator
q_iplus
¶
-
enumerator
q_rminus
¶
-
enumerator
q_iminus
¶
-
enumerator
q_ior
¶
-
enumerator
q_iand
¶
-
enumerator
q_rmult
¶
-
enumerator
q_imult
¶
-
enumerator
q_rdivide
¶
-
enumerator
q_idivide
¶
-
enumerator
q_imod
¶
-
enumerator
q_req
¶
-
enumerator
q_ieq
¶
-
enumerator
q_rne
¶
-
enumerator
q_ine
¶
-
enumerator
q_rlt
¶
-
enumerator
q_ilt
¶
-
enumerator
q_rgt
¶
-
enumerator
q_igt
¶
-
enumerator
q_rstore
¶
-
enumerator
q_istore
¶
-
enumerator
q_rassign
¶
-
enumerator
q_iassign
¶
-
enumerator
q_call
¶
-
enumerator
q_rreturn
¶
-
enumerator
q_ireturn
¶
-
enumerator
q_lindex
¶
-
enumerator
q_rrindex
¶
-
enumerator
q_irindex
¶
-
enumerator
q_itor
¶
-
enumerator
q_jmp
¶
-
enumerator
q_jmpf
¶
-
enumerator
q_param
¶
-
enumerator
q_labl
¶
-
enumerator
q_nop
¶
-
enumerator
-
enum
-
file
scanner.hh
- #include “symtab.hh”
Defines
-
T_EOF
¶
-
T_ERROR
¶
-
T_DOT
¶
-
T_SEMICOLON
¶
-
T_EQ
¶
-
T_COLON
¶
-
T_LEFTBRACKET
¶
-
T_RIGHTBRACKET
¶
-
T_LEFTPAR
¶
-
T_RIGHTPAR
¶
-
T_COMMA
¶
-
T_LESSTHAN
¶
-
T_GREATERTHAN
¶
-
T_ADD
¶
-
T_SUB
¶
-
T_MUL
¶
-
T_RDIV
¶
-
T_OF
¶
-
T_IF
¶
-
T_DO
¶
-
T_ASSIGN
¶
-
T_NOTEQ
¶
-
T_OR
¶
-
T_VAR
¶
-
T_END
¶
-
T_AND
¶
-
T_IDIV
¶
-
T_MOD
¶
-
T_NOT
¶
-
T_THEN
¶
-
T_ELSE
¶
-
T_IDENT
¶
-
T_CONST
¶
-
T_ARRAY
¶
-
T_BEGIN
¶
-
T_WHILE
¶
-
T_ELSIF
¶
-
T_INTNUM
¶
-
T_RETURN
¶
-
T_PROGRAM
¶
-
T_REALNUM
¶
-
T_FUNCTION
¶
-
T_PROCEDURE
¶
-
T_STRINGCONST
¶
-
NR_SYMS
¶
-
-
file
semantic.cc
- #include “semantic.hh”
-
file
symbol.cc
- #include “symtab.hh”
-
file
symtab.cc
- #include <stdlib.h>#include <stdio.h>#include <assert.h>#include <iomanip>#include <fstream>#include <iostream>#include <ctype.h>#include <string.h>#include “symtab.hh”
Variables
-
symbol_table *
sym_tab
= new symbol_table()¶ A global pointer to the symbol_table.
You will use functions in the symbol_table to install strings (and, if you want to make your compiler use shared strings, to reduce memory requirements, to look-up and identify symbols, as well as forget strings).
-
symbol_table *
-
file
symtab.hh
- #include “error.hh”
Defines
-
TEST_SCANNER
¶
Typedefs
-
typedef long
pool_index
¶
-
typedef long
hash_index
¶
-
typedef long
sym_index
¶
-
typedef int
block_level
¶
-
typedef enum symbol_types
sym_type
¶
Enums
Functions
-
ostream &
short_symbols
(ostream&)
-
ostream &
summary_symbols
(ostream&)
-
ostream &
long_symbols
(ostream&)
-
ostream &
operator<<
(ostream&, symbol*)
Variables
-
const block_level
MAX_BLOCK
= 8¶ Max allowed nesting levels (size of block table).
-
const hash_index
MAX_HASH
= 512¶ Max size of hash table.
-
const pool_index
BASE_POOL_SIZE
= 1024¶ Base size of string pool.
-
const int
ILLEGAL_ARRAY_CARD
= -1¶ Signifies a non-int array size. The code using this constant has already been written for you.
-
const int
MAX_TEMP_VARS
= 999999¶ Sets a limit for max nr of temporary variables. Should never be reached unless someone really, really starts to dig writing huge programs in Diesel. See quads.cc.
-
const int
MAX_TEMP_VAR_LENGTH
= 8¶
-
symbol_table *
sym_tab
A global pointer to the symbol_table.
You will use functions in the symbol_table to install strings (and, if you want to make your compiler use shared strings, to reduce memory requirements, to look-up and identify symbols, as well as forget strings).
-
sym_index
void_type
-
sym_index
integer_type
-
sym_index
real_type
-
-
dir
TDDE66/code
-
dir
TDDE66/code/remaining