Constructing Abstract Syntax tree for expression
. Each node can be represented as a record
. operators : one field for operator, remaining fields ptrs to operands
mknode( op,left,right )
. identifier : one field with label id and another ptr to symbol table
mkleaf(id,entry)
. number : one field with label num and another to keep the value of the number
mkleaf(num,val)
Each node in an abstract syntax tree can be implemented as a record with several fields. In the node for an operator one field identifies the operator (called the label of the node) and the remaining contain pointers to the nodes for operands. Nodes of an abstract syntax tree may have additional fields to hold values (or pointers to values) of attributes attached to the node. The functions given in the slide are used to create the nodes of abstract syntax trees for expressions. Each function returns a pointer to a newly created note.
|