Compare commits
2 Commits
9cd417d5da
...
b06406e48a
Author | SHA1 | Date |
---|---|---|
Øyvind Skaaden | b06406e48a | |
Øyvind Skaaden | 6b3065fe11 |
|
@ -23,6 +23,7 @@ int yyerror ( const char *error );
|
|||
/* These are defined in the parser generated by bison */
|
||||
extern int yylineno;
|
||||
extern int yylex ( void );
|
||||
extern int yylex_destroy( void );
|
||||
extern char yytext[];
|
||||
|
||||
/* Global state */
|
||||
|
|
|
@ -291,37 +291,6 @@ flatten(node_t **simplified, node_t *root)
|
|||
static void
|
||||
simplify_tree ( node_t **simplified, node_t *root )
|
||||
{
|
||||
/* TODO: Simplify the syntax tree structure
|
||||
1. prune children: Delete nodes which can only ever have 1 child and no
|
||||
meaningful data, and associate their child directly with their parent.
|
||||
|
||||
2. resolve constant expressions: Compute the value of subtrees representing
|
||||
arithmetic with constants, and replace them with their value.
|
||||
|
||||
3. flatten: Delete internal nodes of list structures, leaving only a parent
|
||||
node with a list type, and all list items as its children. Print list items
|
||||
can be associated directly with the print statement.
|
||||
|
||||
VARIABLE_LIST VARIABLE_LIST
|
||||
VARIABLE_LIST IDENTIFIER_DATA(i)
|
||||
VARIABLE_LIST IDENTIFIER_DATA(j)
|
||||
VARIABLE_LIST IDENTIFIER_DATA(k)
|
||||
VARIABLE_LIST IDENTIFIER_DATA(l)
|
||||
IDENTIFIER_DATA(i) becomes IDENTIFIER_DATA(m)
|
||||
IDENTIFIER_DATA(j)
|
||||
IDENTIFIER_DATA(k)
|
||||
IDENTIFIER_DATA(l)
|
||||
IDENTIFIER_DATA(m)
|
||||
|
||||
Tip: implement these three steps as separate functions to complete one task
|
||||
at the time. e.g.:
|
||||
prune_children(root);
|
||||
redolve_constant_expressions(root);
|
||||
flatten(root);
|
||||
simplified = &root->children[0];
|
||||
node_finalize(root);
|
||||
*/
|
||||
|
||||
if (!root)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue