ic.y 4.99 KB
%{
#include "ic.h"
%}

%start startseq

%union		yystacktype
 	  	{
 	  	   int		intval;
 	  	   double	floatval;
 	  	   char		*stringval;
 	  	   struct id	*idptr;
 	  	   struct decl	*declptr;
 	  	   struct ste	*steptr;
 	  	}

%token  bank program instrument sound wavetable keymap envelope
%token	volume pan
%token	use

%token	keyMin keyMax keyBase velocityMin velocityMax detune
%token	attackTime attackVolume decayTime decayVolume releaseTime releaseVolume

%token	BANK INSTRUMENT SOUND
%token	KEYMAP SFILE

%token	ID TYPE CONST
%token	INTCONST FLOATCONST STRINGCONST 
%token  INTEGER BOOLEAN REAL VOID ERROR
%token	AND COLONEQUAL NOTEQUAL GREATEREQUAL LESSEQUAL

%type	<declptr> intconst

%nonassoc <idptr> ID
%nonassoc <intval> INTCONST 
%nonassoc <stringval> STRINGCONST

%%

intconst	:	INTCONST { $$ = makeenumconstdecl($1); }
   	  	;

envAttackTime	:	attackTime "=" intconst
			{
			    envSetAttackTime(curEnvelope, $3->value);
			}
		;

envAttackVol	:	attackVolume "=" intconst
			{
			    envSetAttackVol(curEnvelope, $3->value);
			}
		;

envDecayTime	:	decayTime "=" intconst
			{
			    envSetDecayTime(curEnvelope, $3->value);
			}
		;

envDecayVol	:	decayVolume "=" intconst
 			{
			    envSetDecayVol(curEnvelope, $3->value);
			}
		;

envReleaseTime	:	releaseTime "=" intconst
 			{
			    envSetReleaseTime(curEnvelope, $3->value);
			}
		;

envReleaseVol	:	releaseVolume "=" intconst
 			{
			    envSetReleaseVol(curEnvelope, $3->value);
			}
		;

envVars		:	envAttackTime
		|	envAttackVol
		|	envDecayTime
		|	envDecayVol
		|	envReleaseTime
		|	envReleaseVol
		;

envVarList	:	envVarList envVars ";"
		|	/* empty */
		;

envDefn		:	envelope ID
			{
			    struct decl *declptr = makeenvdecl();
			    declare($2, declptr);
			    curEnvelope = (ICEnvelope *)declptr;
			}
			"{" envVarList "}"
		;

envRef		:	envelope "=" ID
			{
			    struct decl *declptr = findcurrentdecl($3);
			    soundAddEnvelope(curSound, (ICEnvelope *)declptr);
			}
		;

keyMinKey	:	keyMin "=" intconst
			{
			   keySetKeyMin(curKeyMap, $3->value);
			}
		;

keyMaxKey	:	keyMax "=" intconst
			{
			   keySetKeyMax(curKeyMap, $3->value);
			}
		;

keyBaseKey	:	keyBase "=" intconst
			{
			   keySetKeyBase(curKeyMap, $3->value);
			}
		;

keyVelocityMin	:	velocityMin "=" intconst
			{
			   keySetVelMin(curKeyMap, $3->value);	
			}
		;

keyVelocityMax	:	velocityMax "=" intconst
			{
			   keySetVelMax(curKeyMap, $3->value);	
			}
		;

keyDetune	:	detune "=" intconst
			{
			   keySetDetune(curKeyMap, $3->value);	
			}
		;

keyVars		:	keyMinKey
		|	keyMaxKey
		|	keyBaseKey
		|	keyVelocityMin
		|	keyVelocityMax
		|	keyDetune
		;

keyVarList	:	keyVarList keyVars ";"
		|	/* empty */
		;

keyDefn		:	keymap ID 
			{
			    struct decl *declptr = makekeydecl();
			    declare($2, declptr);
			    curKeyMap = (ICKeyMap *)declptr;
			}
			"{" keyVarList "}"
		;

keyRef		:	keymap "=" ID
			{
			    struct decl *declptr = findcurrentdecl($3);
			    soundAddKeyMap(curSound, (ICKeyMap *)declptr);
			}
		;

soundPan	:	pan "=" intconst
			{
			    soundSetPan(curSound, $3->value);
			}
		;

soundVol	:	volume "=" intconst
			{
			    soundSetVol(curSound, $3->value);
			}
		;

soundUse	:	use "(" STRINGCONST ")"
			{
			    int len = strlen($3);
			    struct id *idptr = enter(ID, $3, len);
			    struct decl *declptr = testglobaldecl(idptr);

			    if (!declptr) {
				declareglobal(idptr, makefiledecl($3));
			    }
			    soundFromFile(curSound, $3);
			}
		;

soundVars	:	soundPan
		|	soundVol
		|	soundUse
		|	keyRef
		|	envRef
		;

soundVarList	:	soundVarList soundVars ";"
		|	/* empty */
		;

sndDefn		:	sound ID 
			{
			    struct decl *declptr = makesounddecl();
			    declare($2, declptr);
			    curSound = (ICSound *)declptr;
			}
			"{" soundVarList "}"
		;

soundRef	:	sound "[" intconst "]" "=" ID
			{
			    struct decl *declptr = findcurrentdecl($6);
			    ICSound *snd = (ICSound *)declptr;
			    instAddSound(curInstrument, snd, $3->value);
			}
		;

instPan		:	pan "=" intconst
			{
			    instSetPan(curInstrument, $3->value);
			}
		;

instVol		:	volume "=" intconst
			{
			    instSetVol(curInstrument, $3->value);
			}
		;

instVars	:	instPan
		|	instVol
		|	soundRef
		;

instVarList	:	instVarList instVars ";"
		|	/* empty */
		;

instdefn	:	instrument ID 
			{
			    struct decl *declptr = makeinstdecl();
			    declare($2, declptr);
                            curInstrument = (ICInst *) declptr;
			}
			"{" instVarList "}"
		;

programRef	:	program "[" intconst "]" "=" ID
			{
			    struct decl *declptr = findcurrentdecl($6);
			    ICInst *inst = (ICInst *)declptr;
			    bankAddProgram(curBank, inst, $3->value);
			}
		|	/* empty */
		;

programlist	:	programlist programRef ";"
 	  	|	/* empty */
 	  	;

bankdefn        :       bank ID 
			{
			    struct decl *declptr = makebankdecl();
                            declare($2, declptr);
			    curBank = (ICBank *)declptr;
			}
                        "{" programlist "}"
		;

defn		:	bankdefn
		|	instdefn
		|	sndDefn
		|	keyDefn
		|	envDefn
		;

startseq	:	startseq defn
		| 	defn
		;
%%