flower-1.0.3
[lilypond.git] / parser.y
blobebc4c54f8b340dfc0f6e03a3fbf44950579c6daf
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 "scommands.hh"
11 #include "debug.hh"
12 #include "parseconstruct.hh"
13 #include "dimen.hh"
15 #ifndef NDEBUG
16 #define YYDEBUG 1
17 #endif
22 %union {
23 Real real;
24 Command *command;
25 Identifier *id;
26 Score_commands *scommands;
27 Voice *voice;
28 Voice_element *el;
29 Staff *staff;
30 String *string;
31 Score *score;
32 const char *consstr;
33 Paperdef *paper;
34 int i;
37 %token VOICE STAFF SCORE TITLE RHYTHMSTAFF BAR NOTENAME OUTPUT
38 %token CM IN PT MM PAPER WIDTH METER UNITSPACE SKIP COMMANDS
40 %type <consstr> unit
41 %token <id> IDENTIFIER
42 %token <string> PITCH DURATION RESTNAME
43 %token <real> REAL
44 %token <string> STRING
46 %type <paper> paper_block paper_body
47 %type <real> dim
48 %type <voice> voice_block voice_body voice_elts voice_elts_dollar
49 %type <el> voice_elt
50 %type <command> score_command
51 %type <score> score_block score_body
52 %type <staff> staff_block rhythmstaff_block rhythmstaff_body
53 %type <i> int
54 %type <scommands> score_commands_block score_commands_body
58 mudela: /* empty */
59 | score_block {
60 add_score($1);
65 score_block: SCORE '{' score_body '}' { $$ = $3; }
68 score_body: { $$ = new Score; }
69 | score_body staff_block { $$->add($2); }
70 | score_body score_commands_block { $$->set($2); }
71 | score_body paper_block { $$->set($2); }
73 score_commands_block:
74 COMMANDS '{' score_commands_body '}' { $$ =$3;}
77 score_commands_body: { $$ = new Score_commands; }
78 | score_commands_body score_command {
79 $$->parser_add($2);
83 paper_block:
84 PAPER '{' paper_body '}' { $$ = $3; }
87 paper_body:
88 /* empty */ { $$ = new Paperdef; }
89 | paper_body WIDTH dim { $$->width = $3;}
90 | paper_body OUTPUT STRING { $$->outfile = *$3;
91 delete $3;
93 | paper_body UNITSPACE dim { $$->whole_width = $3; }
96 dim:
97 REAL unit { $$ = convert_dimen($1,$2); }
101 unit: CM { $$ = "cm"; }
102 |IN { $$ = "in"; }
103 |MM { $$ = "mm"; }
104 |PT { $$ = "pt"; }
108 staff_block:
109 rhythmstaff_block
112 rhythmstaff_block:
113 RHYTHMSTAFF '{' rhythmstaff_body '}' { $$ = $3; }
116 rhythmstaff_body:
117 /* empty */ { $$ = get_new_rhythmstaff(); }
118 | rhythmstaff_body voice_block { $$->add_voice($2); }
121 voice_block:
122 VOICE '{' voice_body '}' { $$ = $3; }
126 voice_body:
127 REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
128 | voice_elts_dollar { $$ = $1; }
131 voice_elts_dollar:
132 '$' voice_elts '$' { $$ = $2; }
135 voice_elts:
136 /* empty */ {
137 $$ = new Voice;
139 | voice_elts voice_elt {
140 $$->add($2);
144 voice_elt:
145 PITCH DURATION { $$ = get_note_element(*$1, *$2);
148 | RESTNAME DURATION { $$ = get_rest_element(*$1, *$2);
153 score_command:
154 SKIP int ':' REAL {
155 $$ = get_skip_command($2, $4);
157 | METER int int {
158 $$ = get_meterchange_command($2, $3);
160 /* | PARTIALMEASURE REAL {
161 $$ = get_partial_command($2);
166 int:
167 REAL {
168 $$ = int($1);
169 if (ABS($1-Real(int($$))) > 1e-8)
170 yyerror("expecting integer number");
177 void
178 parse_file(String s)
180 *mlog << "Parsing ... ";
181 #ifdef YYDEBUG
182 yydebug = !monitor.silence("Parser");
183 #endif
184 new_input(s);
185 yyparse();