// Author : Gregory R. Olsen // Center for Design Research, Stanford University // 560 Panama Street // Stanford, CA 94305-2232 // olsen@cs.stanford.edu // Copyright (c) 1993 Stanford University. All rights reserved. /* * Permission is hereby granted, without written agreement and without * license, to use, copy, modify, and distribute this software and its * documentation for non-commercial use, provided that the above * copyright notice and the following two paragraphs appear in * all copies of this software. * * THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY SPECIAL, * INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER OR NOT ADVISEDOF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY * OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. */ #include #include #include #include "KIFClass.h" #include "KIFGrammar.tab.h" //////////////////////////////////////////// /* FUNCTION: kif_parse ABSTRACT: Function that parses a given string using LEX and YACC based parser to generate an object in the KIF class hierarchy. */ expression *kif_parse(int termp, const char *kstring) { char key[] = ":F"; extern int yyparse(void); extern expression *kif_result; extern char inputstring[]; extern char *inputstringptr; /* current position in inputstring */ extern int inputstringlim; /* end of data */ if (kstring == NULL) return(NULL); /* Put KIF string into parse buffer */ /* A tag ':key' is put at the beginning of the input buffer so as to identify the expected top-level class to be parsed possible values are: :F for form (i.e. sentence, definition, or rule) :T for term */ if (termp) strcpy(key,":T"); sprintf(inputstring,"%s %s",key,kstring); // fprintf(stdout,"Parsing: %s\n",inputstring); inputstringlim = strlen(inputstring); inputstringptr = &inputstring[0]; /* * * * * * * * * * * * * * * * * * */ /* Call parser (Uses YACC and FLEX) */ if (yyparse()) return NULL; else return kif_result; } /* kif_parse */