280 |
PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
281 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
282 |
} else if (args->argsCount() > size) { |
} else if (args->argsCount() > size) { |
283 |
PARSE_ERR(@8, (String("Variable '") + name + |
PARSE_ERR(@8, (String("Array variable '") + name + |
284 |
"' was declared with size " + ToString(size) + |
"' was declared with size " + ToString(size) + |
285 |
" but " + ToString(args->argsCount()) + |
" but " + ToString(args->argsCount()) + |
286 |
" values were assigned." ).c_str()); |
" values were assigned." ).c_str()); |
307 |
} |
} |
308 |
} |
} |
309 |
} |
} |
310 |
|
| DECLARE CONST_ VARIABLE '[' expr ']' ASSIGNMENT '(' args ')' { |
311 |
|
const char* name = $3; |
312 |
|
if (!$5->isConstExpr()) { |
313 |
|
PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
314 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
315 |
|
} else if ($5->exprType() != INT_EXPR) { |
316 |
|
PARSE_ERR(@5, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
317 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
318 |
|
} else if (context->variableByName(name)) { |
319 |
|
PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str()); |
320 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
321 |
|
} else { |
322 |
|
IntExprRef sizeExpr = $5; |
323 |
|
ArgsRef args = $9; |
324 |
|
int size = sizeExpr->evalInt(); |
325 |
|
if (size <= 0) { |
326 |
|
PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
327 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
328 |
|
} else if (args->argsCount() > size) { |
329 |
|
PARSE_ERR(@9, (String("Array variable '") + name + |
330 |
|
"' was declared with size " + ToString(size) + |
331 |
|
" but " + ToString(args->argsCount()) + |
332 |
|
" values were assigned." ).c_str()); |
333 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
334 |
|
} else { |
335 |
|
bool argsOK = true; |
336 |
|
for (int i = 0; i < args->argsCount(); ++i) { |
337 |
|
if (args->arg(i)->exprType() != INT_EXPR) { |
338 |
|
PARSE_ERR( |
339 |
|
@9, |
340 |
|
(String("Array variable '") + name + |
341 |
|
"' declared with invalid assignment values. Assigned element " + |
342 |
|
ToString(i+1) + " is not an integer expression.").c_str() |
343 |
|
); |
344 |
|
argsOK = false; |
345 |
|
break; |
346 |
|
} |
347 |
|
if (!args->arg(i)->isConstExpr()) { |
348 |
|
PARSE_ERR( |
349 |
|
@9, |
350 |
|
(String("const array variable '") + name + |
351 |
|
"' must be defined with const values. Assigned element " + |
352 |
|
ToString(i+1) + " is not a const expression though.").c_str() |
353 |
|
); |
354 |
|
argsOK = false; |
355 |
|
break; |
356 |
|
} |
357 |
|
} |
358 |
|
if (argsOK) { |
359 |
|
context->vartable[name] = new IntArrayVariable(context, size, args, true); |
360 |
|
$$ = new NoOperation; |
361 |
|
} else |
362 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
363 |
|
} |
364 |
|
} |
365 |
|
} |
366 |
| DECLARE CONST_ VARIABLE ASSIGNMENT expr { |
| DECLARE CONST_ VARIABLE ASSIGNMENT expr { |
367 |
const char* name = $3; |
const char* name = $3; |
368 |
if ($5->exprType() == STRING_EXPR) { |
if ($5->exprType() == STRING_EXPR) { |
571 |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
572 |
else if ($6->exprType() != INT_EXPR) |
else if ($6->exprType() != INT_EXPR) |
573 |
PARSE_ERR(@5, (String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str()); |
PARSE_ERR(@5, (String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str()); |
574 |
|
else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
575 |
|
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
576 |
|
" exceeds size of array variable '" + name + |
577 |
|
"' which was declared with size " + |
578 |
|
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
579 |
IntArrayElementRef element = new IntArrayElement(var, $3); |
IntArrayElementRef element = new IntArrayElement(var, $3); |
580 |
$$ = new Assignment(element, $6); |
$$ = new Assignment(element, $6); |
581 |
} |
} |
610 |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
611 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
612 |
} else { |
} else { |
613 |
|
if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
614 |
|
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
615 |
|
" exceeds size of array variable '" + name + |
616 |
|
"' which was declared with size " + |
617 |
|
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
618 |
$$ = new IntArrayElement(var, $3); |
$$ = new IntArrayElement(var, $3); |
619 |
} |
} |
620 |
} |
} |