MarpaX-Languages-Lua-Parser

 view release on metacpan or  search on metacpan

lua.output/fibfor.txt  view on Meta::CPAN

keyword return
return
optional explist
explist
exp
exp
var
prefixexp
var
Name
coroutine
.
Name
wrap
args
(
optional explist
explist
exp
function
keyword function

lua.output/fibfor.txt  view on Meta::CPAN

chunk
stat list
stat list
stat
functioncall
prefixexp
var
prefixexp
var
Name
coroutine
.
Name
yield
args
(
optional explist
explist
exp
var
Name

lua.output/sieve.txt  view on Meta::CPAN

keyword return
return
optional explist
explist
exp
exp
var
prefixexp
var
Name
coroutine
.
Name
wrap
args
(
optional explist
explist
exp
function
keyword function

lua.output/sieve.txt  view on Meta::CPAN

block
chunk
stat list
stat
functioncall
prefixexp
var
prefixexp
var
Name
coroutine
.
Name
yield
args
(
optional explist
explist
exp
var
Name

lua.output/sieve.txt  view on Meta::CPAN

keyword return
return
optional explist
explist
exp
exp
var
prefixexp
var
Name
coroutine
.
Name
wrap
args
(
optional explist
explist
exp
function
keyword function

lua.output/sieve.txt  view on Meta::CPAN

block
chunk
stat list
stat
functioncall
prefixexp
var
prefixexp
var
Name
coroutine
.
Name
yield
args
(
optional explist
explist
exp
var
Name

lua.sources/fibfor.lua  view on Meta::CPAN

-- example of for with generator functions

function generatefib (n)
  return coroutine.wrap(function ()
    local a,b = 1, 1
    while a <= n do
      coroutine.yield(a)
      a, b = b, a+b
    end
  end)
end

for i in generatefib(1000) do print(i) end

lua.sources/sieve.lua  view on Meta::CPAN

-- the sieve of of Eratosthenes programmed with coroutines
-- typical usage: lua -e N=1000 sieve.lua | column

-- generate all the numbers from 2 to n
function gen (n)
  return coroutine.wrap(function ()
    for i=2,n do coroutine.yield(i) end
  end)
end

-- filter the numbers generated by `g', removing multiples of `p'
function filter (p, g)
  return coroutine.wrap(function ()
    while 1 do
      local n = g()
      if n == nil then return end
      if math.mod(n, p) ~= 0 then coroutine.yield(n) end
    end
  end)
end

N=N or 1000		-- from command line
x = gen(N)		-- generate primes up to N
while 1 do
  local n = x()		-- pick a number until done
  if n == nil then break end
  print(n)		-- must be a prime number



( run in 0.330 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )