lua-users home
lua-l archive

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


From: Asko Kauppi <askok@dnainternet.net>

|> Would be easier if you had listed the differences to real 
|> Lua 5 grammar.

below

|> You might be interested in work I'm currently doing, in taking out  
|> the parser from Lua core and making it more part of the 'lua' front  
|> end.

Parser Lua or Lua Light?
Lua parser have trouble, in syntax [function_call & let statement have
conflict, if you use simple Lua syntax: w/o( ['(' explist ')'] into begin),
it`s okey, so [ ... exp function_call || varlist - conflicted on open
bracket]]
In Lua 5.1.2 its rosolve LL gramar version backtracker. So its slow path for
make it up.
If You interesting, I have Lua GLR Grammar for Lua 5.1 on (bison), so I
can`t convert this to normal( non conflicted, non slow LARL parser ). Its
compiled idea of different project, so they release trimed version of Lua.
May be release Lua parser on PEG, so its will be non linear parser, as Lua
5.1.2, and have comparability speed.

So It`s conflict tell on users. On this position we must write [';'], which
not used to other.
And I am decision making creating compilator on Light version of language,
which have trivial transformer, and have all potential Lua text(may be
converted), try to attain realize simple.

Negative, lose, Lua: [local function ...], I can`t understand differents
with [local ... = function ...], it`s write on docs very misty.

|> This means, one can have alternative parser front ends, and  
|> experiment quite freely with the syntax, too.

I have trouble, in this. My release trend to C++ embedding, and may be not
compiled without BOOST, so it`s yield very much.
If you have  trouble whis alternative parser, may be rosolve it together? I
am approach.

|> 
|> -asko
|> 
|> ps. please add "continue" to your syntax?   ;)
|> 
|> pps. of course you cannot call something Lua if it's not at least  
|> backwards compatible with Lua syntax.

It`s not Lua, It`s Lua Light. Many language have Light version, very
attractive is Pascal Light. Many language have Tiny version, so it`s have
tiny potential.
For test of Idea Light version of language is more usability.

|> 
|> 

|> 
|> It`s proposed grammar(Byson) for ( Lua 5 Light, may be ), in 
|> style @Lua 5.1 Reference Manual@
|>  
|>     1 chunk: laststat
|>     2      | stat;
|>     3 block_ended: laststat
|>     4            | stat_w_end;
|>  
|>     6 stat_w_end: stat "end";
|>     7 laststat: stat "return" args
	// + ...return 1, ...return false; in Lua: ...return 1 end, ...
return false end
	// - ... return (1+2); in Lua: ...return 1+2 end

|>     8         | stat "return"
|>     9         | stat "break" "`[integral const]`"
	// it`s Idle idea

|>    10         | stat "break"
		| stat "continue" \\ please add "continue" to your syntax
;)
		// as Clu?

|>    11         | stat "error" args;
	// it`s	potentiality [throw]

|>    12 function_def: "function" '(' parlist ')' block_ended
|>    14             | '\\' parlist '\\' block_ended;
	// + \a\ return (a*a)
|>    16 parlist: /* empty */
|>    17        | "`...`"
|>    18        | namelist '|' "`...`"
	// - namelist ',' "`...`"; it`s the tail version, trimmed args of
function to 2 part
|>    19        | namelist '|' Name
	// + namelist '|' "`...`"; it`s the tail version, Named VARARG
|>    20        | namelist;
|>    21 namelist: namelist ',' Name
|>    22         | Name;
|>    23 stat: /* empty */
|>    24     | "use" varlist
	// Lua: local sin, cos = math.sin, math.cos; You can use this method
farther
	// +Lua5L: use math.sin, math.cos

|>    25     | stat "if" if_unmatched "else" block_ended
	// Lua5L:	if 5==3 then return(' 5 == 3 ') elseif 5==6 then # a
= 6 return(' 5 == 6 ') elseif 5==2 then # a = 2 else # a = 5 return
|>    27     | stat "if" if_unmatched "end"
	// Lua5L:	if 5==3 then return' 5 == 3 ' elseif 5==6 then # a =
6 return' 5 == 6 ' elseif 5==2 then # a = 2 else # a = 5 end
|>    28     | stat "loop" stat_w_end
	// + Lua: "while" "true" stat_w_end
	// in c++ "do" is loop, so on Lua is [algol "block"], for this
"black corner"

|>    29     | stat "while" exp stat_w_end
|>    30     | stat "for" namelist '=' explist stat_w_end
|>             // Lua: for i=1,50 do...; for i=1,20,3 do...; 
|> for k,v in pair(t) do...
|>             // Lua5L{as Clu, w/o 'in' & 'do'}:
|>                 // for i = from_to(1,50) ... for i = 
|> from_to_by(1,20,3) ...  for k,v = pair(t) ...
|>    31     | stat "repeat" stat "until" exp
|>    32     | stat '#' varlist '|' var '=' explist
|>    33     | stat '#' varlist '=' explist
|>    34     | stat '?' function_call
|>    35     | stat "local" namelist
|>    36     | stat "local" namelist '|' Name '=' explist
	// + tail version
|>    37     | stat "local" namelist '=' explist
|>    38     | stat "do" block_ended
|>    40     | stat "yield" args
	// + "coroutine.yield" args; released on vm
|>    41     | stat "yield";
|>    43 if_unmatched: if_unmatched "elseif" if_unmatched
|>    44             | exp "then" chunk;
|>    46 varlist: varlist ',' var
|>    47        | var;
|>    48 bracket: '(' exp ')'
|>    49 var: Name
|>    50    | "self"
	// #a:sqr = function() return (self.__value * self.__value)
|>    51    | bracket var_omega
|>    52    | var var_omega
|>    53    | function_call var_omega;
|>    54 var_omega: '[' exp ']'
|>    55          | ": identifier";    // Lua: ('.' Name) / 
|> (':' Name), Lua5L: Name:Name.Name <- may be
|>    56 function_call: bracket args
|>    57              | var args
|>    58              | function_call args;
|>    59 args: '(' explist ')'
|>    60     | '(' ')'
|>    61     | '{' fieldlist '}'
|>    62     | '{' '}'
|>    63     | String
|>    64     | "`[integral const]`"
	// Lua add(1)
	// + add 1
|>    65     | "`[const object]`"; // nil, false, true, number
	// Lua a:set(false)
	// + a.set 1
|>    66 explist: explist ',' exp
|>    67        | exp;
|>    68 exp: expression
|>    70    | exp '`' var '`' exp  /* 0 */  // Lua: var '(' exp 
|> ',' exp ')'
|>    71    | exp "`or`" exp /* 1 */
|>    72    | exp "`xor`" exp /* 1 */
|>    73    | exp "`and`" exp; /* 2 */
|>    74 expression: expression "`==`" expression /* 3, %nonassoc */
|>    75           | expression "`~=`" expression /* 3, %nonassoc */
|>    76           | expression '>' expression /* 3, %nonassoc */
|>    77           | expression '<' expression /* 3, %nonassoc */
|>    78           | expression "`<=`" expression /* 3, %nonassoc */
|>    79           | expression "`>=`" expression /* 3, %nonassoc */
|>    80           | expression "`..`" expression /* 4, %right */
|>    81           | expression '+' expression /* 5 */
|>    82           | expression '-' expression /* 5 */
|>    83           | expression '*' expression /* 6 */
|>    84           | expression '/' expression /* 6 */
|>    85           | expression '%' expression /* 6 */
|>    86           | '-' expression /* 7 */
|>    87           | '+' expression /* 7 */
|>    88           | '!' expression /* 7 */
|>    89           | expression '^' expression /* 8,%right */
|>    90           | '$' expression  /* 9 */       // {len} Lua: #exp
|>    91           | const_exptession
|>    92           | function_def
|>    93           | bracket
|>    94           | function_call
|>    95           | var
|>    96           | "`...`";
|>    97 const_exptession: '{' fieldlist '}'
|>    98                 | '{' '}'
|>    99                 | String
|>   100                 | "`[integral const]`"
|>   101                 | "`[const object]`";
|>   102 fieldlist: fieldlist ',' fieldlist
|>   103          | '[' exp ']' '=' exp
|>   104          | Name '=' exp
|>   105          | exp;


And the question: May be use Clu syntax for connect to C++ exception?