Skip to content

Commit

Permalink
Fix invalid operator operator use
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhEugene committed Oct 26, 2023
1 parent 03ad5f6 commit 92929d3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion infinity/code/modules/scripting/AST/AST Nodes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var
Class: operator
See <Binary Operators> and <Unary Operators> for subtypes.
*/
/node/expression/operator
/node/expression/c_operator
var
node/expression/exp
tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Class: binary
Represents a binary operator in the AST. A binary operator takes two operands (ie x and y) and returns a value.
*/
/node/expression/operator/binary
/node/expression/c_operator/binary
var/node/expression/exp2

////////// Comparison Operators //////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Class: unary
Represents a unary operator in the AST. Unary operators take a single operand (referred to as x below) and return a value.
*/
/node/expression/operator/unary
/node/expression/c_operator/unary
precedence=OOP_UNARY

/*
Expand Down
52 changes: 26 additions & 26 deletions infinity/code/modules/scripting/Interpreter/Evaluation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Eval(node/expression/exp)
if(istype(exp, /node/expression/FunctionCall))
return RunFunction(exp)
else if(istype(exp, /node/expression/operator))
else if(istype(exp, /node/expression/c_operator))
return EvalOperator(exp)
else if(istype(exp, /node/expression/value/literal))
var/node/expression/value/literal/lit=exp
Expand Down Expand Up @@ -36,57 +36,57 @@
else
return exp

EvalOperator(node/expression/operator/exp)
if(istype(exp, /node/expression/operator/binary))
var/node/expression/operator/binary/bin=exp
EvalOperator(node/expression/c_operator/exp)
if(istype(exp, /node/expression/c_operator/binary))
var/node/expression/c_operator/binary/bin=exp
switch(bin.type)
if(/node/expression/operator/binary/Equal)
if(/node/expression/c_operator/binary/Equal)
return Equal(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/NotEqual)
if(/node/expression/c_operator/binary/NotEqual)
return NotEqual(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Greater)
if(/node/expression/c_operator/binary/Greater)
return Greater(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Less)
if(/node/expression/c_operator/binary/Less)
return Less(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/GreaterOrEqual)
if(/node/expression/c_operator/binary/GreaterOrEqual)
return GreaterOrEqual(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/LessOrEqual)
if(/node/expression/c_operator/binary/LessOrEqual)
return LessOrEqual(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/LogicalAnd)
if(/node/expression/c_operator/binary/LogicalAnd)
return LogicalAnd(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/LogicalOr)
if(/node/expression/c_operator/binary/LogicalOr)
return LogicalOr(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/LogicalXor)
if(/node/expression/c_operator/binary/LogicalXor)
return LogicalXor(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/BitwiseAnd)
if(/node/expression/c_operator/binary/BitwiseAnd)
return BitwiseAnd(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/BitwiseOr)
if(/node/expression/c_operator/binary/BitwiseOr)
return BitwiseOr(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/BitwiseXor)
if(/node/expression/c_operator/binary/BitwiseXor)
return BitwiseXor(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Add)
if(/node/expression/c_operator/binary/Add)
return Add(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Subtract)
if(/node/expression/c_operator/binary/Subtract)
return Subtract(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Multiply)
if(/node/expression/c_operator/binary/Multiply)
return Multiply(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Divide)
if(/node/expression/c_operator/binary/Divide)
return Divide(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Power)
if(/node/expression/c_operator/binary/Power)
return Power(Eval(bin.exp), Eval(bin.exp2))
if(/node/expression/operator/binary/Modulo)
if(/node/expression/c_operator/binary/Modulo)
return Modulo(Eval(bin.exp), Eval(bin.exp2))
else
RaiseError(new/runtimeError/UnknownInstruction())
else
switch(exp.type)
if(/node/expression/operator/unary/Minus)
if(/node/expression/c_operator/unary/Minus)
return Minus(Eval(exp.exp))
if(/node/expression/operator/unary/LogicalNot)
if(/node/expression/c_operator/unary/LogicalNot)
return LogicalNot(Eval(exp.exp))
if(/node/expression/operator/unary/BitwiseNot)
if(/node/expression/c_operator/unary/BitwiseNot)
return BitwiseNot(Eval(exp.exp))
if(/node/expression/operator/unary/group)
if(/node/expression/c_operator/unary/group)
return Eval(exp.exp)
else
RaiseError(new/runtimeError/UnknownInstruction())
Expand Down
22 changes: 11 additions & 11 deletions infinity/code/modules/scripting/Options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ n_scriptOptions/nS_Options
"^=" = "^",
"%=" = "%")

var/list/unary_operators = list("!" = /node/expression/operator/unary/LogicalNot, "~" = /node/expression/operator/unary/BitwiseNot,
"-" = /node/expression/operator/unary/Minus)
var/list/unary_operators = list("!" = /node/expression/c_operator/unary/LogicalNot, "~" = /node/expression/c_operator/unary/BitwiseNot,
"-" = /node/expression/c_operator/unary/Minus)

var/list/binary_operators = list("==" = /node/expression/operator/binary/Equal, "!=" = /node/expression/operator/binary/NotEqual,
">" = /node/expression/operator/binary/Greater, "<" = /node/expression/operator/binary/Less,
">=" = /node/expression/operator/binary/GreaterOrEqual,"<=" = /node/expression/operator/binary/LessOrEqual,
"&&" = /node/expression/operator/binary/LogicalAnd, "||" = /node/expression/operator/binary/LogicalOr,
"&" = /node/expression/operator/binary/BitwiseAnd, "|" = /node/expression/operator/binary/BitwiseOr,
"`" = /node/expression/operator/binary/BitwiseXor, "+" = /node/expression/operator/binary/Add,
"-" = /node/expression/operator/binary/Subtract, "*" = /node/expression/operator/binary/Multiply,
"/" = /node/expression/operator/binary/Divide, "^" = /node/expression/operator/binary/Power,
"%" = /node/expression/operator/binary/Modulo)
var/list/binary_operators = list("==" = /node/expression/c_operator/binary/Equal, "!=" = /node/expression/c_operator/binary/NotEqual,
">" = /node/expression/c_operator/binary/Greater, "<" = /node/expression/c_operator/binary/Less,
">=" = /node/expression/c_operator/binary/GreaterOrEqual,"<=" = /node/expression/c_operator/binary/LessOrEqual,
"&&" = /node/expression/c_operator/binary/LogicalAnd, "||" = /node/expression/c_operator/binary/LogicalOr,
"&" = /node/expression/c_operator/binary/BitwiseAnd, "|" = /node/expression/c_operator/binary/BitwiseOr,
"`" = /node/expression/c_operator/binary/BitwiseXor, "+" = /node/expression/c_operator/binary/Add,
"-" = /node/expression/c_operator/binary/Subtract, "*" = /node/expression/c_operator/binary/Multiply,
"/" = /node/expression/c_operator/binary/Divide, "^" = /node/expression/c_operator/binary/Power,
"%" = /node/expression/c_operator/binary/Modulo)

/n_scriptOptions/nS_Options/New()
.=..()
Expand Down
18 changes: 9 additions & 9 deletions infinity/code/modules/scripting/Parser/Expressions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Proc: Precedence
Compares two operators, decides which is higher in the order of operations, and returns <SHIFT> or <REDUCE>.
*/
Precedence(node/expression/operator/top, node/expression/operator/input)
Precedence(node/expression/c_operator/top, node/expression/c_operator/input)
if(istype(top))
top=top.precedence
if(istype(input))
Expand Down Expand Up @@ -90,7 +90,7 @@
- <GetBinaryOperator()>
- <GetUnaryOperator()>
*/
GetOperator(O, type=/node/expression/operator, L[])
GetOperator(O, type=/node/expression/c_operator, L[])
if(istype(O, type)) return O //O is already the desired type
if(istype(O, /token)) O=O:value //sets O to text
if(istext(O)) //sets O to path
Expand All @@ -110,7 +110,7 @@
- <GetUnaryOperator()>
*/
GetBinaryOperator(O)
return GetOperator(O, /node/expression/operator/binary, options.binary_operators)
return GetOperator(O, /node/expression/c_operator/binary, options.binary_operators)

/*
Proc: GetUnaryOperator
Expand All @@ -122,23 +122,23 @@
- <GetBinaryOperator()>
*/
GetUnaryOperator(O)
return GetOperator(O, /node/expression/operator/unary, options.unary_operators)
return GetOperator(O, /node/expression/c_operator/unary, options.unary_operators)

/*
Proc: Reduce
Takes the operator on top of the opr stack and assigns its operand(s). Then this proc pushes the value of that operation to the top
of the val stack.
*/
Reduce(stack/opr, stack/val)
var/node/expression/operator/O=opr.Pop()
var/node/expression/c_operator/O=opr.Pop()
if(!O) return
if(!istype(O))
errors+=new/scriptError("Error reducing expression - invalid operator.")
return
//Take O and assign its operands, popping one or two values from the val stack
//depending on whether O is a binary or unary operator.
if(istype(O, /node/expression/operator/binary))
var/node/expression/operator/binary/B=O
if(istype(O, /node/expression/c_operator/binary))
var/node/expression/c_operator/binary/B=O
B.exp2=val.Pop()
B.exp =val.Pop()
val.Push(B)
Expand Down Expand Up @@ -205,7 +205,7 @@
continue
val.Push(ParseParenExpression())
else if(istype(curToken, /token/symbol)) //Operator found.
var/node/expression/operator/curOperator //Figure out whether it is unary or binary and get a new instance.
var/node/expression/c_operator/curOperator //Figure out whether it is unary or binary and get a new instance.
if(src.expecting==OPERATOR)
curOperator=GetBinaryOperator(curToken)
if(!curOperator)
Expand Down Expand Up @@ -299,7 +299,7 @@
ParseParenExpression()
if(!CheckToken("(", /token/symbol))
return
return new/node/expression/operator/unary/group(ParseExpression(list(")")))
return new/node/expression/c_operator/unary/group(ParseExpression(list(")")))

/*
Proc: ParseParamExpression
Expand Down

0 comments on commit 92929d3

Please sign in to comment.