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

fix little stuff in Literal Node

parent 014420b3
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ class ASTNode():
pass
def checkType(self):
# self is type correct if all its children are type correct (no exception raised)
for c in self.children:
if c and hasattr(c, 'checkType'):
c.checkType()
......
......@@ -10,9 +10,9 @@ from TheTypeNode import TypeNode
# literals
class LiteralNode(ASTNode):
toLiType = dict({
'LITERALBOOL': 'bool',
'LITERALBOOL': 'boolean',
'LITERALCHAR': 'char',
'LITERALSTRING': 'String',
'LITERALSTRING': 'java.lang.String',
'NULL': 'null',
'NUM': 'int',
'ZERO': 'int'
......@@ -20,14 +20,14 @@ class LiteralNode(ASTNode):
# always list all fields in the init method to show the class structure
def __init__(self, parseTree):
self.parseTree = parseTree
self.liType = LiteralNode.toLiType.get(parseTree.children[0].name) # type of the literal
self.name = LiteralNode.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':
if self.name == 'int':
self.value = int(self.value)
if self.liType == 'LITERALBOOL':
if self.name == 'LITERALBOOL':
if self.value == 'false':
self.value = False
else:
......
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