8 - The Complete Syntax of lua

Here is the complete syntax of lua in extended BNF. (It does not describe operator precedences.)

chunk ::= {stat [`<b>;</b>&acute;]} [laststat [`<b>;</b>&acute;]]

block ::= chunk

stat ::=  varlist1 `<b>=</b>&acute; explist1 | 

functioncall |
do block end |
while exp do block end |
repeat block until exp |
if exp then block {elseif exp then block} [else block] end |
for Name <b>=</b>&acute; exp,´ exp [<b>,</b>&acute; exp] <b>do</b> block <b>end</b> | <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | <b>function</b> funcname funcbody | <b>local</b> <b>function</b> Name funcbody | <b>local</b> namelist [=´ explist1]laststat ::= return [explist1] | break

funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]

varlist1 ::= var {`<b>,</b>&acute; var}

var ::=  Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Namenamelist ::= Name {`<b>,</b>&acute; Name}

explist1 ::= {exp `<b>,</b>&acute;} exp

exp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | `<b>...</b>&acute; | function | 

prefixexp | tableconstructor | exp binop exp | unop expprefixexp ::= var | functioncall | <b>(</b>&acute; exp)´

functioncall ::=  prefixexp args | prefixexp `<b>:</b>&acute; Name argsargs ::=  `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Stringfunction ::= <b>function</b> funcbody

funcbody ::= `<b>(</b>&acute; [parlist1] `<b>)</b>&acute; block <b>end</b>

parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;

tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;

fieldlist ::= field {fieldsep field} [fieldsep]

field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp

fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;

binop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; | 

<b>&lt;</b>&acute; |<=´ | <b>&gt;</b>&acute; |>=´ | <b>==</b>&acute; |~=´ |
and | or

unop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;

Last update: Mon Jun 5 17:05:27 BRT 2006