home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / SPIKE.Y < prev    next >
Text File  |  1983-12-26  |  5KB  |  223 lines

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