home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / math / notebook.y < prev    next >
Encoding:
Lex Description  |  1989-04-30  |  1.7 KB  |  92 lines

  1.  
  2. %{
  3. #include <stdio.h>
  4. extern char * nbval;
  5. extern char * nboldval;
  6. %}
  7.  
  8.  
  9. %token OPENNOTEBOOK CLOSENOTEBOOK
  10. %token NBOPENHEAD OPENHEAD CLOSEHEAD
  11. %token OUTPUTSUBHEAD SETTINGSSUBHEAD
  12. %token CLOSECOMMENT OPENCOMMENT
  13. %token CONTENTS
  14. %token SEMI EQUAL COMMA TOKEN
  15.  
  16. %%
  17.  
  18. notebook    : OPENNOTEBOOK { printf("(setq free-cells ())\n");
  19.                 printf("(setq notebook-control '\n("); } 
  20.           NBOPENHEAD control.list CLOSEHEAD 
  21.             { printf("))\n\n");
  22.               printf("(setq cell-vector [\n"); } 
  23.             cell.list 
  24.             { printf("\n])\n"); }
  25.             CLOSENOTEBOOK
  26.         ;
  27.  
  28. cell.list    : OPENHEAD { printf("\n("); } control.list 
  29.           CLOSEHEAD { printf(" (contents . \""); } 
  30.              cell.contents { printf("))"); }
  31.              cell.list
  32.         | ;
  33.  
  34. cell.contents    : CLOSECOMMENT content.list OPENCOMMENT
  35.         | content.list
  36.         ;
  37.  
  38. content.list    : content.lines /* only for non-subheadings */
  39.         | content.lines
  40.           OUTPUTSUBHEAD
  41.         { printf("\n)\n(output-form . \""); }  content.lines
  42.         | content.lines
  43.           SETTINGSSUBHEAD
  44.         { printf("\n)\n(styles . \""); } content.lines
  45.         ;
  46.  
  47. content.lines    : CONTENTS { printcontents(nbval); } content.lines
  48.         | { printf("\" ");  } /* last line */
  49.         ;
  50.  
  51. control.list    : control SEMI control.list
  52.         | ;
  53.  
  54. control        : atoken { printf(" t\) "); }
  55.         |
  56.         | atoken EQUAL { printf(" "); }
  57.             token.list { printf(")"); } ;
  58.  
  59. atoken        : TOKEN  { printf(" (%s", nbval); } ;
  60.  
  61. token.list    : tokens COMMA token.list
  62.         | tokens ;
  63.  
  64. tokens        : TOKEN { printf("%s ", nboldval); } tokens
  65.         | TOKEN  { printf("%s ", nbval); } ; /* look ahead */
  66.  
  67. %%
  68.  
  69. #define output(c) putc(c, stdout)
  70.  
  71. printcontents(p)
  72.     register char *p;
  73. {
  74.     while (*p)
  75.     { 
  76.         if ('"' == *p) output('\\');
  77.         output(*p++);
  78.     }
  79. }
  80.  
  81.     
  82. main() {
  83.     return (yyparse () );
  84.       }
  85.  
  86. yyerror(s)
  87.     char *s;
  88. {
  89.     fprintf(stderr, "%s\n", s);
  90. }
  91.  
  92.