lilypond-0.0.5
[lilypond.git] / parser.y
blobd60face970f2830abbe8980091da4c7dadc7593a
1 %{ // -*-Fundamental-*-
2 #include <iostream.h>
4 #include "lexer.hh"
5 #include "paper.hh"
6 #include "staff.hh"
7 #include "score.hh"
8 #include "main.hh"
9 #include "keyword.hh"
10 #include "debug.hh"
11 #include "parseconstruct.hh"
12 #include "dimen.hh"
14 #ifndef NDEBUG
15 #define YYDEBUG 1
16 #endif
21 %union {
22 Real real;
23 Command *command;
24 Identifier *id;
26 Voice *voice;
27 Voice_element *el;
28 Staff *staff;
29 String *string;
30 Score *score;
31 const char *consstr;
32 Paperdef *paper;
33 int i;
36 %token VOICE STAFF SCORE TITLE RHYTHMSTAFF BAR NOTENAME OUTPUT
37 %token CM IN PT MM PAPER WIDTH METER
39 %type <consstr> unit
40 %token <id> IDENTIFIER
41 %token <string> PITCH DURATION RESTNAME
42 %token <real> REAL
43 %token <string> STRING
45 %type <paper> paper_block paper_body
46 %type <real> dim
47 %type <voice> voice_block voice_body voice_elts voice_elts_dollar
48 %type <el> voice_elt
49 %type <command> score_command
50 %type <score> score_block score_body
51 %type <staff> staff_block rhythmstaff_block rhythmstaff_body
52 %type <i> int
57 mudela: /* empty */
58 | score_block {
59 add_score($1);
64 score_block: SCORE '{' score_body '}' { $$ = $3; }
67 score_body: { $$ = new Score; }
68 | score_body staff_block { $$->add($2); }
69 | score_body score_command { $$->add($2); }
70 | score_body paper_block { delete $$->paper;
71 $$->paper = $2;
75 paper_block:
76 PAPER '{' paper_body '}' { $$ = $3; }
79 paper_body:
80 /* empty */ { $$ = new Paperdef; }
81 | paper_body WIDTH dim { $$->width = $3;}
82 | paper_body OUTPUT STRING { $$->outfile = *$3;
83 delete $3;
87 dim:
88 REAL unit { $$ = convert_dimen($1,$2); }
92 unit: CM { $$ = "cm"; }
93 |IN { $$ = "in"; }
94 |MM { $$ = "mm"; }
95 |PT { $$ = "pt"; }
99 staff_block:
100 rhythmstaff_block
103 rhythmstaff_block:
104 RHYTHMSTAFF '{' rhythmstaff_body '}' { $$ = $3; }
107 rhythmstaff_body:
108 /* empty */ { $$ = get_new_rhythmstaff(); }
109 | rhythmstaff_body voice_block { $$->add_voice($2); }
112 voice_block:
113 VOICE '{' voice_body '}' { $$ = $3; }
117 voice_body:
118 REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
119 | voice_elts_dollar { $$ = $1; }
122 voice_elts_dollar:
123 '$' voice_elts '$' { $$ = $2; }
126 voice_elts:
127 /* empty */ {
128 $$ = new Voice;
130 | voice_elts voice_elt {
131 $$->add($2);
135 voice_elt:
136 PITCH DURATION { $$ = get_note_element(*$1, *$2);
139 | RESTNAME DURATION { $$ = get_rest_element(*$1, *$2);
144 score_command:
145 BAR REAL {
146 $$ = get_bar_command($2);
148 | METER REAL int int {
149 $$ = get_meter_command($2, $3, $4);
153 int:
154 REAL {
155 $$ = int($1);
156 if (ABS($1-Real(int($$))) > 1e-8)
157 yyerror("expecting integer number");
164 void
165 parse_file(String s)
167 *mlog << "Parsing ... ";
168 #ifdef YYDEBUG
169 yydebug = !monitor.silence("Parser");
170 #endif
171 new_input(s);
172 yyparse();