[Metalua-list] [Q] metalua and lpeg module

V S P toreason at fastmail.fm
Sun Nov 2 01:01:08 GMT+2 2008


Fabien

I am taking a little different direction now
and wanted to ask if this is making sence:

Basically instead of adding new constructs to Lua syntax
and trying to get Metalua to understand them,

I am sticking with existing lua consructs
Because my goal now is to translate a very small subset
of 'lua' code into javascript.

So far there in that subset there are no statements (no assignments)
no functions, only if/else  for loops and
function calls on table elements


So I have been getting some advise from lua user list,
and now have a subset of metalua's parser producing me an AST
tree.  I am using Luaanalyze
http://math2.org/download/luaanalyze-20080925b.tar.gz

as it has a metalua parser/lexer in there, and that one does not depend
on C/Windows. So it works for me.


I have produced a simple AST tree using it
for a sample code that I will need to translate

if a.x233< a.z233 and a.m233< 5 then hide(q.x233) else hide(q.z233) end


the generated AST (printed with table.show code from 
http://lua-users.org/wiki/TableSerialization)


I copied it here:
http://pastebin.com/m64e65f46


It seems like I need now to traverse AST, organize it into
'blocks'   -- and then apply my transformation rules to get them
in javascript (which will be very simple).


I am going in the right direction?

If yes, are there any internal functions/or examples of walking
the AST tree for 'constructing the blocks'  or should be rolling my own?

( I looked at the documentation for metalua, but it seems like the
walkers are avalabe only in .mlua (that is from within metalua
environment,
and I am just trying to use a portion of metalua -- because it has
a prebuild  lua parser/lexer -- and no other project has that
(building my own in LPeg would be a undertaking).


thanks in advance,
Vlad











On Mon, 6 Oct 2008 14:59:05 +0200, "Fabien Fleutot" <fleutot at gmail.com>
said:
> > c:\usr\local\metalua\lua  c:\usr\local\metalua\mlc.luac
> > test_metalua1.lua
> 
> 
> That was a long time ago, with metalua 0.1 and 0.2 IIRC... now the
> command
> line is just "metalua", with "metalua -h" providing some help: I think
> there's a metalua.bat in the windows version, but I can't check right
> now.
> If mlc is still referenced in the current manual (which I can't check
> right
> now either), then it's a mistake.
> 
> 
> > I also tried to execute lua directly on the sample file, thinking
> > that this version of lua would be able to interpret
> > -{
> > but that generated an error:
> > lua: test_metalua1.lua:1: unexpected symbol near '-'
> 
> 
> indeed -{ is a metalua-specific symbol. Metalua shares the same bytecode
> and
> virtual machine as lua but has a distinct compiler. You can either:
> 
> - compile into bytecode with "metalua -o myprog.luac myprog.mlua": then
> myprog.luac is a bytecode file that can be run with "mua myprog.luac"
> (this
> is sometimes useful, as programs with complex metaprogramming features
> can
> take up to a couple of seconds to compile on slower computer. Besides, if
> you embed your program electronic devices, they might not have the
> resources
> to run the metalua compiler)
> 
> - run directly with "metalua myprog.mlua"
> 
> Anyway I'll do my best to provide something lua4windows-compatible ASAP.
-- 
  V S P
  toreason at fastmail.fm

-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
                          unladen european swallow




More information about the Metalua-list mailing list