예제 #1
0
	def insert(self, variable, value, env_list):
		"""
		Inserts a new variable with the specified value
		into the specified environment.

		Parameters:
			variable -- A VARIABLE type Lexeme object with the variable's
						name as its value.

			value 	 -- A NUMBER, BOOLEAN, or STRING type Lexeme object
						with the variable's value as its value.

			env_list -- The Environment list into which to insert
						the variable.
		"""
		if self._debug: print(
			"Inserting variable [" + str(variable) + "]")
		if self._debug: print(
			"        with value [" + str(value) + "].")

		var_glue = Lexeme(token_type="GLUE", left=variable)
		val_glue = Lexeme(token_type="GLUE", left=value)

		head = env_list.left
		var_glue.right = head.left
		val_glue.right = head.right
		head.left = var_glue
		head.right = val_glue
예제 #2
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def booleanExpression(self):
		tree = Lexeme(token_type="BOOLEAN_EXPRESSION")
		tmp = Lexeme(token_type="GLUE")
		tmp.left = self.expression()
		self.match("IS")
		tree.left = self.boolOp()
		tmp.right = self.expression()
		tree.right = tmp

		return tree
예제 #3
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def ifStatement(self):
		if self._debug: print(" in ifStatement")
		self.match("IF")
		tree = Lexeme(token_type="IF_STATEMENT")
		tmp = Lexeme(token_type="GLUE")
		tree.left = self.booleanExpression()
		self.match("COMMA")
		tmp.left = self.block()
		tmp.right = self.optOtherwise()
		tree.right = tmp

		return tree
예제 #4
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def statements(self):
		if self._debug: print(" in statements")
		tree = Lexeme(token_type="STATEMENTS")
		tree.left = self.statement()
		tree.right = self.optStatements()

		return tree
예제 #5
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def commaChain(self):
		if self._debug: print(" in commaChain")
		self.match("COMMA")
		tree = Lexeme(token_type="GLUE")
		tree.left = self.expression()
		tree.right = self.optCommaChain()

		return tree
예제 #6
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def whileStatement(self):
		if self._debug: print(" in whileStatement")
		self.match("WHILE")
		tree = Lexeme(token_type="WHILE_STATEMENT")
		tree.left = self.booleanExpression()
		self.match("COMMA")
		tree.right = self.block()

		return tree
예제 #7
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def assignment(self):
		if self._debug: print(" in assignment")
		self.match("SET")
		tree = Lexeme(token_type="ASSIGNMENT")
		tree.left = self.match("VARIABLE")
		self.match("TO")
		tree.right = self.expression()
		self.match("PERIOD")

		return tree
예제 #8
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def sequence(self):
		if self._debug: print(" in sequence")
		tree = Lexeme(token_type="GLUE")  # this will be attached to the "head" in my environment
		tree.left = self.expression()
		if self.check("AND"):
			self.match("AND")
			tmp = Lexeme(token_type="GLUE")
			tmp.left = self.expression()
			tree.right = tmp
		elif self.commaChainPending():
			tmp = self.commaChain()
			self.match("AND")
			tracer = tmp
			while tracer.right:
				tracer = tracer.right
			tracer.left = self.expression()
			tree.right = tmp

		return tree
예제 #9
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def optCommaChain(self):
		if self._debug: print(" in optCommaChain")
		tree = None
		if self.check("COMMA"):
			tree = Lexeme(token_type="GLUE")
			self.match("COMMA")
			if self.expressionPending():
				tree.left = self.expression()
				tree.right = self.optCommaChain()

		return tree
예제 #10
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def sequence(self):
		if self._debug: print(" in sequence")
		tree = Lexeme(token_type="LIST")
		tree.left = self.expression()
		if self.check("AND"):
			self.match("AND")
			tmp = Lexeme(token_type="GLUE")
			tmp.left = self.expression()
			tree.right = tmp
		elif self.commaChainPending():
			tmp = self.commaChain()
			self.match("AND")
			tracer = tmp
			while tracer.right:
				tracer = tracer.right
			tmp2 = Lexeme(token_type="GLUE")
			tmp2.left = self.expression()
			tracer.right = tmp2
			tree.right = tmp

		return tree
예제 #11
0
파일: parser.py 프로젝트: wtodom/2013-fall
	def program(self):
		if self._debug: print(" in program")
		tree = Lexeme(token_type="PROGRAM")
		sections = []
		while self.functionDefPending() or self.statementsPending():
			if self.functionDefPending():
				sections.append(self.functionDef())
			if self.statementsPending():
				sections.append(self.statements())
		self.match("EOF")
		tmp = Lexeme(token_type="GLUE")
		tracer = tmp
		for section in sections:
			tracer.left = section
			tracer.right = Lexeme(token_type="GLUE")
			tracer = tracer.right
		tree.right = tmp

		return tree