home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / YACCUNX.ZIP / SPIKE.Y < prev    next >
Encoding:
Text File  |  1983-12-26  |  4.7 KB  |  223 lines

  1.  
  2. %term CKB LKB SKB OBJ DBJ SLT FAC PTI PTR PTX GTI GTR GTX
  3. %term AMI API AGI AMR APR AGR PRO PRS EXT
  4.  
  5. %union
  6. {
  7.     int    ival;
  8.     float    fval;
  9.     char   *tval;
  10. }
  11.  
  12. %term <tval> TEXT
  13. %term <ival> ICON
  14. %term <fval> FCON
  15.  
  16. %type <tval> name, object, type, generalizations, groups, 
  17. %type <tval> slot, datatype, facet, text
  18. %type <ival> integer, size origin, index
  19. %type <fval> real
  20.  
  21. %{
  22. char kbname[30] = "";
  23. %}
  24. %%
  25. load:      load command | command;
  26.  
  27. command:      createkb
  28.         | loadkb
  29.         | storekb
  30.         | createobject
  31.         | deleteobject
  32.         | createslot
  33.         | createfacet
  34.         | putfacett
  35.         | putfaceti
  36.         | putfacetr
  37.         | getfacett
  38.         | getfaceti
  39.         | getfacetr
  40.         | makearrayi
  41.         | putarrayi
  42.         | getarrayi
  43.         | makearrayr
  44.         | putarrayr
  45.         | getarrayr
  46.         | printobject
  47.         | printslot
  48.         | exit;
  49.  
  50. createkb:    CKB name = {
  51.             if(createkb($2)) {
  52.                 printf("KB %s created\n", $2);
  53.                 strcpy(kbname, $2);
  54.             } else
  55.                 printf("ERROR: KB %s not created\n", $2);
  56.         };
  57.  
  58. loadkb:        LKB name = {
  59.             if(loadkb($2)) {
  60.                 printf("KB %s loaded\n", $2);
  61.                 strcpy(kbname, $2);
  62.             } else
  63.                 printf("ERROR: KB %s not loaded\n", $2);
  64.         };
  65.  
  66. storekb:    SKB name = {
  67.             if(storekb($2, 0))
  68.                 printf("KB %s stored\n", $2);
  69.             else
  70.                 printf("ERROR: KB %s not stored\n", $2);
  71.         };
  72.  
  73. createobject:    OBJ object type generalizations groups = {
  74.             if(ccreateobject($2, $3, $4, $5))
  75.                 printf("Object %s created\n", $2);
  76.             else
  77.                 printf("ERROR: Object %s not created\n", $2);
  78.         };
  79.  
  80. deleteobject:    DBJ object = {
  81.             if(cdeleteobject($2, 1))
  82.                 printf("Object %s and progeny deleted\n", $2);
  83.             else
  84.                 printf("ERROR: Object %s not deleted\n", $2);
  85.         };
  86.  
  87. createslot:    SLT object slot datatype = {
  88.             if(ccreateslot($2, $3, $4))
  89.                 printf("Slot %s created\n", $3);
  90.             else
  91.                 printf("ERROR: Slot %s not created\n", $3);
  92.         };
  93.  
  94. createfacet:    FAC object slot facet = {
  95.             if(ccreatefacet($2, $3, $4))
  96.                 printf("Facet %s created\n", $4);
  97.             else
  98.                 printf("ERROR: Facet %s not created\n", $4);
  99.         };
  100.  
  101. putfaceti:    PTI object slot facet integer = {
  102.             cputfaceti($2, $3, $4, $5);
  103.         };
  104.  
  105. putfacetr:    PTR object slot facet real = {
  106.             cputfacetr($2, $3, $4, $5);
  107.         };
  108.  
  109. putfacett:    PTX object slot facet text = {
  110.             cputfacett($2, $3, $4, $5);
  111.         };
  112.  
  113. getfaceti:    GTI object slot facet = {int ival;
  114.             ival = cgetfaceti($2, $3, $4);
  115.             printf("value = %d\n", ival);
  116.         };
  117.  
  118. getfacetr:    GTR object slot facet = {float fval;
  119.             fval = cgetfacetr($2, $3, $4);
  120.             printf("value = %f\n", fval);
  121.         };
  122.  
  123. getfacett:    GTX object slot facet = {char *tval;
  124.             cgetfacett($2, $3, $4);
  125.             printf("value = %s\n", tval);
  126.         };
  127.  
  128. makearrayi:    AMI object slot facet size origin = {
  129.             cmakearrayi($2, $3, $4, $5, $6);
  130.         };
  131.  
  132. putarrayi:    API object slot facet index integer = {
  133.             cputarrayi($2, $3, $4, $5, $6);
  134.         };
  135.  
  136. getarrayi:    AGI object slot facet index = {int ival;
  137.             cgetarrayi($2, $3, $4, $5);
  138.             printf("value = %d\n", ival);
  139.         };
  140.  
  141. makearrayr:    AMR object slot facet size origin = {
  142.             cmakearrayr($2, $3, $4, $5, $6);
  143.         };
  144.  
  145. putarrayr:    APR object slot facet index integer = {
  146.             cputarrayr($2, $3, $4, $5, $6);
  147.         };
  148.  
  149. getarrayr:    AGR object slot facet index = {float fval;
  150.             fval = cgetarrayr($2, $3, $4, $5);
  151.             printf("value = %f\n", fval);
  152.         };
  153.  
  154. printobject:    PRO object = {
  155.             cprintobject($2, 1);
  156.         };
  157.  
  158. printslot:    PRS object slot  = {
  159.             cprintslot($2, $3, 1);
  160.         };
  161.  
  162. exit:        EXT = {
  163.             exit();
  164.         };
  165.  
  166. name:        TEXT = {$<tval>$ = save(yytext);};
  167. object:        TEXT = {static char *lastobject;
  168.             if(yytext[0] != '"')
  169.                 $<tval>$ = lastobject = save(yytext);
  170.             else
  171.                 $<tval>$ = lastobject;
  172.             };
  173. type:        TEXT = {$<tval>$ = save(yytext);};
  174. generalizations:TEXT = {$<tval>$ = save(yytext);};
  175. groups:        TEXT = {$<tval>$ = save(yytext);};
  176. slot:        TEXT = {static char *lastslot;
  177.             if(yytext[0] != '"')
  178.                 $<tval>$ = lastslot = save(yytext);
  179.             else
  180.                 $<tval>$ = lastslot;
  181.             };
  182. facet:        TEXT = {static char *lastfacet;
  183.             if(yytext[0] != '"')
  184.                 $<tval>$ = lastfacet = save(yytext);
  185.             else
  186.                 $<tval>$ = lastfacet;
  187.             };
  188. datatype:    TEXT = {$<tval>$ = save(yytext);};
  189. text:        TEXT = {$<tval>$ = save(yytext);};
  190. integer:    ICON = {$<ival>$ = yyival;};
  191. size:        ICON = {$<ival>$ = yyival;};
  192. origin:        ICON = {$<ival>$ = yyival;};
  193. index:        ICON = {$<ival>$ = yyival;};
  194. real:        FCON = {$<fval>$ = yyfval;};
  195.  
  196. %%
  197.  
  198. #include <stdio.h>
  199. #include "spikelex.c"
  200. #include "centry.c"
  201.  
  202. yyerror(s)
  203. char *s;
  204. {
  205.     extern int yyline;
  206.  
  207.     if (yyline)
  208.         fprintf(stderr, "%d: ", yyline);
  209.     fprintf(stderr, "%s\n", s);
  210. }
  211.  
  212. save(s)
  213. char *s;
  214. {
  215.     char *t;
  216.     if(t = malloc(strlen(s)+1)) {
  217.         strcpy(t, s);
  218.         return(t);
  219.     } else {
  220.         printf("Out of Memory in save\n");
  221.         exit();
  222.     }
  223. }
  224.