Hi,


I'm trying to build Said(), and I've got a feeling that a few things are
still missing. Please have a look at my attempt to write down the grammar-
I've replaced some of the macros with more readable symbols (and removed
some whitespace), but other than that, this is what I've got:

/* said_branch(a, b, c, d) is a function that allocates several nodes and
** leaves, fills in the node values a and b, and links c to #1 and d to
** #2 (c, d may be NULL) and returns the address of the first node of that
** branch.
** said_leaf_node(nr) allocates a leaf node, fills it with nr, and returns
** its address.
*/

%token WGROUP /* Word group */


Subexpression:    /* empty */
{ $$ = SAID_BRANCH_NULL }
                | Expression '<' Subexpression '<' Subexpression
{ $$ = said_branch(0x141, 0x144, $1, said_branch(0x144 0x14f, $3, $5)) }
/* This is my attempt to interpret comment "*" from the Said specification*/
                | Expression '<' Subexpression
{ $$ = said_branch(0x144, 0x14f, $1, $3) }
                | Expression '[' '<' Subexpression ']'
{ $$ = said_branch(0x152, 0x144, $1, $4) }
                | Expression
{ $$ = said_branch(0x141, 0x14f, $1, SAID_BRANCH_NULL) }
                ;



Expression:       MainExp
                | MainExp ',' Expression
/* Missing: Those two need to be linked somehow */
                ;



MainExp:          '[' Subexpression ']'
{ $$ = said_branch(0x152, 0x14c, $2, SAID_BRANCH_NULL) }
                | '(' Subexpression ')'
{ $$ = said_branch(0x141, 0x14c, $2, SAID_BRANCH_NULL) }
                | WGROUP
{ $$ = said_branch(0x141, 0x153, said_leaf_node($1), SAID_BRANCH_NULL) }
                ;



BeforeExp:        /* empty */
                        { $$ = SAID_BRANCH_NULL }
                | '/' Subexpression
/*I suppose that $$ shouldn't be $2, unless this thing is meaningless...*/
                ;



NestedBeforeA:    BeforeExp
{ $$ = said_branch(0x142, 0x14a, $1, SAID_BRANCH_NULL) }
                | '[' BeforeExp ']'
{ $$ = said_branch(0x152, 0x142, $2, SAID_BRANCH_NULL) }
                ;



NestedBeforeB:    BeforeExp
{ $$ = said_branch(0x143, 0x14a, $1, SAID_BRANCH_NULL) }
                | '[' BeforeExp ']'
{ $$ = said_branch(0x152, 0x143, $2, SAID_BRANCH_NULL) }
                ;



MoreAfter:        /* empty */
                        { $$ = SAID_BRANCH_NULL }
                | '>'
{ $$ = said_branch(0x14b, SAID_LONG(SAID_GT), SAID_BRANCH_NULL,
SAID_BRANCH_NULL) }
                ;



said_spec:        Subexpression NestedBeforeA MoreAfter
                | Subexpression NestedBeforeA NestedBeforeB MoreAfter
                ;
/* This needs to be linked somehow. */


Thanks for any help,

llap,
 Christoph

Reply via email to