Skip to content

Instantly share code, notes, and snippets.

@mbk
Created July 1, 2020 14:54
Show Gist options
  • Save mbk/c176964b055cded7fb4c9b17e93398cd to your computer and use it in GitHub Desktop.
Save mbk/c176964b055cded7fb4c9b17e93398cd to your computer and use it in GitHub Desktop.
so far, in lua red
;orginal
;function: [ function ws* funcbody ws* ]
;funcbody: [ #"(" opt parlist #")" ws* block ws* "end" ]
function: [ "function" ws* name #"(" opt parlist #")" ws
varlist #"=" explist ws*
ws* functioncall ws*
ws* "do" ws* functioncall ws* "end" ws*
ws* "while" ws* exp ws* "do" ws* functioncall ws* "end" ws*
ws* "repeat" ws* functioncall ws* "until" ws* exp ws*
ws* "if" ws* exp ws* "then" ws* functioncall ws* ; any ["elseif" ws* exp ws* "then" ws* functioncall ws* ] ; opt ["else" ws* functioncall ws*] end ws*
;ws* "for" ws* name ws* #"=" ws* exp ws* any [#"," ws* exp ws*] "do" ws* block ws* "end" ws* |
;ws* "for" ws* namelist ws* "in" ws* explist ws* "do" ws* block ws* "end" ws* |
;ws* "function" funcname funcbody ws* |
;ws* "local" ws* "function" ws* name funcbody ws* |
;ws* "local" namelist opt [#"=" explist]]
ws* "end" ws*]
;funcbody ws* ]
With this input:
function f(n)
x = 1
g(1)
do h(3) end
while true do g(2) end
repeat f(1) until true
if true then h(4)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment