lilypond-0.0.3
[lilypond.git] / parser.y
blobcb0853b3409b32d0a06b7c20751f902afa0c9383
1 %{ // -*-Fundamental-*-
2 #include <iostream.h>
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
17 %union {
18 int i;
19 Real real;
20 Command *command;
21 Identifier *id;
23 Voice *voice;
24 Voice_element *el;
25 Staff *staff;
26 String *string;
27 Score *score;
30 %token VOICE STAFF SCORE TITLE RHYTHMSTAFF BAR NOTENAME OUTPUT
33 %token <id> IDENTIFIER
34 %token <string> PITCH DURATION RESTNAME
35 %token <real> REAL
36 %token <string> STRING
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
46 mudela: /* empty */
47 | score_block {
48 add_score($1);
53 score_block: SCORE '{' score_body '}' { $$ = $3; }
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;
64 staff_block:
65 rhythmstaff_block
68 rhythmstaff_block:
69 RHYTHMSTAFF '{' rhythmstaff_body '}' { $$ = $3; }
72 rhythmstaff_body:
73 /* empty */ { $$ = get_new_rhythmstaff(); }
74 | rhythmstaff_body voice_block { $$->add_voice($2); }
77 voice_block:
78 VOICE '{' voice_body '}' { $$ = $3; }
82 voice_body:
83 REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
84 | voice_elts_dollar { $$ = $1; }
87 voice_elts_dollar:
88 '$' voice_elts '$' { $$ = $2; }
91 voice_elts:
92 /* empty */ {
93 $$ = new Voice;
95 | voice_elts voice_elt {
96 $$->add($2);
100 voice_elt:
101 PITCH DURATION { $$ = get_note_element(*$1, *$2);
104 | RESTNAME DURATION { $$ = get_rest_element(*$1, *$2);
109 score_command:
110 BAR REAL {
111 $$ = get_bar_command($2);
117 void
118 parse_file(String s)
120 *mlog << "Parsing ... ";
121 yydebug = !monitor.silence("Parser");
122 new_input(s);
123 yyparse();