1 %
{ // -*-Fundamental-*-
7 #include "paper-def.hh"
9 #include "input-score.hh"
13 #include "parseconstruct.hh"
15 #include "identifier.hh"
16 #include "commandrequest.hh"
17 #include "musicalrequest.hh"
18 #include "voice-element.hh"
24 Array
<Request
*> pre_reqs
, post_reqs
;
25 Array
<const char *> define_spots
;
26 Paper_def
*default_paper
();
27 char const* defined_ch_c_l
;
28 char const* req_defined_ch_c_l
;
29 int fatal_error_i
= 0;
45 Music_general_chord
*chord
;
52 Array
<String
> * strvec
;
54 Array
<Melodic_req
*> *melreqvec
;
57 Symtables
* symtables
;
63 Notename_tab
*notename_tab
;
68 %token VOICE STAFF SCORE TITLE BAR OUTPUT MULTIVOICE
69 %token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
70 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
71 %token KEY CLEF TABLE VOICES STEM
72 %token PARTIAL MUSIC GROUPING CADENZA
73 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
77 %token
<id
> IDENTIFIER
78 %token
<string> PITCHMOD DURATION RESTNAME
81 %token
<string> STRING
85 %type
<melreqvec
> pitch_list
86 %type
<c
> open_request_parens close_request_parens close_plet_parens
87 %type
<id
> declaration
88 %type
<string> declarable_identifier
89 %type
<paper
> paper_block paper_body
90 %type
<midi
> midi_block midi_body
92 %type
<ii
> default_duration explicit_duration notemode_duration mudela_duration
94 %type
<moment
> duration_length
95 %type
<el
> voice_elt full_element lyrics_elt command_elt
97 %type
<score
> score_block score_body
98 %type
<staff
> staff_block staff_init staff_body
100 %type
<intvec
> intastint_list
101 %type
<request
> post_request pre_request command_req
102 %type
<string> pitchmod
104 %type
<chord
> music_chord music_chord_body
106 %type
<mvoice
> music_voice_body music_voice
108 %type
<interval
> dinterval
110 %type
<symtable
> symtable symtable_body
111 %type
<lookup
> symtables symtables_body
112 %type
<symbol
> symboldef
113 %type
<notename_tab
> notename_tab notename_tab_body
115 %type
<script
> script_definition script_body mudela_script
116 %type
<request
> script_req textscript_req
117 %type
<textdef
> mudela_text
123 | mudela score_block
{
126 | mudela add_declaration
{ }
127 | mudela mudela_command
{}
131 notename_tab
{ lexer
->set
($1); }
137 add_declaration: declaration
{
138 lexer
->add_identifier
($1);
142 declarable_identifier:
144 | IDENTIFIER
{ $$
= new String
($1->name
); }
148 declarable_identifier
'=' staff_block
{
149 $$
= new Staff_id
(*$1, $3);
152 | declarable_identifier
'=' music_voice
{
153 $$
= new M_voice_id
(*$1, $3);
156 | declarable_identifier
'=' script_definition
{
157 $$
= new Script_id
(*$1, $3);
160 | declarable_identifier
'=' music_chord
{
161 $$
= new M_chord_id
(*$1, $3);
164 | declarable_identifier
'=' symtables
{
165 $$
= new Lookup_id
(*$1, $3);
168 | declarable_identifier
'=' notename_tab
{
169 $$
= new Notetab_id
(*$1, $3);
172 | declarable_identifier
'=' real
{
173 $$
= new Real_id
(*$1, new Real
($3));
176 | declarable_identifier
error '}' {
182 NOTENAMES
'{' notename_tab_body
'}' { $$
= $3; }
186 $$
= new Notename_tab
;
189 $$
= $1->notename_tab
(true
);
191 | notename_tab_body STRING
int int {
192 $$
->set
($3, $4, *$2);
201 SCORE
{ define_spots.push
(lexer
->here_ch_c_l
()); }
202 /*cont*/ '{' score_body
'}' {
204 $$
->defined_ch_c_l_
= define_spots.pop
();
205 if
(!$$
->paper_p_
&& ! $$
->midi_p_
)
206 $$
->paper_p_
= default_paper
();
208 /* handle error levels. */
209 $$
->errorlevel_i_
= lexer
->errorlevel_i_
;
210 lexer
->errorlevel_i_
= 0;
215 $$
= new Input_score
;
217 | score_body staff_block
{ $$
->add
($2); }
218 | score_body COMMANDS
'{' music_voice_body
'}' {
221 | score_body paper_block
{ $$
->set
($2); }
222 | score_body midi_block
{ $$
->set
($2); }
229 /* */ { $$
=new Array
<int>; }
230 | intastint_list
int '*' int {
231 $$
->push
($2); $$
->push
($4);
242 '{' paper_body
'}' { $$
= $3; }
247 $$
= default_paper
();
249 | paper_body WIDTH dim
{ $$
->linewidth
= $3;}
250 | paper_body OUTPUT STRING
{ $$
->outfile
= *$3;
253 | paper_body symtables
{ $$
->set
($2); }
254 | paper_body UNITSPACE dim
{ $$
->whole_width
= $3; }
255 | paper_body GEOMETRIC REAL
{ $$
->geometric_
= $3; }
267 '{' midi_body
'}' { $$
= $3; }
273 | midi_body OUTPUT STRING
{
274 $$
->outfile_str_
= *$3;
277 | midi_body TEMPO mudela_duration
':' int {
278 $$
->set_tempo
( wholes
( $3[0], $3[1] ), $5 );
289 STAFF
{ define_spots.push
(lexer
->here_ch_c_l
()); }
290 /*cont*/ '{' staff_body
'}' {
292 $$
-> defined_ch_c_l_
= define_spots.pop
();
299 IDENTIFIER
{ $$
= $1->staff
(true
); }
301 $$
= new Input_staff
(*$1);
308 | staff_body COMMANDS
'{' music_voice_body
'}' {
309 $$
->set_score_wide
($4);
312 $2->set_default_group
( "staff_music" + String
($$
->music_.size
()));
323 music_voice
{ $$
= $1; }
324 | music_chord
{ $$
= $1; }
327 music_voice: MUSIC
'{' music_voice_body
'}' { $$
= $3; }
332 $$
= new Music_voice
;
334 | music_voice_body IDENTIFIER
{
335 $$
->concatenate
($2->mvoice
(true
));
337 | music_voice_body full_element
{
340 | music_voice_body voice_command
{
342 | music_voice_body music
{
345 | music_voice_body
error {
349 music_chord: '{' music_chord_body
'}' { $$
= $2; }
354 $$
= new Voice_group_chord
;
357 $$
= new Multi_voice_chord
;
359 | music_chord_body IDENTIFIER
{
360 $$
->concatenate
($2->mchord
(true
));
362 | music_chord_body music
{
365 | music_chord_body full_element
{
368 | music_chord_body
error {
376 full_element: pre_requests voice_elt post_requests
{
377 add_requests
($2, pre_reqs
);
378 add_requests
($2, post_reqs
);
381 | pre_requests lyrics_elt post_requests
{
382 add_requests
($2, pre_reqs
);
383 add_requests
($2, post_reqs
);
391 $$
= new Voice_element
;
392 $$
-> defined_ch_c_l_
= lexer
->here_ch_c_l
();
396 $2-> defined_ch_c_l_
= $$
->defined_ch_c_l_
;
404 $$
= new Barcheck_req
;
407 $$
= new Bar_req
(*$2);
410 | METER
'{' int '*' int '}' {
411 Meter_change_req
*m
= new Meter_change_req
;
415 | SKIP
'{' duration_length
'}' {
416 Skip_req
* skip_p
= new Skip_req
;
417 skip_p
->duration_
= *$3;
421 | CADENZA
'{' int '}' {
422 $$
= new Cadenza_req
($3);
424 | PARTIAL
'{' duration_length
'}' {
425 $$
= new Partial_measure_req
(*$3);
429 $$
= get_stemdir_req
($3);
432 $$
= new Clef_change_req
(*$2);
435 | KEY
'{' pitch_list
'}' {
436 Key_change_req
*key_p
= new Key_change_req
;
437 key_p
->melodic_p_arr_
= *$3;
441 | GROUPING
'{' intastint_list
'}' {
442 $$
= get_grouping_req
(*$3); delete
$3;
448 assert
(post_reqs.empty
());
450 | post_requests post_request
{
451 $2->defined_ch_c_l_
= lexer
->here_ch_c_l
();
454 | post_requests close_plet_parens INT
'/' INT
{
455 post_reqs.push
( get_request
($2) );
456 req_defined_ch_c_l
= lexer
->here_ch_c_l
();
457 post_reqs.push
( get_plet_request
( $2, $3, $5 ) );
462 close_request_parens
{
463 $$
= get_request
($1);
471 req_defined_ch_c_l
= lexer
->here_ch_c_l
();
476 close_request_parens:
495 SCRIPT
'{' script_body
'}' { $$
= $3; }
500 $$
= new Script_def
(*$1,$2, $3,$4);
506 script_dir mudela_text
{ $$
= get_text_req
($1,$2); }
511 defined_ch_c_l
= lexer
->here_ch_c_l
();
518 script_dir mudela_script
{
519 $$
= get_script_req
($1, $2);
524 IDENTIFIER
{ $$
= $1->script
(true
); }
525 | script_definition
{ $$
= $1; }
526 |
'^' { $$
= get_scriptdef
('^'); }
527 |
'+' { $$
= get_scriptdef
('+'); }
528 |
'-' { $$
= get_scriptdef
('-'); }
529 |
'|' { $$
= get_scriptdef
('|'); }
530 |
'o' { $$
= get_scriptdef
('o'); }
531 |
'>' { $$
= get_scriptdef
('>'); }
532 |
'.' { $$
= get_scriptdef
('.'); }
535 warning
( "too many staccato dots", lexer
->here_ch_c_l
() );
536 $$
= get_scriptdef
('.');
539 $$
= get_scriptdef
('.');
551 | pre_requests pre_request
{
553 $2->defined_ch_c_l_
= lexer
->here_ch_c_l
();
558 open_request_parens
{
559 defined_ch_c_l
= lexer
->here_ch_c_l
();
560 $$
= get_request
($1);
565 PLET
'{' INT
'/' INT
'}' {
568 | DURATIONCOMMAND
'{' STRING
'}' {
569 set_duration_mode
(*$3);
572 | DURATIONCOMMAND
'{' notemode_duration
'}' {
573 set_default_duration
($3);
575 | OCTAVECOMMAND
'{' pitchmod
'}' {
576 set_default_octave
(*$3);
587 $$
= new Moment
(wholes
($1[0], $1[1]));
589 |
int '*' mudela_duration
{
590 $$
= new Moment
(Rational
($1) * wholes
($3[0], $3[1]));
623 get_default_duration
($$
);
626 | INT
'*' INT
'/' INT
{
627 // ugh, must use Duration
637 get_default_duration
($$
);
642 defined_ch_c_l
= lexer
->here_ch_c_l
();
646 defined_ch_c_l
= lexer
->here_ch_c_l
();
656 pitchmod notename notemode_duration
{
657 $$
= get_note_element
(*$1, $2, $3);
660 | RESTNAME notemode_duration
{
661 $$
= get_rest_element
(*$1, $2);
668 mudela_text notemode_duration
{
669 $$
= get_word_element
($1, $2);
676 $$
= new Array
<Melodic_req
*>;
678 | pitch_list NOTENAME
{
679 Melodic_req
*m_p
= new Melodic_req
;
680 m_p
->notename_i_
= $2[0];
681 m_p
->accidental_i_
= $2[1];
689 if
( distance
($1,Real
(int($$
)) ) > 1e-8)
690 error( "integer expected", lexer
->here_ch_c_l
() );
709 real unit
{ $$
= $1*$2; }
713 unit: CM_T
{ $$
= 1 CM
; }
714 |IN_T
{ $$
= 1 INCH
; }
723 SYMBOLTABLES
'{' symtables_body
'}' { $$
= $3; }
731 $$
= new Lookup
(*$1->lookup
(true
));
733 | symtables_body TEXID STRING
{
734 $$
->texsetting
= *$3;
737 | symtables_body STRING
'=' symtable
{
744 TABLE
'{' symtable_body
'}' { $$
= $3; }
748 { $$
= new Symtable
; }
749 | symtable_body STRING symboldef
{
758 $$
= new Symbol
(*$1, *$2);
764 $$
= new Symbol
(*$1, b
);
770 dinterval dinterval
{
771 $$
= new Box
(*$1, *$2);
778 $$
= new Interval
($1, $2);
785 yyerror(const char *s
)
787 lexer
->LexerError
(s
);
790 exit
( fatal_error_i
);
794 parse_file
(String init
, String s
)
796 *mlog
<< "Parsing ... ";
797 lexer
= new My_flex_lexer
;
800 yydebug = !monitor
->silence
("InitParser") && check_debug
;
801 lexer
->set_debug
( !monitor
->silence
("InitLexer") && check_debug
);
804 lexer
->new_input
(init
);
809 if
(check_debug
&& !monitor
->silence
("InitDeclarations"))
810 lexer
->print_declarations
();
812 yydebug = !monitor
->silence
("Parser") && check_debug
;
813 lexer
->set_debug
( !monitor
->silence
("Lexer") && check_debug
);
821 if
(!define_spots.empty
())
822 warning
("Braces don't match.",0);
828 return new Paper_def
(
829 lexer
->lookup_identifier
("default_table")->lookup
(true
));