lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


What I means is that can we define a simple syntactic function as
`
variable#
`
and it will be mapped to a function doing something:
`
function test(variable)
for i =1, #variable do
...
end

end
`
Using the short notation is easy for user to do some specific loop operation.

-----原始邮件-----
发件人: "Xianfu Pan" <pxfgod@gmail.com>
发送时间: 2017年1月14日 星期六
收件人: "Lua mailing list" <lua-l@lists.lua.org>
抄送:
主题: Re: how to make an user defined grammar?

do you mean add a  syntax of the same semantic of for statement?
of course it's possible, but, you should refer to 'lua_parse.c' 'lcode.c*', you should dive to lua's VM bytecode deeply,
`
seq{rf90, delay[], acq}
`
equals to
`
for i =1, #delay do
seq{rf90, delay[i], acq}
end
`
First, I do know what `acq` means, nor the lua language allow the call a function `seq` without `()` directly.
There is an issue that the identifier 'i' will be a ghost identifier. `i` is not named after any hints. Do you treat it as a half-keyword(like _ENV or self)?

In addition, it's an incompatible issue that {} in lua means table creation while [] means __index, you should resolve the conflict. The grammar tree will be more complicated.



2017-01-14 11:17 GMT+08:00 常严 <changy@sibet.ac.cn>:
Hi all,

I would like define a simple grammar as follows:
seq{rf90, delay#, acq}

or
seq{rf90, delay*, acq}

or
seq{rf90, *delay, acq}

or
seq{rf90, delay[], acq}

in which delay may be a table array of objects, and # or * means do the seq{rf90, delay[i], acq} for #delay times.

Its explicit call is
for i =1, #delay do
seq{rf90, delay[i], acq}
end

I'd like to use # or * or [] to keep user in mind that it means loop.  It seems that we may need to define a special syntactic sugar? And is it possible to achieve the above goal? Thanks.

Regards,

Yan
--



Yan Chang
Suzhou Institute of Biomedical Engineering and Technology (SIBET)
Chinese Academy of Sciences (CAS)
88th Keling Road, SND, Suzhou, China 215163

Tel: +86 0512 6958 8133  (office)
Email:
changy@sibet.ac.cn






--



Yan Chang
Suzhou Institute of Biomedical Engineering and Technology (SIBET)
Chinese Academy of Sciences (CAS)
88th Keling Road, SND, Suzhou, China 215163

Tel: +86 0512 6958 8133  (office)
Email:
changy@sibet.ac.cn