38 |
%token <sValue> STRING |
%token <sValue> STRING |
39 |
%token <sValue> IDENTIFIER |
%token <sValue> IDENTIFIER |
40 |
%token <sValue> VARIABLE |
%token <sValue> VARIABLE |
41 |
%token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE |
%token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE FUNCTION CALL |
42 |
%token BITWISE_OR BITWISE_AND BITWISE_NOT |
%token BITWISE_OR BITWISE_AND BITWISE_NOT |
43 |
%token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD |
%token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD |
44 |
%token LE GE |
%token LE GE |
45 |
|
|
46 |
%type <nEventHandlers> script eventhandlers |
%type <nEventHandlers> script sections |
47 |
%type <nEventHandler> eventhandler |
%type <nEventHandler> section eventhandler |
48 |
%type <nStatements> statements opt_statements |
%type <nStatements> statements opt_statements userfunctioncall |
49 |
%type <nStatement> statement assignment |
%type <nStatement> statement assignment |
50 |
%type <nFunctionCall> functioncall |
%type <nFunctionCall> functioncall |
51 |
%type <nArgs> args |
%type <nArgs> args |
58 |
%% |
%% |
59 |
|
|
60 |
script: |
script: |
61 |
eventhandlers { |
sections { |
62 |
$$ = context->handlers = $1; |
$$ = context->handlers = $1; |
63 |
} |
} |
64 |
|
|
65 |
eventhandlers: |
sections: |
66 |
eventhandler { |
section { |
67 |
$$ = new EventHandlers(); |
$$ = new EventHandlers(); |
68 |
$$->add($1); |
if ($1) $$->add($1); |
69 |
} |
} |
70 |
| eventhandlers eventhandler { |
| sections section { |
71 |
|
$$ = $1; |
72 |
|
if ($2) $$->add($2); |
73 |
|
} |
74 |
|
|
75 |
|
section: |
76 |
|
function_declaration { |
77 |
|
$$ = EventHandlerRef(); |
78 |
|
} |
79 |
|
| eventhandler { |
80 |
$$ = $1; |
$$ = $1; |
|
$$->add($2); |
|
81 |
} |
} |
82 |
|
|
83 |
eventhandler: |
eventhandler: |
106 |
$$ = context->onController; |
$$ = context->onController; |
107 |
} |
} |
108 |
|
|
109 |
|
function_declaration: |
110 |
|
FUNCTION IDENTIFIER opt_statements END FUNCTION { |
111 |
|
const char* name = $2; |
112 |
|
if (context->functionProvider->functionByName(name)) { |
113 |
|
PARSE_ERR(@2, (String("There is already a built-in function with name '") + name + "'.").c_str()); |
114 |
|
} else if (context->userFunctionByName(name)) { |
115 |
|
PARSE_ERR(@2, (String("There is already a user defined function with name '") + name + "'.").c_str()); |
116 |
|
} else { |
117 |
|
context->userFnTable[name] = $3; |
118 |
|
} |
119 |
|
} |
120 |
|
|
121 |
opt_statements: |
opt_statements: |
122 |
/* epsilon (empty argument) */ { |
/* epsilon (empty argument) */ { |
123 |
$$ = new Statements(); |
$$ = new Statements(); |
146 |
functioncall { |
functioncall { |
147 |
$$ = $1; |
$$ = $1; |
148 |
} |
} |
149 |
|
| userfunctioncall { |
150 |
|
$$ = $1; |
151 |
|
} |
152 |
| DECLARE VARIABLE { |
| DECLARE VARIABLE { |
153 |
const char* name = $2; |
const char* name = $2; |
154 |
//printf("declared var '%s'\n", name); |
//printf("declared var '%s'\n", name); |
358 |
$$.statements = $5; |
$$.statements = $5; |
359 |
} |
} |
360 |
|
|
361 |
|
userfunctioncall: |
362 |
|
CALL IDENTIFIER { |
363 |
|
const char* name = $2; |
364 |
|
StatementsRef fn = context->userFunctionByName(name); |
365 |
|
if (context->functionProvider->functionByName(name)) { |
366 |
|
PARSE_ERR(@1, (String("Keyword 'call' must only be used for user defined functions, not for any built-in function like '") + name + "'.").c_str()); |
367 |
|
$$ = StatementsRef(); |
368 |
|
} else if (!fn) { |
369 |
|
PARSE_ERR(@2, (String("No user defined function with name '") + name + "'.").c_str()); |
370 |
|
$$ = StatementsRef(); |
371 |
|
} else { |
372 |
|
$$ = fn; |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
functioncall: |
functioncall: |
377 |
IDENTIFIER '(' args ')' { |
IDENTIFIER '(' args ')' { |
378 |
const char* name = $1; |
const char* name = $1; |
379 |
//printf("function call of '%s' with args\n", name); |
//printf("function call of '%s' with args\n", name); |
380 |
ArgsRef args = $3; |
ArgsRef args = $3; |
381 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
382 |
if (!fn) { |
if (context->userFunctionByName(name)) { |
383 |
|
PARSE_ERR(@1, (String("Missing 'call' keyword before user defined function name '") + name + "'.").c_str()); |
384 |
|
$$ = new FunctionCall(name, args, NULL); |
385 |
|
} else if (!fn) { |
386 |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
387 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
388 |
} else if (args->argsCount() < fn->minRequiredArgs()) { |
} else if (args->argsCount() < fn->minRequiredArgs()) { |
412 |
//printf("function call of '%s' (with empty args)\n", name); |
//printf("function call of '%s' (with empty args)\n", name); |
413 |
ArgsRef args = new Args; |
ArgsRef args = new Args; |
414 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
415 |
if (!fn) { |
if (context->userFunctionByName(name)) { |
416 |
|
PARSE_ERR(@1, (String("Missing 'call' keyword before user defined function name '") + name + "'.").c_str()); |
417 |
|
$$ = new FunctionCall(name, args, NULL); |
418 |
|
} else if (!fn) { |
419 |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
420 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
421 |
} else if (fn->minRequiredArgs() > 0) { |
} else if (fn->minRequiredArgs() > 0) { |
430 |
//printf("function call of '%s' (without args)\n", name); |
//printf("function call of '%s' (without args)\n", name); |
431 |
ArgsRef args = new Args; |
ArgsRef args = new Args; |
432 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
433 |
if (!fn) { |
if (context->userFunctionByName(name)) { |
434 |
|
PARSE_ERR(@1, (String("Missing 'call' keyword before user defined function name '") + name + "'.").c_str()); |
435 |
|
$$ = new FunctionCall(name, args, NULL); |
436 |
|
} else if (!fn) { |
437 |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
438 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
439 |
} else if (fn->minRequiredArgs() > 0) { |
} else if (fn->minRequiredArgs() > 0) { |