Browse Source

Throw a parsing error when attempting to use anything but a +, * or - as a unary operator

constants
Tristan B. V. Kildaire 10 months ago
parent
commit
cc2cdf2c30
  1. 17
      source/tlang/compiler/parsing/core.d

17
source/tlang/compiler/parsing/core.d

@ -904,10 +904,19 @@ public final class Parser
/* Check if unary or not (if so no expressions on stack) */
if(!hasExp())
{
Expression rhs = parseExpression();
/* Create UnaryExpression */
opExp = new UnaryOperatorExpression(operatorType, rhs);
/* Only `*`, `+` and `-` are valid */
if(operatorType == SymbolType.STAR || operatorType == SymbolType.ADD || operatorType == SymbolType.SUB)
{
/* Parse the expression following the unary operator */
Expression rhs = parseExpression();
/* Create UnaryExpression comprised of the operator and the right-hand side expression */
opExp = new UnaryOperatorExpression(operatorType, rhs);
}
else
{
expect("Expected *, + or - as unary operators but got "~to!(string)(operatorType));
}
}
/* If has, then binary */
else

Loading…
Cancel
Save