mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
language: var, reassign, comparison operators
This commit is contained in:
@ -41,6 +41,20 @@ types:
|
||||
type: Symbol
|
||||
- name: value
|
||||
type: Expression
|
||||
VarAssignment:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: symbol
|
||||
type: Symbol
|
||||
- name: value
|
||||
type: Expression
|
||||
SetAssignment:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: symbol
|
||||
type: Symbol
|
||||
- name: value
|
||||
type: Expression
|
||||
InfixOperator:
|
||||
values:
|
||||
- name: token
|
||||
@ -70,6 +84,18 @@ types:
|
||||
- name: Remainder
|
||||
values:
|
||||
token: "rem"
|
||||
- name: Lesser
|
||||
values:
|
||||
token: "<"
|
||||
- name: Greater
|
||||
values:
|
||||
token: ">"
|
||||
- name: GreaterEqual
|
||||
values:
|
||||
token: ">="
|
||||
- name: LesserEqual
|
||||
values:
|
||||
token: "<="
|
||||
InfixOperation:
|
||||
parent: Expression
|
||||
values:
|
||||
|
@ -8,6 +8,8 @@ digraph A {
|
||||
type_Block [shape=box,label="Block"]
|
||||
type_CompilationUnit [shape=box,label="CompilationUnit"]
|
||||
type_LetAssignment [shape=box,label="LetAssignment"]
|
||||
type_VarAssignment [shape=box,label="VarAssignment"]
|
||||
type_SetAssignment [shape=box,label="SetAssignment"]
|
||||
type_InfixOperator [shape=box,label="InfixOperator"]
|
||||
type_InfixOperation [shape=box,label="InfixOperation"]
|
||||
type_BooleanLiteral [shape=box,label="BooleanLiteral"]
|
||||
@ -35,6 +37,8 @@ digraph A {
|
||||
type_Node -> type_CompilationUnit
|
||||
type_Node -> type_Native
|
||||
type_Expression -> type_LetAssignment
|
||||
type_Expression -> type_VarAssignment
|
||||
type_Expression -> type_SetAssignment
|
||||
type_Expression -> type_InfixOperation
|
||||
type_Expression -> type_BooleanLiteral
|
||||
type_Expression -> type_FunctionCall
|
||||
@ -58,6 +62,10 @@ digraph A {
|
||||
type_CompilationUnit -> type_Definition [style=dotted]
|
||||
type_LetAssignment -> type_Symbol [style=dotted]
|
||||
type_LetAssignment -> type_Expression [style=dotted]
|
||||
type_VarAssignment -> type_Symbol [style=dotted]
|
||||
type_VarAssignment -> type_Expression [style=dotted]
|
||||
type_SetAssignment -> type_Symbol [style=dotted]
|
||||
type_SetAssignment -> type_Expression [style=dotted]
|
||||
type_InfixOperation -> type_Expression [style=dotted]
|
||||
type_InfixOperation -> type_InfixOperator [style=dotted]
|
||||
type_FunctionCall -> type_Symbol [style=dotted]
|
||||
|
@ -14,5 +14,9 @@ enum class InfixOperator(val token: String) {
|
||||
Equals("=="),
|
||||
NotEquals("!="),
|
||||
EuclideanModulo("mod"),
|
||||
Remainder("rem")
|
||||
Remainder("rem"),
|
||||
Lesser("<"),
|
||||
Greater(">"),
|
||||
GreaterEqual(">="),
|
||||
LesserEqual("<=")
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitPrefixOperation(node: PrefixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSetAssignment(node: SetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitStringLiteral(node: StringLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
@ -62,6 +65,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitSymbolReference(node: SymbolReference): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitVarAssignment(node: VarAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitWhile(node: While): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -23,8 +23,10 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
Native(Node),
|
||||
Parentheses(Expression),
|
||||
PrefixOperation(Expression),
|
||||
SetAssignment(Expression),
|
||||
StringLiteral(Expression),
|
||||
Symbol(Node),
|
||||
SymbolReference(Expression),
|
||||
VarAssignment(Expression),
|
||||
While(Expression)
|
||||
}
|
||||
|
@ -36,11 +36,15 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitPrefixOperation(node: PrefixOperation): T
|
||||
|
||||
fun visitSetAssignment(node: SetAssignment): T
|
||||
|
||||
fun visitStringLiteral(node: StringLiteral): T
|
||||
|
||||
fun visitSymbol(node: Symbol): T
|
||||
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
|
||||
fun visitVarAssignment(node: VarAssignment): T
|
||||
|
||||
fun visitWhile(node: While): T
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is Block -> visitBlock(node)
|
||||
is CompilationUnit -> visitCompilationUnit(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is VarAssignment -> visitVarAssignment(node)
|
||||
is SetAssignment -> visitSetAssignment(node)
|
||||
is InfixOperation -> visitInfixOperation(node)
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
|
29
ast/src/main/kotlin/gay/pizza/pork/ast/SetAssignment.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/SetAssignment.kt
Normal file
@ -0,0 +1,29 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("setAssignment")
|
||||
class SetAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.SetAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSetAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is SetAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = symbol.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
29
ast/src/main/kotlin/gay/pizza/pork/ast/VarAssignment.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/VarAssignment.kt
Normal file
@ -0,0 +1,29 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("varAssignment")
|
||||
class VarAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.VarAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitVarAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is VarAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = symbol.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user