Skip to content
Snippets Groups Projects
Commit 3b5eed03 authored by Xun Yang's avatar Xun Yang
Browse files

some more node changes

parent c62c25f3
No related branches found
No related tags found
No related merge requests found
from AST import ASTNode, getParseTreeNodes, getTypeName
from Environment import Env
from WordNodes import ExprNode
from WordNodes import makeNodeFromExpr
# containing line level nodes: block, for/while/if, declaration
......
from AST import ASTNode, getParseTreeNodes, getTypeName
from LineNodes import BlockNode
from WordNodes import ExprNode
from WordNodes import makeNodeFromExpr
from Environment import Env
from collections import OrderedDict
......@@ -33,7 +33,7 @@ class FieldNode(ASTNode):
nameNodes = getParseTreeNodes(['variableInit'], node)
for n in nameNodes:
self.fieldInit = ExprNode(n)
self.fieldInit = makeNodeFromExpr(n)
if self.fieldInit: self.children.append(self.fieldInit)
......
from AST import ASTNode, getParseTreeNodes, getTypeName
from Environment import Env
# literals
class LiteralNode(ASTNode):
toLiType = dict({
'LITERALBOOL': 'bool',
'LITERALCHAR': 'char',
'LITERALSTRING': 'String',
'NULL': 'null',
'NUM': 'int',
'ZERO': 'int'
})
# always list all fields in the init method to show the class structure
def __init__(self, parseTree):
self.parseTree = parseTree
self.liType = toLiType.get(parseTree.children[0].name) # type of the literal
self.value = parseTree.children[0].lex # the value
self.env = None
self.children = []
if self.liType == 'int':
self.value = int(self.value)
if self.liType == 'LITERALBOOL':
if self.value == 'false':
self.value = False
else:
self.value = True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment