Python Forum

Full Version: Syntax checker
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to make a syntax checker. The way it should work:
The input is a text file which contains lines of codes (eg.:for i in range(5):print(i)). The program checks them, then decides whether it's syntactically correct or not. I require some help with this task. It's all new for me.
Start coding the task using the skills you have learned so far, when you get stuck on a particular part, post code in code tags and explain what you think should be happening and what is actually happening, also post any errors in error tags.
I simply don't know how to make it. I have the basics but this is a task I need to do as soon as possible, even though nothing like this was explained to us in class.
You can use the py_compile module. python -m py_compile myfile.py

https://docs.python.org/3/library/py_compile.html
I solved it with the ast module but Thank you I will check it out.