I'm trying to write a python parser, and in my opiniion it could parse an "if statement" but it doesn't. It shows me a "syntax error" message.
Can someone tell me what I'm doing wrong?
Thanks in advance.
The code is here: https://github.com/narke/py2neko
I modified the input string like this:
s = '''if 5:
print 10
else:
print 20 \n'''
check_syntax(s)
and the output is:
Syntax error at '5'
atom: 10
factor None
None
cmp: None None
atom: 20
factor None
None
cmp: None None
simple_stmt: None
From your code:
if 5:\n
is not valid syntax because it is not a completeif
statement. You need to provide a suite (code to execute) if the expression isTrue
. For example: