]> git.donarmstrong.com Git - lilypond.git/blob - parser.y
23987a273daef7dbde42b74ae066b0b4d4681540
[lilypond.git] / parser.y
1 %{ // -*-Fundamental-*-
2 #include <iostream.h>
3 //#include "mudobs.hh"
4 #include "lexer.hh"
5 #include "staff.hh"
6 #include "score.hh"
7 #include "keyword.hh"
8 #include "globvars.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
31
32 %token <id> IDENTIFIER
33 %token <string> PITCH DURATION RESTNAME
34 %token <real> REAL
35
36
37 %type <voice> voice_block voice_body voice_elts voice_elts_dollar
38 %type <el> voice_elt
39 %type <command> score_command
40 %type <score> score_block score_body
41 %type <staff> staff_block  rhythmstaff_block rhythmstaff_body
42
43 %%
44
45 mudela:
46         score_block { 
47                 delete the_score; 
48                 the_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         ;
60
61 staff_block:
62         rhythmstaff_block
63         ;
64
65 rhythmstaff_block:
66         RHYTHMSTAFF '{' rhythmstaff_body '}'    { $$ = $3; }
67         ;
68
69 rhythmstaff_body:
70         /* empty */                     { $$ = get_new_rhythmstaff(); }
71         | rhythmstaff_body voice_block  { $$->add_voice($2); }  
72         ;
73
74 voice_block:
75         VOICE '{' voice_body '}'        { $$ = $3; }
76         ;
77
78
79 voice_body:
80         REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
81         | voice_elts_dollar     { $$ = $1; }
82         ;
83
84 voice_elts_dollar:
85         '$' voice_elts '$'  { $$ = $2; }
86         ;
87
88 voice_elts:
89         /* empty */             {
90             $$ = new Voice;
91         }
92         | voice_elts voice_elt {
93             $$->add($2);
94         }
95         ;
96
97 voice_elt:
98         PITCH DURATION                  { $$ = get_note_element(*$1, *$2);
99
100         }
101         |  RESTNAME DURATION            { $$ = get_rest_element(*$1, *$2);
102
103         }
104         ;
105
106 score_command:
107         BAR REAL                        {
108                 $$ = get_bar_command($2);
109         }
110         ;
111
112 %%
113
114 void
115 parse_file(String s)
116 {
117    *mlog << "Parsing ... ";
118    yydebug = debug_flags & DEBUGPARSER;
119    new_input(s);
120    yyparse();
121 }