home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / app / omtd / parse.y < prev    next >
Text File  |  1991-03-14  |  4KB  |  176 lines

  1. /*
  2.  * Copyright (c) 1990 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18.  
  19. /*
  20.  * Built-in keywords.
  21.  */
  22. %token TK_QUIT TK_RUN TK_STOP TK_PRINT TK_MERGE TK_TEMPO TK_DUMP TK_ECHO
  23. %token TK_CHANNEL TK_CLICK TK_DELETE TK_COPY TK_MUTE TK_UNMUTE TK_QUANTIZE
  24. %token TK_SAVE TK_LOAD TK_TRACKS TK_NEW TK_INSERT TK_VOLUME TK_TRANS
  25. %token TK_SET TK_SETTING TK_OFF TK_CLEAR TK_MOVE
  26.  
  27. %token TK_ID TK_INT TK_REAL TK_STRING
  28. %token TK_EOF
  29.  
  30. %{
  31. #include <sys/types.h>
  32. #include "setting.h"
  33. #include "track.h"
  34.  
  35. #define YYDEBUG
  36. char *prompt = "(mtd) ";
  37. %}
  38.  
  39. %union {
  40.     int i;
  41.     char *s;
  42.     float f;
  43.     struct track *trk;
  44.     struct {
  45.         int s, e; 
  46.     } w;
  47. };
  48.  
  49. %type <trk>    ntrack track
  50. %type <i>    TK_INT channel opt_repeat opt_time time
  51. %type <s>    TK_ID
  52. %type <w>    win opt_win
  53.  
  54. %%
  55. input:      prompt line newline
  56.     | input line newline
  57.     ;
  58. line:      /* null */
  59.     | command
  60.     | error
  61.     ;
  62. newline:  '\n' prompt 
  63.     ;
  64. prompt:   /* null */        { fputs(prompt, stdout); fflush(stdout); }
  65.     ;
  66. command:  c.run
  67.     | c.quit
  68.     | c.merge
  69.     | c.channel
  70.     | c.tracks
  71.     | c.new
  72.     | c.copy
  73.     | c.echo
  74.     | c.click
  75.     | c.save
  76.     | c.load
  77.     | c.quantize
  78.     | c.tempo
  79.     | c.clear
  80.     | c.mute
  81.     | c.delete
  82.     | c.dump
  83.     ;
  84. c.dump:      TK_DUMP track        { dump_command($2); }
  85.     ;
  86. c.run:      TK_RUN         { run_command(0, (void *)0); }
  87.     | TK_RUN time        { run_command($2, (void *)0); }
  88.     | TK_RUN track         { run_command(0, $2); }
  89.     | TK_RUN track time    { run_command($3, $2); }
  90.     ;
  91. c.quit:      TK_QUIT        { exit(0); }
  92.     ;
  93. c.merge:  TK_MERGE ntrack    { merge_command($2); }
  94.     ;
  95. c.channel:
  96.       TK_CHANNEL ntrack channel
  97.                 { channel_command($2, $3); }
  98.     ;
  99. c.tracks: TK_TRACKS         { tracks_command(); }
  100.     ;
  101. c.new:      TK_NEW        { new_command(); }
  102.     ;
  103. c.copy:      TK_COPY opt_repeat track opt_win ntrack opt_time
  104. {
  105.     if ($3)
  106.         copy_command($3, $4.s, $4.e, $5, $6, $2);
  107. }
  108. c.echo:      TK_ECHO         { echo_command(-1); }
  109.     | TK_ECHO TK_INT    { echo_command($2); }
  110.     ;
  111. c.click:  TK_CLICK TK_OFF        { click_off(); }
  112.     | TK_CLICK            { click_on(-1, -1); }
  113.     | TK_CLICK TK_INT        { click_on($2, -1); }
  114.     | TK_CLICK TK_INT TK_INT    { click_on($2, $3); }
  115.     ;
  116. c.save:      TK_SAVE TK_ID        { save_command($2); }
  117.     ;
  118. c.load:      TK_LOAD TK_ID        { load_command($2); }
  119.     ;
  120. c.quantize:
  121.       TK_QUANTIZE track TK_INT '/' TK_INT
  122. {
  123.     if ($2)
  124.         quantize_command($2, $3, $5);
  125. }
  126.     ;
  127. c.tempo:  TK_TEMPO TK_INT    { tempo_command($2); }
  128.     ;
  129. c.clear:  TK_CLEAR track opt_win    { clear_command($2, $3.s, $3.e); }
  130.     ;
  131. c.move:      TK_MOVE time time    { move_command($2, $3); }
  132.     | TK_MOVE time        { move_command($2, 0); }
  133.     ;
  134. c.delete: TK_DELETE track    { clear_command($2, 0, ~0);
  135.                   delete_command($2); }
  136.     ;
  137. c.mute:      TK_UNMUTE track    { mute_command($2, 0); }
  138.     | TK_MUTE track        { mute_command($2, 1); }
  139.     ;
  140. opt_repeat:
  141.       /* null */        { $$ = 1; }
  142.     | TK_INT
  143.     | ':' TK_INT        { $$ = $2; }
  144.     ;
  145. opt_time: /* null */        { $$ = 0; }
  146.     | time
  147.     ;
  148. opt_win:  /* null */        { $$.s = 0; $$.e = ~0; }
  149.     | time            { $$.s = $1; $$.e = ~0; }
  150.     | win
  151.     ;
  152. win:      time ',' time        { $$.s = $1; $$.e = $3; }
  153.     ;
  154. track:      TK_ID            { $$ = find_track($1); }
  155.     ;
  156. ntrack:      TK_ID            { $$ = lookup_track($1, s.echo_channel); }
  157.     ;
  158. channel:  TK_INT
  159.     ;
  160. time:      TK_INT        { $$ = ttt($1, 0, 0); }
  161.     | TK_INT ':' TK_INT    { $$ = ttt($1, $3, 0); }
  162.     | TK_INT ':' TK_INT ':' TK_INT    { $$ = ttt($1, $3, $5); }
  163.     ;
  164. %%
  165. yyerror(s)
  166.     char *s;
  167. {
  168.     printf("syntax error\n");
  169. }
  170.  
  171. ttt(bar, beat, tick)
  172.     int bar, beat, tick;
  173. {
  174.     return tick + s.ticks_per_beat * (beat + bar * s.beats_per_bar);
  175. }
  176.