home *** CD-ROM | disk | FTP | other *** search
-
- %{
-
- #import <ansi/stdlib.h>
- #import <ansi/string.h>
- #import <ansi/stdio.h>
- #import <ansi/ctype.h>
- #import <ansi/math.h>
-
- #import "../Tree.h"
-
- extern void lispdocPrepareTextToScan(NXStream *text);
- extern yylex(), yyparse();
-
- static void yyerror(char *s);
- static NXZone *treeZone;
- static Properties *treeProps;
- static Tree *resultTree;
- static Tree *lispdocMakeTree(char *name, char *description);
- static Tree *lispdocAddChildren(Tree *tree, List *children);
- static List *lispdocGatherSibling(List *list, Tree *sibling);
- static List *lispdocMakeChildrenList(Tree *child);
-
- %}
-
- %union{
- Tree *tree;
- char *name;
- List *list;
- }
-
- %token <name> NAME DESCRIPTION
- %token LISPKEY
- %left LP RP
-
- %type <tree> lispnode lispdoc lispbody
- %type <list> nodelist
-
- %%
-
- lispdoc: lispnode
- {
- resultTree = $1;
- }
- | /* empty */
- {
- resultTree = nil;
- }
- ;
-
- lispnode: LP lispbody nodelist RP
- {
- $$ = lispdocAddChildren($2, $3);
- }
- | LP lispbody RP
- {
- $$ = $2;
- }
- | LP RP
- {
- $$ = nil;
- }
- ;
-
- lispbody: LISPKEY NAME LP DESCRIPTION RP
- {
- $$ = lispdocMakeTree($2, $4);
- free($2);
- free($4);
- }
- ;
-
- nodelist: nodelist lispnode
- {
- $$ = lispdocGatherSibling($1, $2);
- }
- | lispnode
- {
- $$ = lispdocMakeChildrenList($1);
- }
- ;
-
- %%
-
- static Tree *lispdocMakeTree(char *name, char *description)
- {
- return [[[Tree allocFromZone:treeZone]
- initLabel:name props:treeProps] setDescription:description];
- }
-
- static Tree *lispdocAddChildren(Tree *tree, List *children)
- {
- Tree *child;
- int i;
-
- for(i = 0; i < [children count]; i++){
- child = (Tree *)[children objectAt:i];
- [tree addTree:child];
- }
- [children free];
- return tree;
- }
-
- static List *lispdocGatherSibling(List *list, Tree *sibling)
- {
- [list addObject:sibling];
- return list;
- }
-
- static List *lispdocMakeChildrenList(Tree *child)
- {
- List *list;
-
- list = [[List alloc] init];
- [list addObject:child];
- return list;
- }
-
- id createLispTree(NXStream *stream, Properties *props, NXZone *zone)
- {
- int r;
-
- lispdocPrepareTextToScan(stream);
- treeZone = zone;
- treeProps = props;
- r = yyparse();
- return resultTree;
- }
-
- static void yyerror(char *s)
- {
- printf("parser error:%s\n",s);
- }
-
-