/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
parse.c
*/
/* Routines for parse-tree construction and syntax directed translation.
This is all in C, since lex and yacc generate C. I could wrap some
C++ in C linkage, but I'd rather have total flexibility. -Melvin
*/
#include "parse.h"
#include "yacc.tab.h"
/* Temporary, convert to list or other structure which can extend */
int cur_unit;
node * unit[256];
/* Add (not insert) another leaf on the extreme right (outside) of the tree */
node * add_leaf_right( node * tree, node * leaf )
{
node * ptr;
for( ptr = tree; ptr->right; ptr = ptr->right )
;
if( ptr )
ptr->right = leaf;
return tree;
}
node * mknode( int op, sym * sym_ptr, node * left, node * right )
{
node * new_node = malloc_node();
new_node->op = op;
new_node->left = left;
new_node->right = right;
new_node->sym_ptr = sym_ptr;
return new_node;
}
/* mkleaf_id( node_op, sym_ptr ) */
node * mkleaf_id( int type, sym * sym_ptr )
{
node * new_node = calloc_node();
new_node->op = OP_ID;
new_node->sym_ptr = sym_ptr;
sym_ptr->type = type;
return new_node;
}
node * mkleaf_declaration( int type, sym * sym_ptr )
{
node * new_node = calloc_node();
new_node->op = OP_DECLARE;
new_node->sym_ptr = sym_ptr;
sym_ptr->type = type;
return new_node;
}
/* mkleaf_constant_int( 123 ) */
node * mkleaf_constant_int( long lval )
{
node * new_node = calloc_node();
new_node->u.lval = lval;
new_node->op = OP_CONSTANT;
new_node->type = TYPE_INT;
return new_node;
}
/* mkleaf_constant_int( 123 ) */
node * mkleaf_constant_float( float fval )
{
node * new_node = calloc_node();
new_node->u.fval = fval;
new_node->op = OP_CONSTANT;
/*
new_node->type = TYPE_FLOAT;
*/
return new_node;
}
/* Used to string statements together in the yacc grammar like this:
compound_statement:
statement compound_statement
{ mkleaf_statement( $1, $2 ); }
| statement
{ mklead_statement( $1, 0 ); } <-- last statement is null
*/
node * mkleaf_statement( node * code, node * next_statement )
{
return 0;
}
node * mkleaf_function_def( int type, sym * fun, node * statements )
{
node * new_node = calloc_node();
new_node->op = OP_DEFINE;
if( fun )
{
new_node->sym_ptr = fun;
new_node->sym_ptr->type = type | TYPE_FUNCTION;
}
new_node->right = statements;
return new_node;
}
int add_tree( node * tree )
{
unit[ cur_unit++ ] = tree;
}