summaryrefslogtreecommitdiff
path: root/parser.y
blob: cb0853b3409b32d0a06b7c20751f902afa0c9383 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%{ // -*-Fundamental-*-
#include <iostream.h>

#include "lexer.hh"
#include "staff.hh"
#include "score.hh"
#include "main.hh"
#include "keyword.hh"
#include "debug.hh"
#include "parseconstruct.hh"
#define YYDEBUG 1


%}


%union {
     int i;    
    Real real;
    Command *command;
    Identifier *id;    

    Voice *voice;    
    Voice_element *el;	
    Staff *staff;    
    String *string;
    Score *score;    
}

%token VOICE STAFF SCORE TITLE RHYTHMSTAFF BAR NOTENAME OUTPUT


%token <id> IDENTIFIER
%token <string> PITCH DURATION RESTNAME
%token <real> REAL
%token <string> STRING

%type <voice> voice_block voice_body voice_elts voice_elts_dollar
%type <el> voice_elt
%type <command> score_command
%type <score> score_block score_body
%type <staff> staff_block  rhythmstaff_block rhythmstaff_body

%%

mudela:	/* empty */
	| score_block { 
		add_score($1);
	}
	;


score_block: SCORE '{' score_body '}' 	{ $$ = $3; }
	;

score_body:		{ $$ = new Score; } 
	| score_body staff_block	{ $$->add($2); }
	| score_body score_command	{ $$->add($2); }
	| score_body OUTPUT STRING	{ $$->outfile = *$3;
		delete $3;
	}
	;

staff_block:
	rhythmstaff_block
	;

rhythmstaff_block:
	RHYTHMSTAFF '{' rhythmstaff_body '}'	{ $$ = $3; }
	;

rhythmstaff_body:
	/* empty */			{ $$ = get_new_rhythmstaff(); }
	| rhythmstaff_body voice_block 	{ $$->add_voice($2); } 	
	;

voice_block:
	VOICE '{' voice_body '}'	{ $$ = $3; }
	;


voice_body:
	REAL voice_elts_dollar { $$ = $2; $$->start = $1; }
	| voice_elts_dollar	{ $$ = $1; }
	;

voice_elts_dollar:
	'$' voice_elts '$'  { $$ = $2; }
 	;

voice_elts:
	/* empty */		{
            $$ = new Voice;
        }
        | voice_elts voice_elt {
            $$->add($2);
        }
	;

voice_elt:
	PITCH DURATION 			{ $$ = get_note_element(*$1, *$2);

	}
	|  RESTNAME DURATION		{ $$ = get_rest_element(*$1, *$2);

	}
	;

score_command:
	BAR REAL			{
		$$ = get_bar_command($2);
	}
	;

%%

void
parse_file(String s)
{
   *mlog << "Parsing ... ";
   yydebug = !monitor.silence("Parser");
   new_input(s);
   yyparse();
}