]> git.donarmstrong.com Git - lilypond.git/blob - parser.y
release: 0.0.3
[lilypond.git] / parser.y
1 %{ // -*-Fundamental-*-
2 #include <iostream.h>
3
4 #include "lexer.hh"
5 #include "staff.hh"
6 #include "score.hh"
7 #include "main.hh"
8 #include "keyword.hh"
9 #include "debug.hh"
10 #include "parseconstruct.hh"
11 #define YYDEBUG 1
12
13
14 %}
15
16
17 %union {
18      int i;    
19     Real real;
20     Command *command;
21     Identifier *id;    
22
23     Voice *voice;    
24     Voice_element *el;  
25     Staff *staff;    
26     String *string;
27     Score *score;    
28 }
29
30 %token VOICE STAFF SCORE TITLE RHYTHMSTAFF BAR NOTENAME OUTPUT
31
32
33 %token <id> IDENTIFIER
34 %token <string> PITCH DURATION RESTNAME
35 %token <real> REAL
36 %token <string> STRING
37
38 %type <voice> voice_block voice_body voice_elts voice_elts_dollar
39 %type <el> voice_elt
40 %type <command> score_command
41 %type <score> score_block score_body
42 %type <staff> staff_block  rhythmstaff_block rhythmstaff_body
43
44 %%
45
46 mudela: /* empty */
47         | score_block { 
48                 add_score($1);
49         }
50         ;
51
52
53 score_block: SCORE '{' score_body '}'   { $$ = $3; }
54         ;
55
56 score_body:             { $$ = new Score; } 
57         | score_body staff_block        { $$->add($2); }
58         | score_body score_command      { $$->add($2); }
59         | score_body OUTPUT STRING      { $$->outfile = *$3;
60                 delete $3;
61         }
62         ;
63
64 staff_block:
65         rhythmstaff_block
66         ;
67
68 rhythmstaff_block:
69         RHYTHMSTAFF '{' rhythmstaff_body '}'    { $$ = $3; }
70         ;
71
72 rhythmstaff_body:
73         /* empty */                     { $$ = get_new_rhythmstaff(); }
74         | rhythmstaff_body voice_block  { $$->add_voice($2); }  
75         ;
76
77 voice_block:
78         VOICE '{' voice_body '}'        { $$ = $3; }
79         ;
80
81
82 voice_body:
83         REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
84         | voice_elts_dollar     { $$ = $1; }
85         ;
86
87 voice_elts_dollar:
88         '$' voice_elts '$'  { $$ = $2; }
89         ;
90
91 voice_elts:
92         /* empty */             {
93             $$ = new Voice;
94         }
95         | voice_elts voice_elt {
96             $$->add($2);
97         }
98         ;
99
100 voice_elt:
101         PITCH DURATION                  { $$ = get_note_element(*$1, *$2);
102
103         }
104         |  RESTNAME DURATION            { $$ = get_rest_element(*$1, *$2);
105
106         }
107         ;
108
109 score_command:
110         BAR REAL                        {
111                 $$ = get_bar_command($2);
112         }
113         ;
114
115 %%
116
117 void
118 parse_file(String s)
119 {
120    *mlog << "Parsing ... ";
121    yydebug = !monitor.silence("Parser");
122    new_input(s);
123    yyparse();
124 }