change Node to nodes module; use a class hierarchy for node types

This commit is contained in:
Josh Holtrop 2011-08-30 10:58:36 -04:00
parent 0b33cc7401
commit b8e617bd39
3 changed files with 20 additions and 10 deletions

View File

@ -1,7 +0,0 @@
class Node(object):
def __init__(self, type, children=None, node=None, data=None):
self.type = type
self.children = children
self.node = node
self.data = data

17
parser/nodes.py Normal file
View File

@ -0,0 +1,17 @@
class Node(object):
def __init__(self, children=None):
self.children = children
class StatementNode(Node):
def __init__(self, children=None):
Node.__init__(self, children)
class ExprNode(Node):
def __init__(self, children=None):
Node.__init__(self, children)
class CExprNode(ExprNode):
def __init__(self, cstring):
ExprNode.__init__(self)
self.cstring = cstring

View File

@ -1,10 +1,10 @@
from lexrules import tokens
from Node import Node
from nodes import *
def p_statement(p):
'statement : expr SEMICOLON'
p[0] = Node('statement', [p[1]])
p[0] = StatementNode([p[1]])
def p_expr(p):
'expr : c_expr'
@ -12,4 +12,4 @@ def p_expr(p):
def p_c_expr(p):
'c_expr : C LPAREN STRING RPAREN'
p[0] = Node('c_expr', data=p[3])
p[0] = CExprNode(p[3])