AttributeError: 'module' object has no attribute 'Parser'
AttributeError: 'module' object has no attribute 'Parser'
这是我的 final.py 文件。
#!/usr/bin/python
import sys
import os
sys.path.insert(0, './src/')
import lexRule
import parser
import ply.lex as lex
import ply.yacc as yacc
import node_file
import genAssembly as ga
import getopt
import pydot
def main(argv):
to_parse = ''
try:
opts, args = getopt.getopt(argv,"o:f:h",["opt=","file=","help"])
except getopt.GetoptError:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
parse = parser.Parser()
optjump = 0
for opt, arg in opts:
if opt in ("-o", "--opt"):
if arg == "1":
optjump = 1
elif opt in ("-f", "--file"):
tree = parse.parse_file(file(arg))
t = parser.tac.code
q = []
if optjump == 1:
for x in range(0,len(t)-1):
if t[x][0] == "goto" and t[x+1][3] == t[x][3]:
q.append(x)
for qw in reversed(q):
del t[qw]
parser.tac.code = t
old_target = sys.stdout
ga.generate()
sys.stdout = open('output.s', 'w')
ga.generate()
sys.stdout = old_target
print("Run ./a.out for execution")
# os.system("nasm -f elf32 inout.s")
# os.system("nasm -f elf32 fileio.s")
os.system("nasm -f elf32 output.s")
# os.system("nasm -f elf32 val1.s")
# os.system("nasm -f elf32 next1.s")
# os.system("nasm -f elf32 append2.s")
os.system("gcc -m32 output.o ./bin/inout.o ./bin/fileio.o ./bin/val1.o ./bin/next1.o ./bin/append2.o")
elif opt in ("-h", "--help"):
_file = open("./README.txt")
content = _file.read()
print(content)
else:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
if not opts:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
if __name__ == "__main__":
main(sys.argv[1:])
当我 运行 它在 cmd 上时,这是我得到的错误。error
我正在使用 python2 和 运行ning 这些命令:
python bin/final.py -f test/ackermann.java
python bin/final.py -o 1 -f test/ackermann.java
我正在尝试 运行 的项目是:https://github.com/abhigarg-iitk/java_compiler
由于您正在使用自己的解析器模块(与标准库同名)位于标准库包之外的其他位置,因此您需要使用 from ... import ...
语法和 __init.py__
文件在你的解析器包目录中。
如需进一步阅读,您可以在 https://docs.python.org/3/reference/import.html
查看 python 文档
这是我的 final.py 文件。
#!/usr/bin/python
import sys
import os
sys.path.insert(0, './src/')
import lexRule
import parser
import ply.lex as lex
import ply.yacc as yacc
import node_file
import genAssembly as ga
import getopt
import pydot
def main(argv):
to_parse = ''
try:
opts, args = getopt.getopt(argv,"o:f:h",["opt=","file=","help"])
except getopt.GetoptError:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
parse = parser.Parser()
optjump = 0
for opt, arg in opts:
if opt in ("-o", "--opt"):
if arg == "1":
optjump = 1
elif opt in ("-f", "--file"):
tree = parse.parse_file(file(arg))
t = parser.tac.code
q = []
if optjump == 1:
for x in range(0,len(t)-1):
if t[x][0] == "goto" and t[x+1][3] == t[x][3]:
q.append(x)
for qw in reversed(q):
del t[qw]
parser.tac.code = t
old_target = sys.stdout
ga.generate()
sys.stdout = open('output.s', 'w')
ga.generate()
sys.stdout = old_target
print("Run ./a.out for execution")
# os.system("nasm -f elf32 inout.s")
# os.system("nasm -f elf32 fileio.s")
os.system("nasm -f elf32 output.s")
# os.system("nasm -f elf32 val1.s")
# os.system("nasm -f elf32 next1.s")
# os.system("nasm -f elf32 append2.s")
os.system("gcc -m32 output.o ./bin/inout.o ./bin/fileio.o ./bin/val1.o ./bin/next1.o ./bin/append2.o")
elif opt in ("-h", "--help"):
_file = open("./README.txt")
content = _file.read()
print(content)
else:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
if not opts:
print 'Usage : ./bin/final.py [options][-f/-h/-o] [string]'
sys.exit(2)
if __name__ == "__main__":
main(sys.argv[1:])
当我 运行 它在 cmd 上时,这是我得到的错误。error 我正在使用 python2 和 运行ning 这些命令: python bin/final.py -f test/ackermann.java python bin/final.py -o 1 -f test/ackermann.java 我正在尝试 运行 的项目是:https://github.com/abhigarg-iitk/java_compiler
由于您正在使用自己的解析器模块(与标准库同名)位于标准库包之外的其他位置,因此您需要使用 from ... import ...
语法和 __init.py__
文件在你的解析器包目录中。
如需进一步阅读,您可以在 https://docs.python.org/3/reference/import.html
查看 python 文档