NAME ^

lua50.bnf - The Complete Syntax of Lua

DESCRIPTION ^

The following grammar comes from "Lua 5.0 Reference Manual".

        chunk ::= 
                ( stat [ ';' ] )* 

        block ::= 
                chunk

        stat ::= 
                varlist1 '=' 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
                | return [ explist1 ]
                | break
                | for Name '=' exp ',' exp [ ',' exp ] do block end
                | for Name ( ',' Name )* in explist1 do block end
                | function funcname funcbody
                | local function Name funcbody
                | local namelist [ init ]

        funcname ::= 
                Name ( '.' Name )* [ ':' Name ]

        varlist1 ::= 
                var ( ',' var )* 

        var ::= 
                Name | prefixexp '[' exp ']' | prefixexp '.' Name

        namelist ::= 
                Name ( ',' Name )*

        init ::=
                '=' explist1

        explist1 ::= 
                ( exp ',' )* exp

        exp ::= 
                nil | false | true | Number | Literal 
                | function | prefixexp | tableconstructor | exp binop exp | unop exp

        prefixexp ::= 
                var | functioncall | '(' exp ')'

        functioncall ::= 
                prefixexp args | prefixexp ':' Name args

        args ::= 
                '(' [ explist1 ] ')' | tableconstructor | Literal

        function ::= 
                function funcbody

        funcbody ::= 
                '(' [ parlist1 ] ')' block end

        parlist1 ::= 
                Name ( ',' Name )* [ ',' '...' ] | '...'

        tableconstructor ::= 
                '{' [ fieldlist ] '}'

        fieldlist ::= 
                field ( fieldsep field )* [ fieldsep ]

        field ::= 
                '[' exp ']' '=' exp | name '=' exp | exp

        fieldsep ::= 
                ',' | ';'

        binop ::= 
                '+' | '-' | '*' | '/' | '^' | '..' 
                | '<' | '<=' | '>' | '>=' | '==' | '~=' 
                | and | or

        unop ::= 
                '-' | not


parrot