aboutsummaryrefslogtreecommitdiff
path: root/src/gram.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/gram.y')
-rw-r--r--src/gram.y123
1 files changed, 92 insertions, 31 deletions
diff --git a/src/gram.y b/src/gram.y
index a60f170..93484a7 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -34,7 +34,12 @@ static int convert_pos(char *text, int *pos);
%token NODE POS END MEANING ALIAS ANT TOPIC FORMS XREF
%token <string> STRING
-%type <string> string
+%type <num> pos
+%type <string> string forms
+%type <header> nodehdr alias
+%type <descr> descr
+%type <list> list aliases descrlist header
+%type <item> item
%union {
int num;
@@ -49,90 +54,146 @@ static int convert_pos(char *text, int *pos);
%%
input : list
+ {
+ node_list = $1;
+ }
;
list : item
+ {
+ $$ = list_create();
+ switch ($1.type) {
+ case item_node:
+ list_append($$, $1.v.node);
+ break;
+
+ case item_list:
+ list_concat($$, $1.v.list);
+ list_destroy(&$1.v.list, NULL, NULL);
+ }
+ }
| list item
+ {
+ switch ($2.type) {
+ case item_node:
+ list_append($1, $2.v.node);
+ break;
+
+ case item_list:
+ list_concat($1, $2.v.list);
+ list_destroy(&$2.v.list, NULL, NULL);
+ }
+ $$ = $1;
+ }
;
-item : header descrlist END
+item : header descrlist end
{
- printf("</NODE>\n\n");
+ $$.type = item_node;
+ $$.v.node = create_node($1, $2);
}
- | thead list END
+ | TOPIC string list end
{
- printf("</T>\n");
+ $$.type = item_list;
+ $$.v.list = $3;
+ list_iterate($3, _register_topic,
+ make_descr(descr_topic, $2));
}
;
-thead : TOPIC string
- {
- printf("<T ID=\"%s\">\n", $2);
- }
- ;
-
end : END
;
header : nodehdr
+ {
+ $$ = list_create();
+ list_append($$, $1);
+ }
| nodehdr aliases
+ {
+ list_prepend($2, $1);
+ $$ = $2;
+ }
;
-nodehdr : node key pos forms
- ;
-
-node : NODE
- {
- printf("<NODE>\n");
- }
- ;
-
-key : string
- {
- printf(" <K>%s</K>\n", $1);
+nodehdr : NODE string pos forms
+ {
+ $$ = emalloc(sizeof(*$$));
+ $$->key = $2;
+ $$->pos = $3;
+ $$->forms = $4;
}
;
-
+
pos : /* empty */
+ {
+ $$ = -1;
+ }
| POS string
{
- printf(" <P>%s</P>\n", $2);
+ if (convert_pos($2, &$$))
+ YYERROR;
}
;
forms : /* empty */
+ {
+ $$ = NULL;
+ }
| FORMS string
{
- printf(" <F>%s</F>\n", $2);
+ $$ = $2;
}
;
aliases : alias
+ {
+ $$ = list_create();
+ list_append($$, $1);
+ }
| aliases alias
+ {
+ list_append($1, $2);
+ $$ = $1;
+ }
;
-alias : ALIAS key pos forms
+alias : ALIAS string pos forms
+ {
+ $$ = emalloc(sizeof(*$$));
+ $$->key = $2;
+ $$->pos = $3;
+ $$->forms = $4;
+ }
;
descrlist: descr
+ {
+ $$ = list_create();
+ list_append($$, $1);
+ }
| descrlist descr
+ {
+ list_append($1, $2);
+ $$ = $1;
+ }
;
descr : TOPIC string
{
- printf(" <T ID=\"%s\" />\n", $2);
+ $$ = make_descr(descr_topic, $2);
}
| MEANING string
{
- printf(" <M>%s</M>\n", $2);
+ $$ = make_descr(descr_meaning, $2);
}
| ANT string
{
- printf(" <A>%s</A>\n", $2);
+ $$ = make_descr(descr_antonym, $2);
}
| XREF string
{
- printf(" <X>%s</X>\n", $2);
+ $$ = make_descr(descr_xref, $2);
}
;

Return to:

Send suggestions and report system problems to the System administrator.