Compare commits

...

2 Commits

Author SHA1 Message Date
iko
ad74107a2c
Added somw loops 2024-05-18 14:33:40 +03:00
iko
4ed8acbbb1
break and goto 2024-05-18 13:33:29 +03:00
3 changed files with 72 additions and 0 deletions

View File

@ -3,3 +3,4 @@
- [ ] functioncall
- [ ] any string apart from the basic string with no escapes
- [ ] check if int fits in int or make it a float
- [ ] strip out comments before parsing

View File

@ -465,7 +465,11 @@
[%blok blok]
[%asmnt varlist exprlist]
[%label label]
[%goto label]
[%func-call functioncall]
[%while cond=expr body=blok]
[%repeat body=blok cond=expr]
[%break ~]
[%empty ~]
==
++ parse-stat
@ -474,6 +478,34 @@
;~ pose
(cold [%empty ~] (just ';'))
::
(cold [%break ~] (jest 'break'))
::
%+ cook
|= [* cond=expr * body=blok *] [%while cond body]
;~ (glue wss)
(jest 'while')
parse-expr
(jest 'do')
parse-blok
(jest 'end')
==
::
%+ cook
|= [* body=blok * cond=expr] [%repeat body cond]
;~ (glue wss)
(jest 'repeat')
parse-blok
(jest 'until')
parse-expr
==
::
%+ cook
|= [* =label] [%goto label]
;~ (glue ws)
(jest 'goto')
parse-name
==
::
%+ cook
|= =label [%label label]
parse-label
@ -513,6 +545,29 @@
==
%label (print-label +.stat)
%func-call (print-functioncall +.stat)
%break "break"
%goto
%- zing
:~
"goto "
(trip +.stat)
==
%while
%- zing
:~
"while "
(print-expr cond.stat)
" do\0a"
(print-blok body.stat)
==
%repeat
%- zing
:~
"repeat\0a"
(print-blok body.stat)
"until "
(print-expr cond.stat)
==
==
:: functioncall
::

View File

@ -55,3 +55,19 @@ print('the way of the future')
print 'hello'
h{key1 = 'Sonmi~451'}
goto helli
break
while true do
break
end
repeat
do
foo = 9
;
end
until true