pikasTech/PikaPython

Loop problems

Closed this issue · 5 comments

With my referenced project

>>> for i in range(0, 10):
... print(i)
[error] print: can not print val
   REF i                (#56)
 -> RUN print           (#63)

And while loops hang up completely

>>> i = 0
>>> i
0
>>> while i != 10:
... i +=1

<hangs>

When okay that might have been due to missing spaces in the second line, but with them I just get syntax error.

>>> for i in range(0, 10):
...    print(i)
... 
[error]: Syntax error.

When okay that might have been due to missing spaces in the second line, but with them I just get syntax error.

>>> for i in range(0, 10):
...    print(i)
... 
[error]: Syntax error.

Only support 4 spaces

Now more error info is supplied.

516a57d#diff-8a8892e40c9d3ed8524d468438e837a6e35dd628a3f9e560fb92f7651987a4b0R968

With my referenced project

>>> for i in range(0, 10):
... print(i)
[error] print: can not print val
   REF i                (#56)
 -> RUN print           (#63)

And while loops hang up completely

>>> i = 0
>>> i
0
>>> while i != 10:
... i +=1

<hangs>
Python 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> while a >0:
... 
  File "<stdin>", line 2
    
    ^
IndentationError: expected an indented block after 'while' statement on line 1

No space is also wrong in CPython. The robustness of PikaScript is not good enough for wrong input, so checking it in CPython first may be helpful.

Indeed you're right, the 4 spaces is really important.

>>> for i in range(0,10):
...     print(i)
...
0
1
2
3
4
5
6
7
8
9
>>> i = 0
>>> while i != 10:
...     i += 1
...
>>> i
10

But maybe throwing an IndentationError would be better.

Also things that would be syntax errors are not marked as one but just execute

>>> while i != 10
>>> 

vs

>>> while i != 10
  File "<stdin>", line 1
    while i != 10
                ^
SyntaxError: invalid syntax

But anyways this error was on my side.

Indeed you're right, the 4 spaces is really important.

>>> for i in range(0,10):
...     print(i)
...
0
1
2
3
4
5
6
7
8
9
>>> i = 0
>>> while i != 10:
...     i += 1
...
>>> i
10

But maybe throwing an IndentationError would be better.

Also things that would be syntax errors are not marked as one but just execute

>>> while i != 10
>>> 

vs

>>> while i != 10
  File "<stdin>", line 1
    while i != 10
                ^
SyntaxError: invalid syntax

But anyways this error was on my side.

It's true that the error checker is need enhancement.