Browse Source

add in some node types

master
Brett Langdon 10 years ago
parent
commit
2168bbf7cd
7 changed files with 91 additions and 1 deletions
  1. +13
    -0
      ast/base.go
  2. +13
    -0
      ast/compoundstatement.go
  3. +13
    -0
      ast/expressionstatement.go
  4. +0
    -1
      ast/node.go
  5. +18
    -0
      ast/simplestatement.go
  6. +16
    -0
      ast/smallstatement.go
  7. +18
    -0
      ast/statement.go

+ 13
- 0
ast/base.go View File

@ -0,0 +1,13 @@
package ast
type BaseNode struct {
ID NodeID
}
func (node *BaseNode) initBaseNode(id NodeID) {
node.ID = id
}
func (node *BaseNode) Name() string {
return NodeNames[node.ID]
}

+ 13
- 0
ast/compoundstatement.go View File

@ -0,0 +1,13 @@
package ast
type CompoundStatement struct {
Statement
}
func NewCompoundStatement() *CompoundStatement {
node := &CompoundStatement{}
node.initBaseNode(SIMPLE_STMT)
return node
}
func (node *CompoundStatement) StatementNode() {}

+ 13
- 0
ast/expressionstatement.go View File

@ -0,0 +1,13 @@
package ast
type ExpressionStatement struct {
BaseNode
}
func NewExpressionStatement() *ExpressionStatement {
node := &ExpressionStatement{}
node.initBaseNode(EXPR_STMT)
return node
}
func (node *ExpressionStatement) SmallStatementNode() {}

+ 0
- 1
ast/node.go View File

@ -1,6 +1,5 @@
package ast
type Node interface {
ID() NodeID
Name() string
}

+ 18
- 0
ast/simplestatement.go View File

@ -0,0 +1,18 @@
package ast
type SimpleStatement struct {
BaseNode
Statements []*SmallStatement
}
func NewSimpleStatement() *SimpleStatement {
node := &SimpleStatement{}
node.initBaseNode(SIMPLE_STMT)
return node
}
func (node *SimpleStatement) StatementNode() {}
func (node *SimpleStatement) AppendSmallStatement(n *SmallStatement) {
node.Statements = append(node.Statements, n)
}

+ 16
- 0
ast/smallstatement.go View File

@ -0,0 +1,16 @@
package ast
type SmallStatementNode interface {
SmallStatementNode()
}
type SmallStatement struct {
BaseNode
Statement SmallStatementNode
}
func NewSmallStatement() *SmallStatement {
node := &SmallStatement{}
node.initBaseNode(SMALL_STMT)
return node
}

+ 18
- 0
ast/statement.go View File

@ -0,0 +1,18 @@
package ast
type StatementNode interface {
StatementNode()
}
type Statement struct {
BaseNode
Statement StatementNode
}
func NewStatement() *Statement {
node := &Statement{}
node.initBaseNode(STMT)
return node
}
func (node *Statement) StatementNode() {}

Loading…
Cancel
Save