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

  1. %union
  2. {
  3.     char   *tval;
  4.     int        ival;
  5.     float    fval;
  6.     long    lval;
  7. }
  8.  
  9. %term <tval> TCON
  10. %term <ival> ICON
  11. %term <fval> FCON
  12.  
  13. %type <tval> text
  14. %type <ival> integer
  15. %type <fval> real
  16.  
  17. %%
  18.  
  19. dialog:        /* empty */ | dialog command;
  20.  
  21. command:    text integer real = {
  22.             printf("command: text = %s, integer = %d, real = %f\n",$1,$2,$3);
  23.             };
  24.  
  25. text:        TCON = {$<tval>$ = save(yytext);printf("YACC/TCON: %s\n", $<tval>$);};
  26.  
  27. integer:    ICON = {$<ival>$ = yyival;printf("YACC/ICON: %d\n", $<ival>$);};
  28.  
  29. real:        FCON = {$<fval>$ = yyfval;printf("YACC/FCON: %f\n", $<fval>$);};
  30.  
  31. %%
  32.  
  33. #include <stdio.h>
  34.  
  35. extern char yytext[];
  36. extern int yyival;
  37. extern float yyfval;
  38.  
  39. main()
  40. {
  41.     if(yyparse())
  42.         printf("Fail\n");
  43.     else
  44.         printf("Success\n");
  45. }
  46.  
  47. yyunion(to, from)
  48. YYSTYPE *to, *from;
  49. {
  50.     to->lval = from->lval;
  51. }
  52.  
  53. yyerror(s)
  54. char *s;
  55. {
  56.     extern int yyline;
  57.  
  58.     if (yyline)
  59.         fprintf(stderr, "%d: ", yyline);
  60.     fprintf(stderr, "%s\n", s);
  61. }
  62.  
  63. save(s)
  64. char *s;
  65. {
  66.     char *t;
  67.     if(t = malloc(strlen(s)+1)) {
  68.         strcpy(t, s);
  69.         return(t);
  70.     } else {
  71.         printf("Out of Memory in save\n");
  72.         exit();
  73.     }
  74. }
  75.