change Node to nodes module; use a class hierarchy for node types
This commit is contained in:
parent
0b33cc7401
commit
b8e617bd39
@ -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
17
parser/nodes.py
Normal 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
|
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
from lexrules import tokens
|
from lexrules import tokens
|
||||||
from Node import Node
|
from nodes import *
|
||||||
|
|
||||||
def p_statement(p):
|
def p_statement(p):
|
||||||
'statement : expr SEMICOLON'
|
'statement : expr SEMICOLON'
|
||||||
p[0] = Node('statement', [p[1]])
|
p[0] = StatementNode([p[1]])
|
||||||
|
|
||||||
def p_expr(p):
|
def p_expr(p):
|
||||||
'expr : c_expr'
|
'expr : c_expr'
|
||||||
@ -12,4 +12,4 @@ def p_expr(p):
|
|||||||
|
|
||||||
def p_c_expr(p):
|
def p_c_expr(p):
|
||||||
'c_expr : C LPAREN STRING RPAREN'
|
'c_expr : C LPAREN STRING RPAREN'
|
||||||
p[0] = Node('c_expr', data=p[3])
|
p[0] = CExprNode(p[3])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user