当前位置: 首页>>代码示例>>Python>>正文


Python Parser.commandLines方法代码示例

本文整理汇总了Python中Parser.Parser.commandLines方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.commandLines方法的具体用法?Python Parser.commandLines怎么用?Python Parser.commandLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser.Parser的用法示例。


在下文中一共展示了Parser.commandLines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import commandLines [as 别名]
def main():
	"output file is the file where output will be written to"
	filename = sys.argv[1].split('.')[0]
	outputfile = open( filename + ".hack", "a" )

	"input file is the file where input will come from"
	inputfile = Parser( sys.argv[1] )

	lines = inputfile.commandLines()

	for line in lines:
		if( ParserComd( line ).commandType() == 'A_command' ):
			symbol_line = ParserComd( line ).symbol( )
			symbol_a = SymbolTable( )
			symbol_a.addEntry( symbol_line )
			f = symbol_a.GetAddress( symbol_line )
			outputfile.write( f )
			outputfile.write( '\n' )

		elif( ParserComd( line ).commandType() == 'C_command_a' or ParserComd( line ).commandType() == 'C_command_b'):
			dest_line = ParserComd( line ).dest()
			comp_line = ParserComd( line ).comp()
			jump_line = ParserComd( line ).jump()
			cbinary = Code( dest_line, comp_line, jump_line ).cinstruction()
			outputfile.write( cbinary )
			outputfile.write( '\n' )
		elif( ParserComd( line ).commandType() == 'L_command' ):
			outputfile.write( 'This line is going to delete\n' )

	outputfile.close()
开发者ID:chenzhengchen200821109,项目名称:github-nand2tetries,代码行数:32,代码来源:main.py

示例2: main

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import commandLines [as 别名]
def main():
	"output file setup"
	arg_length = len( sys.argv ) - 2
	if arg_length == 0:
		objectFileName = sys.argv[1].split('.')[0]
		filename = sys.argv[1]
		output = CodeWriter(objectFileName, filename)
		input = Parser( )
		commandlines = input.commandLines( filename )
		for line in commandlines:
			if input.typeCommand( line ) == 'C_ARITHMETIC':
				output.writeArithmetic( line )
				output.Write()
			elif input.typeCommand( line ) in [ 'C_PUSH', 'C_POP' ]:
				output.writePushPop( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_LABEL':
				output.writeLabel( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_GOTO':
				output.writeGoto( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_IFGOTO':
				output.writeIfGoTo( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_FUNCTION':
				#output.writeInit( line )
				output.writeFunction( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_RETURN':
				output.writeReturn( line )
				output.Write()
			elif input.typeCommand( line ) == 'C_CALL':
				output.writeCall( line )
				output.Write()
	else:
		count = 0
		objectFileName = sys.argv[-1]
		while count < arg_length:
			"input file setup"
			filename = sys.argv[ count + 1 ]
			output = CodeWriter(objectFileName, filename)
			input = Parser( )
			commandlines = input.commandLines( filename )
			for line in commandlines:
				if input.typeCommand( line ) == 'C_ARITHMETIC':
					output.writeArithmetic( line )
					output.Write()
				elif input.typeCommand( line ) in [ 'C_PUSH', 'C_POP' ]:
					output.writePushPop( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_LABEL':
					output.writeLabel( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_GOTO':
					output.writeGoto( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_IFGOTO':
					output.writeIfGoTo( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_FUNCTION':
					#output.writeInit( line )
					output.writeFunction( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_RETURN':
					output.writeReturn( line )
					output.Write()
				elif input.typeCommand( line ) == 'C_CALL':
					output.writeCall( line )
					output.Write()
			count += 1

	output.Close()
开发者ID:chenzhengchen200821109,项目名称:github-nand2tetries,代码行数:75,代码来源:main.py


注:本文中的Parser.Parser.commandLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。