Created
July 19, 2017 15:50
-
-
Save Varriount/14294ffa001805915dcc7463d698882a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an example how an abstract syntax tree could be modelled in Nim | |
type | |
NodeKind = enum # the different node types | |
nkInt, # a leaf with an integer value | |
nkFloat, # a leaf with a float value | |
nkString, # a leaf with a string value | |
nkAdd, # an addition | |
nkSub, # a subtraction | |
nkIf # an if statement | |
Node = ref NodeObj | |
NodeObj = object | |
nodeId: int | |
line, column: int | |
case kind: NodeKind | |
of nkInt: | |
intVal: int | |
of nkFloat: | |
floatVal: float | |
of nkString: | |
strVal: string | |
of nkAdd, nkSub: | |
leftOp, rightOp: Node | |
of nkIf: | |
condition, thenPart, elsePart: Node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment