aboutsummaryrefslogtreecommitdiff
path: root/engines/director/lingo/lingo-gr.y
blob: a818cf41fefc7d11a78bbf4f88082791cf16dbad (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

// Heavily inspired by hoc
// Copyright (C) AT&T 1995
// All Rights Reserved
//
// Permission to use, copy, modify, and distribute this software and
// its documentation for any purpose and without fee is hereby
// granted, provided that the above copyright notice appear in all
// copies and that both that the copyright notice and this
// permission notice and warranty disclaimer appear in supporting
// documentation, and that the name of AT&T or any of its entities
// not be used in advertising or publicity pertaining to
// distribution of the software without specific, written prior
// permission.
//
// AT&T DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
// IN NO EVENT SHALL AT&T OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
// THIS SOFTWARE.


%debug

// %glr-parser
// %defines "engines/director/lingo/lingo-gr.h"

%{
#define FORBIDDEN_SYMBOL_ALLOW_ALL

#include "common/endian.h"
#include "common/hash-str.h"
#include "common/rect.h"

#include "director/lingo/lingo.h"
#include "director/lingo/lingo-code.h"
#include "director/lingo/lingo-gr.h"

extern int yylex();
extern int yyparse();

using namespace Director;
void yyerror(const char *s) {
	g_lingo->_hadError = true;
	warning("######################  LINGO: %s at line %d col %d", s, g_lingo->_linenumber, g_lingo->_colnumber);
}

void checkEnd(Common::String *token, const char *expect, bool required) {
	if (required) {
		if (token->compareToIgnoreCase(expect)) {
			Common::String err = Common::String::format("end mismatch. Expected %s but got %s", expect, token->c_str());
			yyerror(err.c_str());
		}
	}

	delete token;
}

%}

%union {
	Common::String *s;
	int i;
	double f;
	int e[2];	// Entity + field
	int code;
	int narg;	/* number of arguments */
	Common::Array<double> *arr;

	struct {
		Common::String *s;
		int e;
	} objectfield;
}

%token UNARY
%token CASTREF VOID VAR POINT RECT ARRAY OBJECT REFERENCE
%token<i> INT ARGC ARGCNORET
%token<e> THEENTITY THEENTITYWITHID
%token<f> FLOAT
%token<s> BLTIN BLTINNOARGS BLTINNOARGSORONE BLTINONEARG BLTINARGLIST TWOWORDBUILTIN
%token<s> FBLTIN FBLTINNOARGS FBLTINONEARG FBLTINARGLIST RBLTIN RBLTINONEARG
%token<s> ID STRING HANDLER SYMBOL
%token<s> ENDCLAUSE tPLAYACCEL tMETHOD
%token<objectfield> THEOBJECTFIELD
%token tDOWN tELSE tELSIF tEXIT tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tMOVIE tNEXT tOF tPREVIOUS tPUT tREPEAT tSET tTHEN tTO tWHEN
%token tWITH tWHILE tNLELSE tFACTORY tOPEN tPLAY tDONE tINSTANCE
%token tGE tLE tEQ tNEQ tAND tOR tNOT tMOD
%token tAFTER tBEFORE tCONCAT tCONTAINS tSTARTS tCHAR tITEM tLINE tWORD
%token tSPRITE tINTERSECTS tWITHIN tTELL tPROPERTY
%token tON tME tENDIF tENDREPEAT tENDTELL

%type<code> asgn begin elseif end expr if when repeatwhile
%type<code> repeatwith stmtlist tell reference simpleexpr
%type<narg> argdef arglist nonemptyarglist
%type<s> on

%left tAND tOR
%left '<' tLE '>' tGE tEQ tNEQ tCONTAINS tSTARTS
%left '&' tCONCAT
%left '+' '-'
%left '*' '/' '%' tMOD
%right UNARY

%%

program: program '\n' programline
	| programline
	| error	'\n'		{ yyerrok; }
	;

programline: /* empty */
	| defn
	| stmt
	;

asgn: tPUT expr tINTO ID 		{
		g_lingo->code1(LC::c_varpush);
		g_lingo->codeString($4->c_str());
		g_lingo->code1(LC::c_assign);
		$$ = $2;
		delete $4; }
	| tPUT expr tINTO reference 		{
			g_lingo->code1(LC::c_assign);
			$$ = $2; }
	| tPUT expr tAFTER expr 		{ $$ = g_lingo->code1(LC::c_after); }		// D3
	| tPUT expr tBEFORE expr 		{ $$ = g_lingo->code1(LC::c_before); }		// D3
	| tSET ID tEQ expr			{
		g_lingo->code1(LC::c_varpush);
		g_lingo->codeString($2->c_str());
		g_lingo->code1(LC::c_assign);
		$$ = $4;
		delete $2; }
	| tSET THEENTITY tEQ expr	{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(0); // Put dummy id
		g_lingo->code1(LC::c_theentityassign);
		g_lingo->codeInt($2[0]);
		g_lingo->codeInt($2[1]);
		$$ = $4; }
	| tSET ID tTO expr			{
		g_lingo->code1(LC::c_varpush);
		g_lingo->codeString($2->c_str());
		g_lingo->code1(LC::c_assign);
		$$ = $4;
		delete $2; }
	| tSET THEENTITY tTO expr	{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(0); // Put dummy id
		g_lingo->code1(LC::c_theentityassign);
		g_lingo->codeInt($2[0]);
		g_lingo->codeInt($2[1]);
		$$ = $4; }
	| tSET THEENTITYWITHID expr tTO expr	{
		g_lingo->code1(LC::c_swap);
		g_lingo->code1(LC::c_theentityassign);
		g_lingo->codeInt($2[0]);
		g_lingo->codeInt($2[1]);
		$$ = $5; }
	| tSET THEENTITYWITHID simpleexpr tEQ expr	{
		g_lingo->code1(LC::c_swap);
		g_lingo->code1(LC::c_theentityassign);
		g_lingo->codeInt($2[0]);
		g_lingo->codeInt($2[1]);
		$$ = $5; }
	| tSET THEOBJECTFIELD tTO expr	{
		g_lingo->code1(LC::c_objectfieldassign);
		g_lingo->codeString($2.s->c_str());
		g_lingo->codeInt($2.e);
		$$ = $4; }
	;

stmtoneliner: macro
	| expr
	| proc
	;

stmtonelinerwithif: macro
	| expr
	| proc
	| ifoneliner
	;

stmt: stmtoneliner
	| ifstmt
	// repeat while (expression = TRUE)
	//   statements
	// end repeat
	//
	| repeatwhile expr end stmtlist end tENDREPEAT	{
		inst body = 0, end = 0;
		WRITE_UINT32(&body, $3 - $1);
		WRITE_UINT32(&end, $5 - $1);
		(*g_lingo->_currentScript)[$1 + 1] = body;	/* body of loop */
		(*g_lingo->_currentScript)[$1 + 2] = end; }	/* end, if cond fails */
	;
	// repeat with index = start to end
	//   statements
	// end repeat
	//
	| repeatwith tEQ expr end tTO expr end stmtlist end tENDREPEAT {
		inst init = 0, finish = 0, body = 0, end = 0, inc = 0;
		WRITE_UINT32(&init, $3 - $1);
		WRITE_UINT32(&finish, $6 - $1);
		WRITE_UINT32(&body, $8 - $1);
		WRITE_UINT32(&end, $9 - $1);
		WRITE_UINT32(&inc, 1);
		(*g_lingo->_currentScript)[$1 + 1] = init;	/* initial count value */
		(*g_lingo->_currentScript)[$1 + 2] = finish;/* final count value */
		(*g_lingo->_currentScript)[$1 + 3] = body;	/* body of loop */
		(*g_lingo->_currentScript)[$1 + 4] = inc;	/* increment */
		(*g_lingo->_currentScript)[$1 + 5] = end; }	/* end, if cond fails */

	// repeat with index = high down to low
	//   statements
	// end repeat
	//
	| repeatwith tEQ expr end tDOWN tTO expr end stmtlist end tENDREPEAT {
		inst init = 0, finish = 0, body = 0, end = 0, inc = 0;
		WRITE_UINT32(&init, $3 - $1);
		WRITE_UINT32(&finish, $7 - $1);
		WRITE_UINT32(&body, $9 - $1);
		WRITE_UINT32(&end, $10 - $1);
		WRITE_UINT32(&inc, (uint32)-1);
		(*g_lingo->_currentScript)[$1 + 1] = init;	/* initial count value */
		(*g_lingo->_currentScript)[$1 + 2] = finish;/* final count value */
		(*g_lingo->_currentScript)[$1 + 3] = body;	/* body of loop */
		(*g_lingo->_currentScript)[$1 + 4] = inc;	/* increment */
		(*g_lingo->_currentScript)[$1 + 5] = end; }	/* end, if cond fails */
	| when stmtonelinerwithif end {
		inst end = 0;
		WRITE_UINT32(&end, $3 - $1);
		g_lingo->code1(STOP);
		(*g_lingo->_currentScript)[$1 + 1] = end; }
	| tell expr '\n' stmtlist end tENDTELL {
			warning("STUB: TELL is not implemented"); }
	| tell expr tTO expr {
			warning("STUB: TELL is not implemented");
		}
	;

ifstmt: if expr end tTHEN stmtlist end elseifstmtlist end tENDIF {
		inst then = 0, else1 = 0, end = 0;
		WRITE_UINT32(&then, $3 - $1);
		WRITE_UINT32(&else1, $6 - $1);
		WRITE_UINT32(&end, $8 - $1);
		(*g_lingo->_currentScript)[$1 + 1] = then;	/* thenpart */
		(*g_lingo->_currentScript)[$1 + 2] = else1;	/* elsepart */
		(*g_lingo->_currentScript)[$1 + 3] = end;	/* end, if cond fails */

		g_lingo->processIf($1, $8 - $1, 0); }
	| if expr end tTHEN stmtlist end elseifstmtlist tELSE begin stmtlist end tENDIF {
		inst then = 0, else1 = 0, end = 0;
		WRITE_UINT32(&then, $3 - $1);
		WRITE_UINT32(&else1, $6 - $1);
		WRITE_UINT32(&end, $11 - $1);
		(*g_lingo->_currentScript)[$1 + 1] = then;	/* thenpart */
		(*g_lingo->_currentScript)[$1 + 2] = else1;	/* elsepart */
		(*g_lingo->_currentScript)[$1 + 3] = end;	/* end, if cond fails */

		g_lingo->processIf($1, $11 - $1, $9 - $1); }
	;

elseifstmtlist:	/* nothing */
	| elseifstmt elseifstmtlist
	;

elseifstmt: elseif expr end tTHEN stmtlist end {
		inst then = 0;
		WRITE_UINT32(&then, $3 - $1);
		(*g_lingo->_currentScript)[$1 + 1] = then;	/* thenpart */

		g_lingo->codeLabel($1); }
	;

ifoneliner: if expr end tTHEN stmtoneliner end tELSE begin stmtoneliner end tENDIF {
		inst then = 0, else1 = 0, end = 0;
		WRITE_UINT32(&then, $3 - $1);
		WRITE_UINT32(&else1, $6 - $1);
		WRITE_UINT32(&end, $10 - $1);
		(*g_lingo->_currentScript)[$1 + 1] = then;	/* thenpart */
		(*g_lingo->_currentScript)[$1 + 2] = else1;	/* elsepart */
		(*g_lingo->_currentScript)[$1 + 3] = end;	/* end, if cond fails */

		g_lingo->processIf($1, $10 - $1, $8 - $1); }
	| if expr end tTHEN stmtoneliner end tENDIF {
			inst then = 0, else1 = 0, end = 0;
			WRITE_UINT32(&then, $3 - $1);
			WRITE_UINT32(&else1, 0);
			WRITE_UINT32(&end, $6 - $1);
			(*g_lingo->_currentScript)[$1 + 1] = then;	/* thenpart */
			(*g_lingo->_currentScript)[$1 + 2] = else1;	/* elsepart */
			(*g_lingo->_currentScript)[$1 + 3] = end;	/* end, if cond fails */

			g_lingo->processIf($1, $6 - $1, $6 - $1); }
	;


repeatwhile:	tREPEAT tWHILE		{ $$ = g_lingo->code3(LC::c_repeatwhilecode, STOP, STOP); }
	;

repeatwith:		tREPEAT tWITH ID	{
		$$ = g_lingo->code3(LC::c_repeatwithcode, STOP, STOP);
		g_lingo->code3(STOP, STOP, STOP);
		g_lingo->codeString($3->c_str());
		delete $3; }
	;

if:	  tIF					{
		$$ = g_lingo->code1(LC::c_ifcode);
		g_lingo->code3(STOP, STOP, STOP);
		g_lingo->code1(0);  // Do not skip end
		g_lingo->codeLabel(0); } // Mark beginning of the if() statement
	;

elseif:	  tELSIF			{
		inst skipEnd;
		WRITE_UINT32(&skipEnd, 1); // We have to skip end to avoid multiple executions
		$$ = g_lingo->code1(LC::c_ifcode);
		g_lingo->code3(STOP, STOP, STOP);
		g_lingo->code1(skipEnd); }
	;

begin:	  /* nothing */		{ $$ = g_lingo->_currentScript->size(); }
	;

end:	  /* nothing */		{ g_lingo->code1(STOP); $$ = g_lingo->_currentScript->size(); }
	;

stmtlist: 					{ $$ = g_lingo->_currentScript->size(); }
	| stmtlist '\n'
	| stmtlist stmt
	;

when:	  tWHEN	ID tTHEN	{
		$$ = g_lingo->code1(LC::c_whencode);
		g_lingo->code1(STOP);
		g_lingo->codeString($2->c_str());
		delete $2; }

tell:	  tTELL				{
		$$ = g_lingo->code1(LC::c_tellcode);
		g_lingo->code1(STOP); }

simpleexpr: INT		{
		$$ = g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt($1); }
	| FLOAT		{
		$$ = g_lingo->code1(LC::c_floatpush);
		g_lingo->codeFloat($1); }
	| SYMBOL	{											// D3
		$$ = g_lingo->code1(LC::c_symbolpush);
		g_lingo->codeString($1->c_str()); }
	| STRING		{
		$$ = g_lingo->code1(LC::c_stringpush);
		g_lingo->codeString($1->c_str()); }
	| ID		{
		$$ = g_lingo->code1(LC::c_eval);
		g_lingo->codeString($1->c_str());
		delete $1; }
	;

expr: simpleexpr { $$ = $1; }
	| reference
	| FBLTINNOARGS 	{
		g_lingo->codeFunc($1, 0);
		delete $1; }
	| FBLTINONEARG expr		{
		g_lingo->codeFunc($1, 1);
		delete $1; }
	| FBLTINARGLIST arglist	{ g_lingo->codeFunc($1, $2); }
	| ID '(' arglist ')'	{
		$$ = g_lingo->codeFunc($1, $3);
		delete $1; }
	| THEENTITY	{
		$$ = g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(0); // Put dummy id
		g_lingo->code1(LC::c_theentitypush);
		inst e = 0, f = 0;
		WRITE_UINT32(&e, $1[0]);
		WRITE_UINT32(&f, $1[1]);
		g_lingo->code2(e, f); }
	| THEENTITYWITHID expr	{
		$$ = g_lingo->code1(LC::c_theentitypush);
		inst e = 0, f = 0;
		WRITE_UINT32(&e, $1[0]);
		WRITE_UINT32(&f, $1[1]);
		g_lingo->code2(e, f); }
	| THEOBJECTFIELD {
		g_lingo->code1(LC::c_objectfieldpush);
		g_lingo->codeString($1.s->c_str());
		g_lingo->codeInt($1.e); }
	| asgn
	| expr '+' expr				{ g_lingo->code1(LC::c_add); }
	| expr '-' expr				{ g_lingo->code1(LC::c_sub); }
	| expr '*' expr				{ g_lingo->code1(LC::c_mul); }
	| expr '/' expr				{ g_lingo->code1(LC::c_div); }
	| expr tMOD expr			{ g_lingo->code1(LC::c_mod); }
	| expr '>' expr				{ g_lingo->code1(LC::c_gt); }
	| expr '<' expr				{ g_lingo->code1(LC::c_lt); }
	| expr tEQ expr				{ g_lingo->code1(LC::c_eq); }
	| expr tNEQ expr			{ g_lingo->code1(LC::c_neq); }
	| expr tGE expr				{ g_lingo->code1(LC::c_ge); }
	| expr tLE expr				{ g_lingo->code1(LC::c_le); }
	| expr tAND expr			{ g_lingo->code1(LC::c_and); }
	| expr tOR expr				{ g_lingo->code1(LC::c_or); }
	| tNOT expr  %prec UNARY	{ g_lingo->code1(LC::c_not); }
	| expr '&' expr				{ g_lingo->code1(LC::c_ampersand); }
	| expr tCONCAT expr			{ g_lingo->code1(LC::c_concat); }
	| expr tCONTAINS expr		{ g_lingo->code1(LC::c_contains); }
	| expr tSTARTS expr			{ g_lingo->code1(LC::c_starts); }
	| '+' expr  %prec UNARY		{ $$ = $2; }
	| '-' expr  %prec UNARY		{ $$ = $2; g_lingo->code1(LC::c_negate); }
	| '(' expr ')'				{ $$ = $2; }
	| '[' arglist ']'			{ $$ = g_lingo->code1(LC::c_arraypush); g_lingo->codeArray($2); }
	| tSPRITE expr tINTERSECTS expr 	{ g_lingo->code1(LC::c_intersects); }
	| tSPRITE expr tWITHIN expr		 	{ g_lingo->code1(LC::c_within); }
	| tCHAR expr tOF expr				{ g_lingo->code1(LC::c_charOf); }
	| tCHAR expr tTO expr tOF expr		{ g_lingo->code1(LC::c_charToOf); }
	| tITEM expr tOF expr				{ g_lingo->code1(LC::c_itemOf); }
	| tITEM expr tTO expr tOF expr		{ g_lingo->code1(LC::c_itemToOf); }
	| tLINE expr tOF expr				{ g_lingo->code1(LC::c_lineOf); }
	| tLINE expr tTO expr tOF expr		{ g_lingo->code1(LC::c_lineToOf); }
	| tWORD expr tOF expr				{ g_lingo->code1(LC::c_wordOf); }
	| tWORD expr tTO expr tOF expr		{ g_lingo->code1(LC::c_wordToOf); }
	| tME '(' ID ')'					{ g_lingo->codeMe($3, 0); }
	| tME '(' ID ',' arglist ')'		{ g_lingo->codeMe($3, $5); }
	| tME								{ g_lingo->codeMe(nullptr, 0); }
	;

reference: 	RBLTINONEARG simpleexpr	{
		g_lingo->codeFunc($1, 1);
		delete $1; }
	;

proc: tPUT expr				{ g_lingo->code1(LC::c_printtop); }
	| gotofunc
	| playfunc
	| tEXIT tREPEAT			{ g_lingo->code1(LC::c_exitRepeat); }
	| tEXIT					{ g_lingo->code1(LC::c_procret); }
	| tGLOBAL globallist
	| tPROPERTY propertylist
	| tINSTANCE instancelist
	| BLTINNOARGS 	{
		g_lingo->codeFunc($1, 0);
		delete $1; }
	| BLTINONEARG expr		{
		g_lingo->codeFunc($1, 1);
		delete $1; }
	| BLTINNOARGSORONE expr	{
		g_lingo->codeFunc($1, 1);
		delete $1; }
	| BLTINNOARGSORONE 		{
		g_lingo->code1(LC::c_voidpush);
		g_lingo->codeFunc($1, 1);
		delete $1; }
	| BLTINARGLIST arglist	{ g_lingo->codeFunc($1, $2); }
	| tOPEN expr tWITH expr	{ g_lingo->code1(LC::c_open); }
	| tOPEN expr 			{ g_lingo->code2(LC::c_voidpush, LC::c_open); }
	| TWOWORDBUILTIN ID arglist	{ Common::String s(*$1); s += '-'; s += *$2; g_lingo->codeFunc(&s, $3); }
	;

globallist: ID					{ g_lingo->code1(LC::c_global); g_lingo->codeString($1->c_str()); delete $1; }
	| globallist ',' ID			{ g_lingo->code1(LC::c_global); g_lingo->codeString($3->c_str()); delete $3; }
	;

propertylist: ID				{ g_lingo->code1(LC::c_property); g_lingo->codeString($1->c_str()); delete $1; }
	| propertylist ',' ID		{ g_lingo->code1(LC::c_property); g_lingo->codeString($3->c_str()); delete $3; }
	;

instancelist: ID				{ g_lingo->code1(LC::c_instance); g_lingo->codeString($1->c_str()); delete $1; }
	| instancelist ',' ID		{ g_lingo->code1(LC::c_instance); g_lingo->codeString($3->c_str()); delete $3; }
	;

// go {to} {frame} whichFrame {of movie whichMovie}
// go {to} {frame "Open23" of} movie whichMovie
// go loop
// go next
// go previous
// go to {frame} whichFrame {of movie whichMovie}
// go to {frame whichFrame of} movie whichMovie

gotofunc: tGO tLOOP				{ g_lingo->code1(LC::c_gotoloop); }
	| tGO tNEXT					{ g_lingo->code1(LC::c_gotonext); }
	| tGO tPREVIOUS				{ g_lingo->code1(LC::c_gotoprevious); }
	| tGO expr 			{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(1);
		g_lingo->code1(LC::c_goto); }
	| tGO expr gotomovie	{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(3);
		g_lingo->code1(LC::c_goto); }
	| tGO gotomovie				{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(2);
		g_lingo->code1(LC::c_goto); }
	;

gotomovie: tOF tMOVIE expr
	| tMOVIE expr
	;

playfunc: tPLAY tDONE			{ g_lingo->code1(LC::c_playdone); }
	| tPLAY expr 			{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(1);
		g_lingo->code1(LC::c_play); }
	| tPLAY expr gotomovie	{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(3);
		g_lingo->code1(LC::c_play); }
	| tPLAY gotomovie				{
		g_lingo->code1(LC::c_intpush);
		g_lingo->codeInt(2);
		g_lingo->code1(LC::c_play); }
	| tPLAYACCEL { g_lingo->codeSetImmediate(true); } arglist	{
		g_lingo->codeSetImmediate(false);
		g_lingo->codeFunc($1, $3); }
	;

// macro
//
// Special Note  The macro keyword is retained in Director 3.0 to maintain compatibility
// with scripts developed under Version 2.0. When writing new scripts, or editing old
// scripts, you should use handlers instead of macros. (Handlers are defined with the on keyword.)
//
// Syntax:
//
// --  [comment]
// macro macroName [argument1] [, argument2]
// [, argument3]
// [statement1]
// [statement2]
//
// Keyword.  Defines a macro. A macro is a multiple-line script defined
// in the Text window. Macros can accept arguments (inputs) and
// optionally return a result. Macros can call other macros and can be
// called from any other script or factory.
//
// The first line of a castmember in the Text window that contains a macro must be
// a comment (--). You can define more than one macro in a given text castmember.
// The macro definition ends where the next macro (or factory) begins.
//
// See also:
//   on keyword
defn: tMACRO ID { g_lingo->_indef = kStateInArgs; g_lingo->_currentFactory.clear(); }
		begin argdef '\n' argstore stmtlist 		{
			g_lingo->code1(LC::c_procret);
			g_lingo->define(*$2, $4, $5);
			g_lingo->clearArgStack();
			g_lingo->_indef = kStateNone; }
	| tFACTORY ID	{ g_lingo->codeFactory(*$2); }
	| tMETHOD { g_lingo->_indef = kStateInArgs; }
		begin argdef '\n' argstore stmtlist 		{
			g_lingo->code1(LC::c_procret);
			g_lingo->define(*$1, $3, $4 + 1, &g_lingo->_currentFactory);
			g_lingo->clearArgStack();
			g_lingo->_indef = kStateNone; }
	| on begin argdef '\n' argstore stmtlist ENDCLAUSE endargdef {	// D3
		g_lingo->code1(LC::c_procret);
		g_lingo->define(*$1, $2, $3);
		g_lingo->clearArgStack();
		g_lingo->_indef = kStateNone;
		g_lingo->_ignoreMe = false;

		checkEnd($7, $1->c_str(), false); }
	| on begin argdef '\n' argstore stmtlist {	// D4. No 'end' clause
		g_lingo->code1(LC::c_procret);
		g_lingo->define(*$1, $2, $3);
		g_lingo->_indef = kStateNone;
		g_lingo->clearArgStack();
		g_lingo->_ignoreMe = false; }

on:  tON ID { $$ = $2; g_lingo->_indef = kStateInArgs; g_lingo->_currentFactory.clear(); g_lingo->_ignoreMe = true; }

argdef:  /* nothing */ 		{ $$ = 0; }
	| ID					{ g_lingo->codeArg($1); $$ = 1; }
	| argdef ',' ID			{ g_lingo->codeArg($3); $$ = $1 + 1; }
	| argdef '\n' ',' ID	{ g_lingo->codeArg($4); $$ = $1 + 1; }
	;

endargdef:	/* nothing */
	| ID
	| endargdef ',' ID
	;

argstore:	  /* nothing */		{ g_lingo->codeArgStore(); g_lingo->_indef = kStateInDef; }
	;

macro: ID nonemptyarglist	{
		g_lingo->code1(LC::c_call);
		g_lingo->codeString($1->c_str());
		inst numpar = 0;
		WRITE_UINT32(&numpar, $2);
		g_lingo->code1(numpar); }
	;

arglist:  /* nothing */ 	{ $$ = 0; }
	| expr					{ $$ = 1; }
	| arglist ',' expr		{ $$ = $1 + 1; }
	;

nonemptyarglist:  expr			{ $$ = 1; }
	| nonemptyarglist ',' expr	{ $$ = $1 + 1; }
	;

%%