mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
Add support for not equals (!=) infix operation.
This commit is contained in:
parent
0b3700667d
commit
95fe6e9abb
@ -2,12 +2,15 @@
|
||||
main = { in
|
||||
three = 3
|
||||
two = 2
|
||||
|
||||
calculateSimple = { in
|
||||
(50 + three) * two
|
||||
}
|
||||
|
||||
calculateComplex = { in
|
||||
three + two + 50
|
||||
}
|
||||
|
||||
multiply = { a, b in
|
||||
a * b
|
||||
}
|
||||
@ -25,6 +28,14 @@ main = { in
|
||||
!value
|
||||
}
|
||||
|
||||
notEqual = { a, b in
|
||||
a != b
|
||||
}
|
||||
|
||||
equal = { a, b in
|
||||
a == b
|
||||
}
|
||||
|
||||
[
|
||||
calculateSimpleResult,
|
||||
calculateComplexResult,
|
||||
@ -33,6 +44,10 @@ main = { in
|
||||
trueValue,
|
||||
falseValue,
|
||||
invert(true),
|
||||
invert(false)
|
||||
invert(false),
|
||||
equal(5, 5),
|
||||
equal(5, 6),
|
||||
notEqual(5, 5),
|
||||
notEqual(5, 6)
|
||||
]
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ enum class InfixOperator(val token: String) {
|
||||
Minus("-"),
|
||||
Multiply("*"),
|
||||
Divide("/"),
|
||||
Equals("==")
|
||||
Equals("=="),
|
||||
NotEquals("!=")
|
||||
}
|
||||
|
@ -81,6 +81,9 @@ class PorkEvaluator(root: Scope) : NodeVisitor<Any> {
|
||||
InfixOperator.Equals -> {
|
||||
return left == right
|
||||
}
|
||||
InfixOperator.NotEquals -> {
|
||||
return left != right
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,8 @@ class PorkParser(source: PeekableSource<Token>) {
|
||||
TokenType.Minus,
|
||||
TokenType.Multiply,
|
||||
TokenType.Divide,
|
||||
TokenType.Equality)) {
|
||||
TokenType.Equality,
|
||||
TokenType.Inequality)) {
|
||||
val infixToken = next()
|
||||
val infixOperator = convertInfixOperator(infixToken)
|
||||
return InfixOperation(expression, infixOperator, readExpression())
|
||||
@ -133,6 +134,7 @@ class PorkParser(source: PeekableSource<Token>) {
|
||||
TokenType.Multiply -> InfixOperator.Multiply
|
||||
TokenType.Divide -> InfixOperator.Divide
|
||||
TokenType.Equality -> InfixOperator.Equals
|
||||
TokenType.Inequality -> InfixOperator.NotEquals
|
||||
else -> throw RuntimeException("Unknown Infix Operator")
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
Symbol,
|
||||
IntLiteral,
|
||||
Equality,
|
||||
Inequality,
|
||||
Equals(SingleChar('='), Promotion('=', Equality)),
|
||||
Plus(SingleChar('+')),
|
||||
Minus(SingleChar('-')),
|
||||
@ -17,7 +18,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
RightBracket(SingleChar(']')),
|
||||
LeftParentheses(SingleChar('(')),
|
||||
RightParentheses(SingleChar(')')),
|
||||
Negation(SingleChar('!')),
|
||||
Negation(SingleChar('!'), Promotion('=', Inequality)),
|
||||
Comma(SingleChar(',')),
|
||||
False(Keyword("false")),
|
||||
True(Keyword("true")),
|
||||
|
Loading…
Reference in New Issue
Block a user