lua-users home
lua-l archive

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

It was thus said that the Great 常严 once stated:
> 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.

  There is MetaLua, which allows user written syntax to be added, and I
think there are some other projects that will allow this form of hacking as
well (such as LuainLua [1], a project in Lua to compile Lua into Lua
bytecodes).  But before going down that road, you do need to think about
what you are trying to do.  For instance, you have (and I'm using '@' as the
syntactic element to show that this is new):


But what about this case?


What's the expansion?

	for i = 1 , max(#a,#b) do

	for i = 1 , min(#a,#b) do

	for i = 1 , #a do
		for j = 1 , #b do

because a case could be made for each one.  There are other cases to be
aware of, such as:

	x = min(@foo)
	y = min(max(@foo))
	z = z + @foo -- assume z has been initialized properly
	i = i + @a + @b -- assume i has been initialized properly

How would these be mapped?  Are these even valid?  If not, why not?

  There's a bit of this blog post (
that might be of interest for this (it's the bottom part, just past the
graph image---search for "Connection Machine"), as using the syntax from
there, your example would be:

	α seq(rf90,•delay,acq)

(that's <UNICODE ALPHA> seq(rf90,<UNICODE DOT>delay,acq))