39 |
%error-verbose |
%error-verbose |
40 |
|
|
41 |
%token <iValue> INTEGER "integer literal" |
%token <iValue> INTEGER "integer literal" |
42 |
|
%token <iUnitValue> INTEGER_UNIT "integer literal with unit" |
43 |
%token <sValue> STRING "string literal" |
%token <sValue> STRING "string literal" |
44 |
%token <sValue> IDENTIFIER "function name" |
%token <sValue> IDENTIFIER "function name" |
45 |
%token <sValue> VARIABLE "variable name" |
%token <sValue> VARIABLE "variable name" |
229 |
if (name[0] == '@') |
if (name[0] == '@') |
230 |
PARSE_WRN(@2, (String("Variable '") + name + "' declared as string, integer expression assigned though.").c_str()); |
PARSE_WRN(@2, (String("Variable '") + name + "' declared as string, integer expression assigned though.").c_str()); |
231 |
IntExprRef expr = $4; |
IntExprRef expr = $4; |
232 |
|
IntVariableRef var = new IntVariable(context); |
233 |
if (expr->isConstExpr()) { |
if (expr->isConstExpr()) { |
234 |
const vmint i = expr->evalInt(); |
const vmint i = expr->evalInt(); |
|
IntVariableRef var = new IntVariable(context); |
|
|
context->vartable[name] = var; |
|
235 |
$$ = new Assignment(var, new IntLiteral(i)); |
$$ = new Assignment(var, new IntLiteral(i)); |
236 |
} else { |
} else { |
|
IntVariableRef var = new IntVariable(context); |
|
|
context->vartable[name] = var; |
|
237 |
$$ = new Assignment(var, expr); |
$$ = new Assignment(var, expr); |
238 |
} |
} |
239 |
|
var->copyUnitFrom(expr); |
240 |
|
var->setFinal(expr->isFinal()); |
241 |
|
context->vartable[name] = var; |
242 |
} |
} |
243 |
} |
} |
244 |
| DECLARE VARIABLE '[' expr ']' { |
| DECLARE VARIABLE '[' expr ']' { |
255 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
256 |
} else { |
} else { |
257 |
IntExprRef expr = $4; |
IntExprRef expr = $4; |
258 |
vmint size = expr->evalInt(); |
if (expr->unitType() || expr->unitPrefix(0)) { |
259 |
if (size <= 0) { |
PARSE_ERR(@4, "Units are not allowed as array size."); |
|
PARSE_ERR(@4, (String("Array variable '") + name + "' declared with array size " + ToString(size) + ".").c_str()); |
|
260 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
261 |
} else { |
} else { |
262 |
context->vartable[name] = new IntArrayVariable(context, size); |
if (expr->isFinal()) |
263 |
$$ = new NoOperation; |
PARSE_WRN(@4, "Final operator '!' is meaningless here."); |
264 |
|
vmint size = expr->evalInt(); |
265 |
|
if (size <= 0) { |
266 |
|
PARSE_ERR(@4, (String("Array variable '") + name + "' declared with array size " + ToString(size) + ".").c_str()); |
267 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
268 |
|
} else { |
269 |
|
context->vartable[name] = new IntArrayVariable(context, size); |
270 |
|
$$ = new NoOperation; |
271 |
|
} |
272 |
} |
} |
273 |
} |
} |
274 |
} |
} |
295 |
"' was declared with size " + ToString(size) + |
"' was declared with size " + ToString(size) + |
296 |
" but " + ToString(args->argsCount()) + |
" but " + ToString(args->argsCount()) + |
297 |
" values were assigned." ).c_str()); |
" values were assigned." ).c_str()); |
298 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
299 |
|
} else if (sizeExpr->unitType() || sizeExpr->unitPrefix(0)) { |
300 |
|
PARSE_ERR(@4, "Units are not allowed as array size."); |
301 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
302 |
} else { |
} else { |
303 |
|
if (sizeExpr->isFinal()) |
304 |
|
PARSE_WRN(@4, "Final operator '!' is meaningless here."); |
305 |
bool argsOK = true; |
bool argsOK = true; |
306 |
for (vmint i = 0; i < args->argsCount(); ++i) { |
for (vmint i = 0; i < args->argsCount(); ++i) { |
307 |
if (args->arg(i)->exprType() != INT_EXPR) { |
if (args->arg(i)->exprType() != INT_EXPR) { |
313 |
); |
); |
314 |
argsOK = false; |
argsOK = false; |
315 |
break; |
break; |
316 |
|
} else if (args->arg(i)->asInt()->unitType() || |
317 |
|
args->arg(i)->asInt()->unitPrefix(0)) |
318 |
|
{ |
319 |
|
PARSE_ERR( |
320 |
|
@8, |
321 |
|
(String("Array variable '") + name + |
322 |
|
"' declared with invalid assignment values. Assigned element " + |
323 |
|
ToString(i+1) + " contains a unit.").c_str() |
324 |
|
); |
325 |
|
argsOK = false; |
326 |
|
break; |
327 |
} |
} |
328 |
} |
} |
329 |
if (argsOK) { |
if (argsOK) { |
357 |
"' was declared with size " + ToString(size) + |
"' was declared with size " + ToString(size) + |
358 |
" but " + ToString(args->argsCount()) + |
" but " + ToString(args->argsCount()) + |
359 |
" values were assigned." ).c_str()); |
" values were assigned." ).c_str()); |
360 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
361 |
|
} else if (sizeExpr->unitType() || sizeExpr->unitPrefix(0)) { |
362 |
|
PARSE_ERR(@5, "Units are not allowed as array size."); |
363 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
364 |
} else { |
} else { |
365 |
|
if (sizeExpr->isFinal()) |
366 |
|
PARSE_WRN(@5, "Final operator '!' is meaningless here."); |
367 |
bool argsOK = true; |
bool argsOK = true; |
368 |
for (vmint i = 0; i < args->argsCount(); ++i) { |
for (vmint i = 0; i < args->argsCount(); ++i) { |
369 |
if (args->arg(i)->exprType() != INT_EXPR) { |
if (args->arg(i)->exprType() != INT_EXPR) { |
385 |
); |
); |
386 |
argsOK = false; |
argsOK = false; |
387 |
break; |
break; |
388 |
|
} else if (args->arg(i)->asInt()->unitType() || |
389 |
|
args->arg(i)->asInt()->unitPrefix(0)) |
390 |
|
{ |
391 |
|
PARSE_ERR( |
392 |
|
@9, |
393 |
|
(String("const array variable '") + name + |
394 |
|
"' declared with invalid assignment values. Assigned element " + |
395 |
|
ToString(i+1) + " contains a unit.").c_str() |
396 |
|
); |
397 |
|
argsOK = false; |
398 |
|
break; |
399 |
} |
} |
400 |
} |
} |
401 |
if (argsOK) { |
if (argsOK) { |
431 |
else |
else |
432 |
PARSE_ERR(@5, (String("Assignment to const integer variable '") + name + "' requires const expression.").c_str()); |
PARSE_ERR(@5, (String("Assignment to const integer variable '") + name + "' requires const expression.").c_str()); |
433 |
ConstIntVariableRef var = new ConstIntVariable(i); |
ConstIntVariableRef var = new ConstIntVariable(i); |
434 |
|
var->copyUnitFrom(expr); |
435 |
|
var->setFinal(expr->isFinal()); |
436 |
context->vartable[name] = var; |
context->vartable[name] = var; |
437 |
//$$ = new Assignment(var, new IntLiteral(i)); |
//$$ = new Assignment(var, new IntLiteral(i)); |
438 |
$$ = new NoOperation(); |
$$ = new NoOperation(); |
443 |
} |
} |
444 |
| WHILE '(' expr ')' opt_statements END WHILE { |
| WHILE '(' expr ')' opt_statements END WHILE { |
445 |
if ($3->exprType() == INT_EXPR) { |
if ($3->exprType() == INT_EXPR) { |
446 |
$$ = new While($3, $5); |
IntExprRef expr = $3; |
447 |
|
if (expr->isFinal() && expr->isConstExpr()) |
448 |
|
PARSE_WRN(@3, "Final operator '!' is meaningless here."); |
449 |
|
$$ = new While(expr, $5); |
450 |
} else { |
} else { |
451 |
PARSE_ERR(@3, "Condition for 'while' loops must be integer expression."); |
PARSE_ERR(@3, "Condition for 'while' loops must be integer expression."); |
452 |
$$ = new While(new IntLiteral(0), $5); |
$$ = new While(new IntLiteral(0), $5); |
456 |
$$ = new SyncBlock($2); |
$$ = new SyncBlock($2); |
457 |
} |
} |
458 |
| IF '(' expr ')' opt_statements ELSE opt_statements END IF { |
| IF '(' expr ')' opt_statements ELSE opt_statements END IF { |
459 |
$$ = new If($3, $5, $7); |
if ($3->exprType() == INT_EXPR) { |
460 |
|
IntExprRef expr = $3; |
461 |
|
if (expr->isFinal() && expr->isConstExpr()) |
462 |
|
PARSE_WRN(@3, "Final operator '!' is meaningless here."); |
463 |
|
$$ = new If($3, $5, $7); |
464 |
|
} else { |
465 |
|
PARSE_ERR(@3, "Condition for 'if' must be integer expression."); |
466 |
|
$$ = new If(new IntLiteral(0), $5, $7); |
467 |
|
} |
468 |
} |
} |
469 |
| IF '(' expr ')' opt_statements END IF { |
| IF '(' expr ')' opt_statements END IF { |
470 |
$$ = new If($3, $5); |
if ($3->exprType() == INT_EXPR) { |
471 |
|
IntExprRef expr = $3; |
472 |
|
if (expr->isFinal() && expr->isConstExpr()) |
473 |
|
PARSE_WRN(@3, "Final operator '!' is meaningless here."); |
474 |
|
$$ = new If($3, $5); |
475 |
|
} else { |
476 |
|
PARSE_ERR(@3, "Condition for 'if' must be integer expression."); |
477 |
|
$$ = new If(new IntLiteral(0), $5); |
478 |
|
} |
479 |
} |
} |
480 |
| SELECT expr caseclauses END SELECT { |
| SELECT expr caseclauses END SELECT { |
481 |
if ($2->exprType() == INT_EXPR) { |
if ($2->exprType() == INT_EXPR) { |
482 |
$$ = new SelectCase($2, $3); |
IntExprRef expr = $2; |
483 |
|
if (expr->unitType() || expr->unitPrefix(0)) { |
484 |
|
PARSE_ERR(@2, "Units are not allowed here."); |
485 |
|
} else { |
486 |
|
if (expr->isFinal() && expr->isConstExpr()) |
487 |
|
PARSE_WRN(@2, "Final operator '!' is meaningless here."); |
488 |
|
$$ = new SelectCase(expr, $3); |
489 |
|
} |
490 |
} else { |
} else { |
491 |
PARSE_ERR(@2, "Statement 'select' can only by applied to integer expressions."); |
PARSE_ERR(@2, "Statement 'select' can only by applied to integer expressions."); |
492 |
$$ = new SelectCase(new IntLiteral(0), $3); |
$$ = new SelectCase(new IntLiteral(0), $3); |
563 |
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects an assignable variable.").c_str()); |
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects an assignable variable.").c_str()); |
564 |
argsOK = false; |
argsOK = false; |
565 |
break; |
break; |
566 |
|
} else if (args->arg(i)->exprType() == INT_EXPR && !fn->acceptsArgUnitType(i, args->arg(i)->asInt()->unitType())) { |
567 |
|
if (args->arg(i)->asInt()->unitType()) |
568 |
|
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' does not expect unit " + unitTypeStr(args->arg(i)->asInt()->unitType()) + ".").c_str()); |
569 |
|
else |
570 |
|
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects a unit.").c_str()); |
571 |
|
argsOK = false; |
572 |
|
break; |
573 |
|
} else if (!fn->acceptsArgUnitPrefix(i) && args->arg(i)->exprType() == INT_EXPR && args->arg(i)->asInt()->unitPrefix(0)) { |
574 |
|
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' does not expect a unit prefix.").c_str()); |
575 |
|
argsOK = false; |
576 |
|
break; |
577 |
|
} else if (!fn->acceptsArgFinal(i) && args->arg(i)->exprType() == INT_EXPR && args->arg(i)->asInt()->isFinal()) { |
578 |
|
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' does not expect a \"final\" value.").c_str()); |
579 |
|
argsOK = false; |
580 |
|
break; |
581 |
} |
} |
582 |
} |
} |
583 |
$$ = new FunctionCall(name, args, argsOK ? fn : NULL); |
$$ = new FunctionCall(name, args, argsOK ? fn : NULL); |
652 |
PARSE_ERR(@2, (String("Variable assignment: Variable '") + name + "' is not assignable.").c_str()); |
PARSE_ERR(@2, (String("Variable assignment: Variable '") + name + "' is not assignable.").c_str()); |
653 |
else if (var->exprType() != $3->exprType()) |
else if (var->exprType() != $3->exprType()) |
654 |
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' is of type " + typeStr(var->exprType()) + ", assignment is of type " + typeStr($3->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' is of type " + typeStr(var->exprType()) + ", assignment is of type " + typeStr($3->exprType()) + " though.").c_str()); |
655 |
|
else if (var->exprType() == INT_EXPR) { |
656 |
|
IntVariableRef intVar = var; |
657 |
|
IntExprRef expr = $3; |
658 |
|
if (intVar->unitType() != expr->unitType()) |
659 |
|
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' has unit type " + unitTypeStr(intVar->unitType()) + ", assignment has unit type " + unitTypeStr(expr->unitType()) + " though.").c_str()); |
660 |
|
else if (intVar->unitFactor() != expr->unitFactor()) |
661 |
|
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' has a different unit prefix.").c_str()); |
662 |
|
else if (intVar->isFinal() != expr->isFinal()) |
663 |
|
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' was declared as " + String(intVar->isFinal() ? "final" : "not final") + ", assignment is " + String(expr->isFinal() ? "final" : "not final") + " though.").c_str()); |
664 |
|
} |
665 |
$$ = new Assignment(var, $3); |
$$ = new Assignment(var, $3); |
666 |
} |
} |
667 |
| VARIABLE '[' expr ']' ASSIGNMENT expr { |
| VARIABLE '[' expr ']' ASSIGNMENT expr { |
677 |
PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str()); |
PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str()); |
678 |
else if ($3->exprType() != INT_EXPR) |
else if ($3->exprType() != INT_EXPR) |
679 |
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()); |
680 |
|
else if ($3->asInt()->unitType()) |
681 |
|
PARSE_ERR(@3, "Unit types are not allowed as array index."); |
682 |
else if ($6->exprType() != INT_EXPR) |
else if ($6->exprType() != INT_EXPR) |
683 |
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()); |
684 |
|
else if ($6->asInt()->unitType()) |
685 |
|
PARSE_ERR(@6, "Unit types are not allowed for array variables."); |
686 |
|
else if ($6->asInt()->isFinal()) |
687 |
|
PARSE_ERR(@6, "Final operator '!' not allowed for array variables."); |
688 |
else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
689 |
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
690 |
" exceeds size of array variable '" + name + |
" exceeds size of array variable '" + name + |
691 |
"' which was declared with size " + |
"' which was declared with size " + |
692 |
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
693 |
|
else if ($3->asInt()->isFinal()) |
694 |
|
PARSE_WRN(@3, "Final operator '!' is meaningless here."); |
695 |
IntArrayElementRef element = new IntArrayElement(var, $3); |
IntArrayElementRef element = new IntArrayElement(var, $3); |
696 |
$$ = new Assignment(element, $6); |
$$ = new Assignment(element, $6); |
697 |
} |
} |
700 |
INTEGER { |
INTEGER { |
701 |
$$ = new IntLiteral($1); |
$$ = new IntLiteral($1); |
702 |
} |
} |
703 |
|
| INTEGER_UNIT { |
704 |
|
IntLiteralRef literal = new IntLiteral($1.iValue); |
705 |
|
literal->setUnit($1.prefix, $1.unit); |
706 |
|
$$ = literal; |
707 |
|
} |
708 |
| STRING { |
| STRING { |
709 |
$$ = new StringLiteral($1); |
$$ = new StringLiteral($1); |
710 |
} |
} |
730 |
} else if ($3->exprType() != INT_EXPR) { |
} else if ($3->exprType() != INT_EXPR) { |
731 |
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()); |
732 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
733 |
|
} else if ($3->asInt()->unitType() || $3->asInt()->unitPrefix(0)) { |
734 |
|
PARSE_ERR(@3, "Units are not allowed as array index."); |
735 |
|
$$ = new IntLiteral(0); |
736 |
} else { |
} else { |
737 |
if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
738 |
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
739 |
" exceeds size of array variable '" + name + |
" exceeds size of array variable '" + name + |
740 |
"' which was declared with size " + |
"' which was declared with size " + |
741 |
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
742 |
|
else if ($3->asInt()->isFinal()) |
743 |
|
PARSE_WRN(@3, "Final operator '!' is meaningless here."); |
744 |
$$ = new IntArrayElement(var, $3); |
$$ = new IntArrayElement(var, $3); |
745 |
} |
} |
746 |
} |
} |
757 |
if ($2->exprType() != INT_EXPR) { |
if ($2->exprType() != INT_EXPR) { |
758 |
PARSE_ERR(@2, (String("Right operand of bitwise operator '.not.' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
PARSE_ERR(@2, (String("Right operand of bitwise operator '.not.' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
759 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
760 |
|
} else if ($2->asInt()->unitType() || $2->asInt()->unitPrefix(0)) { |
761 |
|
PARSE_ERR(@2, "Units are not allowed for operands of bitwise operations."); |
762 |
|
$$ = new IntLiteral(0); |
763 |
} else { |
} else { |
764 |
$$ = new BitwiseNot($2); |
$$ = new BitwiseNot($2); |
765 |
} |
} |
768 |
if ($2->exprType() != INT_EXPR) { |
if ($2->exprType() != INT_EXPR) { |
769 |
PARSE_ERR(@2, (String("Right operand of operator 'not' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
PARSE_ERR(@2, (String("Right operand of operator 'not' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
770 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
771 |
|
} else if ($2->asInt()->unitType() || $2->asInt()->unitPrefix(0)) { |
772 |
|
PARSE_ERR(@2, "Units are not allowed for operands of logical operations."); |
773 |
|
$$ = new IntLiteral(0); |
774 |
} else { |
} else { |
775 |
$$ = new Not($2); |
$$ = new Not($2); |
776 |
} |
} |
777 |
} |
} |
778 |
|
| '!' unary_expr { |
779 |
|
if ($2->exprType() != INT_EXPR) { |
780 |
|
PARSE_ERR(@2, (String("Right operand of \"final\" operator '!' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
781 |
|
$$ = new IntLiteral(0); |
782 |
|
} else { |
783 |
|
$$ = new Final($2); |
784 |
|
} |
785 |
|
} |
786 |
|
|
787 |
expr: |
expr: |
788 |
concat_expr |
concat_expr |
812 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
813 |
PARSE_ERR(@3, (String("Right operand of operator 'or' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator 'or' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
814 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
815 |
|
} else if (lhs->asInt()->unitType() || lhs->asInt()->unitPrefix(0)) { |
816 |
|
PARSE_ERR(@1, "Units are not allowed for operands of logical operations."); |
817 |
|
$$ = new IntLiteral(0); |
818 |
|
} else if (rhs->asInt()->unitType() || rhs->asInt()->unitPrefix(0)) { |
819 |
|
PARSE_ERR(@3, "Units are not allowed for operands of logical operations."); |
820 |
|
$$ = new IntLiteral(0); |
821 |
} else { |
} else { |
822 |
$$ = new Or(lhs, rhs); |
$$ = new Or(lhs, rhs); |
823 |
} |
} |
836 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
837 |
PARSE_ERR(@3, (String("Right operand of operator 'and' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator 'and' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
838 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
839 |
|
} else if (lhs->asInt()->unitType() || lhs->asInt()->unitPrefix(0)) { |
840 |
|
PARSE_ERR(@1, "Units are not allowed for operands of logical operations."); |
841 |
|
$$ = new IntLiteral(0); |
842 |
|
} else if (rhs->asInt()->unitType() || rhs->asInt()->unitPrefix(0)) { |
843 |
|
PARSE_ERR(@3, "Units are not allowed for operands of logical operations."); |
844 |
|
$$ = new IntLiteral(0); |
845 |
} else { |
} else { |
846 |
$$ = new And(lhs, rhs); |
$$ = new And(lhs, rhs); |
847 |
} |
} |
858 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
859 |
PARSE_ERR(@3, (String("Right operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
860 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
861 |
|
} else if (lhs->asInt()->unitType() || lhs->asInt()->unitPrefix(0)) { |
862 |
|
PARSE_ERR(@1, "Units are not allowed for operands of bitwise operations."); |
863 |
|
$$ = new IntLiteral(0); |
864 |
|
} else if (rhs->asInt()->unitType() || rhs->asInt()->unitPrefix(0)) { |
865 |
|
PARSE_ERR(@3, "Units are not allowed for operands of bitwise operations."); |
866 |
|
$$ = new IntLiteral(0); |
867 |
} else { |
} else { |
868 |
$$ = new BitwiseOr(lhs, rhs); |
$$ = new BitwiseOr(lhs, rhs); |
869 |
} |
} |
882 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
883 |
PARSE_ERR(@3, (String("Right operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
884 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
885 |
|
} else if (lhs->asInt()->unitType() || lhs->asInt()->unitPrefix(0)) { |
886 |
|
PARSE_ERR(@1, "Units are not allowed for operands of bitwise operations."); |
887 |
|
$$ = new IntLiteral(0); |
888 |
|
} else if (rhs->asInt()->unitType() || rhs->asInt()->unitPrefix(0)) { |
889 |
|
PARSE_ERR(@3, "Units are not allowed for operands of bitwise operations."); |
890 |
|
$$ = new IntLiteral(0); |
891 |
} else { |
} else { |
892 |
$$ = new BitwiseAnd(lhs, rhs); |
$$ = new BitwiseAnd(lhs, rhs); |
893 |
} |
} |
904 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
905 |
PARSE_ERR(@3, (String("Right operand of operator '<' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '<' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
906 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
907 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
908 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
909 |
|
{ |
910 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
911 |
|
$$ = new IntLiteral(0); |
912 |
} else { |
} else { |
913 |
$$ = new Relation(lhs, Relation::LESS_THAN, rhs); |
$$ = new Relation(lhs, Relation::LESS_THAN, rhs); |
914 |
} |
} |
922 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
923 |
PARSE_ERR(@3, (String("Right operand of operator '>' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '>' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
924 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
925 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
926 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
927 |
|
{ |
928 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
929 |
|
$$ = new IntLiteral(0); |
930 |
} else { |
} else { |
931 |
$$ = new Relation(lhs, Relation::GREATER_THAN, rhs); |
$$ = new Relation(lhs, Relation::GREATER_THAN, rhs); |
932 |
} |
} |
940 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
941 |
PARSE_ERR(@3, (String("Right operand of operator '<=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '<=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
942 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
943 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
944 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
945 |
|
{ |
946 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
947 |
|
$$ = new IntLiteral(0); |
948 |
} else { |
} else { |
949 |
$$ = new Relation(lhs, Relation::LESS_OR_EQUAL, rhs); |
$$ = new Relation(lhs, Relation::LESS_OR_EQUAL, rhs); |
950 |
} |
} |
958 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
959 |
PARSE_ERR(@3, (String("Right operand of operator '>=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '>=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
960 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
961 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
962 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
963 |
|
{ |
964 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
965 |
|
$$ = new IntLiteral(0); |
966 |
} else { |
} else { |
967 |
$$ = new Relation(lhs, Relation::GREATER_OR_EQUAL, rhs); |
$$ = new Relation(lhs, Relation::GREATER_OR_EQUAL, rhs); |
968 |
} |
} |
969 |
} |
} |
970 |
| rel_expr '=' add_expr { |
| rel_expr '=' add_expr { |
971 |
$$ = new Relation($1, Relation::EQUAL, $3); |
ExpressionRef lhs = $1; |
972 |
|
ExpressionRef rhs = $3; |
973 |
|
if (lhs->exprType() != INT_EXPR) { |
974 |
|
PARSE_ERR(@1, (String("Left operand of operator '=' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
975 |
|
$$ = new IntLiteral(0); |
976 |
|
} else if (rhs->exprType() != INT_EXPR) { |
977 |
|
PARSE_ERR(@3, (String("Right operand of operator '=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
978 |
|
$$ = new IntLiteral(0); |
979 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
980 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
981 |
|
{ |
982 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
983 |
|
$$ = new IntLiteral(0); |
984 |
|
} else { |
985 |
|
$$ = new Relation(lhs, Relation::EQUAL, rhs); |
986 |
|
} |
987 |
} |
} |
988 |
| rel_expr '#' add_expr { |
| rel_expr '#' add_expr { |
989 |
$$ = new Relation($1, Relation::NOT_EQUAL, $3); |
ExpressionRef lhs = $1; |
990 |
|
ExpressionRef rhs = $3; |
991 |
|
if (lhs->exprType() != INT_EXPR) { |
992 |
|
PARSE_ERR(@1, (String("Left operand of operator '#' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
993 |
|
$$ = new IntLiteral(0); |
994 |
|
} else if (rhs->exprType() != INT_EXPR) { |
995 |
|
PARSE_ERR(@3, (String("Right operand of operator '#' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
996 |
|
$$ = new IntLiteral(0); |
997 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
998 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
999 |
|
{ |
1000 |
|
PARSE_ERR(@2, "Operands of relative operations must have same unit."); |
1001 |
|
$$ = new IntLiteral(0); |
1002 |
|
} else { |
1003 |
|
$$ = new Relation(lhs, Relation::NOT_EQUAL, rhs); |
1004 |
|
} |
1005 |
} |
} |
1006 |
|
|
1007 |
add_expr: |
add_expr: |
1015 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
1016 |
PARSE_ERR(@3, (String("Right operand of operator '+' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '+' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
1017 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
1018 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
1019 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
1020 |
|
{ |
1021 |
|
PARSE_ERR(@2, "Operands of '+' operations must have same unit."); |
1022 |
|
$$ = new IntLiteral(0); |
1023 |
} else { |
} else { |
1024 |
$$ = new Add(lhs,rhs); |
$$ = new Add(lhs,rhs); |
1025 |
} |
} |
1033 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
1034 |
PARSE_ERR(@3, (String("Right operand of operator '-' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '-' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
1035 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
1036 |
|
} else if (lhs->asInt()->unitType() != rhs->asInt()->unitType() || |
1037 |
|
lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor()) |
1038 |
|
{ |
1039 |
|
PARSE_ERR(@2, "Operands of '-' operations must have same unit."); |
1040 |
|
$$ = new IntLiteral(0); |
1041 |
} else { |
} else { |
1042 |
$$ = new Sub(lhs,rhs); |
$$ = new Sub(lhs,rhs); |
1043 |
} |
} |
1054 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
1055 |
PARSE_ERR(@3, (String("Right operand of operator '*' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '*' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
1056 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
1057 |
|
} else if (lhs->asInt()->unitType() && rhs->asInt()->unitType()) { |
1058 |
|
PARSE_ERR(@2, "Only one operand of operator '*' may have a unit type"); |
1059 |
|
$$ = new IntLiteral(0); |
1060 |
|
} else if (lhs->asInt()->unitPrefix(0) && rhs->asInt()->unitPrefix(0)) { |
1061 |
|
PARSE_ERR(@2, "Only one operand of operator '*' may have a unit prefix"); |
1062 |
|
$$ = new IntLiteral(0); |
1063 |
} else { |
} else { |
1064 |
$$ = new Mul(lhs,rhs); |
$$ = new Mul(lhs,rhs); |
1065 |
} |
} |
1073 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
1074 |
PARSE_ERR(@3, (String("Right operand of operator '/' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '/' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
1075 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
1076 |
|
} else if (lhs->asInt()->unitType() && rhs->asInt()->unitType() && |
1077 |
|
lhs->asInt()->unitType() != rhs->asInt()->unitType()) |
1078 |
|
{ |
1079 |
|
PARSE_ERR(@2, "Operands of operator '/' with two different unit types."); |
1080 |
|
$$ = new IntLiteral(0); |
1081 |
|
} else if (!lhs->asInt()->unitType() && rhs->asInt()->unitType()) { |
1082 |
|
PARSE_ERR(@3, ("Dividing left operand without any unit type by right operand with unit type " + typeStr(rhs->exprType()) + " is not possible.").c_str()); |
1083 |
|
$$ = new IntLiteral(0); |
1084 |
|
} else if (lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor() && |
1085 |
|
lhs->asInt()->unitPrefix(0) && rhs->asInt()->unitPrefix(0)) |
1086 |
|
{ |
1087 |
|
PARSE_ERR(@2, "Dividing two operands with two different unit prefixes is not possible."); |
1088 |
|
$$ = new IntLiteral(0); |
1089 |
|
} else if (lhs->asInt()->unitFactor() != rhs->asInt()->unitFactor() && |
1090 |
|
rhs->asInt()->unitPrefix(0)) |
1091 |
|
{ |
1092 |
|
PARSE_ERR(@3, "Dividing left operand without any unit prefix by right operand with unit prefix is not possible."); |
1093 |
|
$$ = new IntLiteral(0); |
1094 |
} else { |
} else { |
1095 |
$$ = new Div(lhs,rhs); |
$$ = new Div(lhs,rhs); |
1096 |
} |
} |
1105 |
PARSE_ERR(@3, (String("Right operand of modulo operator must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of modulo operator must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
1106 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
1107 |
} else { |
} else { |
1108 |
|
if (lhs->asInt()->unitType() || lhs->asInt()->unitPrefix(0)) |
1109 |
|
PARSE_ERR(@1, "Operands of modulo operator must not use any unit."); |
1110 |
|
if (rhs->asInt()->unitType() || rhs->asInt()->unitPrefix(0)) |
1111 |
|
PARSE_ERR(@3, "Operands of modulo operator must not use any unit."); |
1112 |
$$ = new Mod(lhs,rhs); |
$$ = new Mod(lhs,rhs); |
1113 |
} |
} |
1114 |
} |
} |