Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.53 KB | None | 0 0
  1. class StatementNode {
  2.     enum Kind {
  3.         case IFELSE, FOR, WHILE, BLOCK
  4.     }
  5.    
  6.     var text: String
  7.     var kind: Kind
  8.     var position:(col: Int, row: Int)
  9.    
  10.     init(_ position: (Int, Int),_ kind: Kind,_ text: String) {
  11.         self.text = text
  12.         self.position = position
  13.         self.kind = kind
  14.     }
  15. }
  16.  
  17. class DeclType {
  18.     enum declType {
  19.         case VAR, TYPE, CONST
  20.     }
  21.     var type: declType
  22.     var text: String
  23.     var position:(col: Int, row: Int)
  24.     init(_ position: (Int, Int),_ text: String, _ type:declType) {
  25.         self.type = type
  26.         self.text = text
  27.         self.position = position
  28.     }
  29. }
  30.  
  31. class VarType: DeclType {
  32.     init(_ position: (Int, Int), _ text: String) {
  33.         super.init(position, text, .VAR)
  34.     }
  35. }
  36.  
  37. class DeclarationScope {
  38.     var declList = [String: DeclType]()
  39. }
  40.  
  41. class Block: StatementNode {
  42.     var declScope: DeclarationScope?
  43.     var stmtList = [StatementNode]()
  44.     init(_ position: (Int, Int),_ text: String,_ declaration:DeclarationScope? = nil) {
  45.         self.declScope = declaration
  46.         super.init(position, .BLOCK, text)
  47.     }
  48. }
  49.  
  50. class IFElseStmt: StatementNode {
  51.     var condition: Expression
  52.     var block: StatementNode
  53.     var elseBlock: StatementNode?
  54.     init(_ position: (Int, Int),_ text: String,_ cond: Expression,_ block: StatementNode,_ elseBlock:StatementNode? = nil) {
  55.         self.condition = cond
  56.         self.block = block
  57.         self.elseBlock = elseBlock
  58.         super.init(position, .IFELSE, text)
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement