lua2.1的文法

下面是lua2.1的文法,来自lua源代码中的lua.stx文件

 

终结符使用黑体表示

非终结符使用斜体表示

 

functionlist -> null

| functionlist stat sc

| functionlist function

| functionlist setdebug

 

function -> function name body

 

method -> function name : name body 

 

body -> ( parlist ) block end

 

statlist -> null

| statlist stat sc

 

sc -> null | ;

 

stat -> stat1

 

cond -> expr1

 

stat1 -> if expr1 then PrepJump block Prejump elsepart end

| while expr1 do PrepJump block PreJump end

| repeat block until cond PrepJump

| varlist = exprlist1

| functioncall

| local localdeclist decinit

 

elsepart -> null

| else block

| elseif cond then PrepJump block PrepJump elsepart

 

block -> statlist ret

 

ret -> null

| return exprlist sc

 

PrepJump -> null

 

expr1 -> expr

 

expr -> ( expr )

| expr1 == expr1

| expr1 < expr1

| expr1 > expr1

| expr1 ~= expr1

| expr1 <= expr1

| expr1 >= expr1

| expr1 + expr1

| expr1 - expr1

| expr1 * expr1

| expr1 / expr1

| expr1 ^ expr1

| expr1 .. expr1

| 有个表达式暂时没想明白,暂时不写上去

| table

| varexp

| number

| string

| nil

| functioncall

| not expr1

| expr1 and PreJump expr1

| expr1 or PrepJump expr1

 

table -> { filedlist }

 

functioncall -> funcvalue funcParams

 

funcvalue -> varexp

| varexp : name

 

funcParams -> ( exprlist )

| table


exprlist -> null | exprlist1

 

exprlist1 -> expr | exprlist1 , expr

 

parlist -> parlist1

 

parlist1 -> name

| parlist1 , name

 

fieldlist -> null

| lfieldlist1 lastcomma

| ffieldlist1 lastcomma

| lfieldlist1 ; ffieldlist1 lastcomma

 

lastcomma -> null | ,

 

ffieldlist1 -> ffield

| ffieldlist1 , ffield

 

ffield -> name = expr1

 

lfieldlist1 -> expr1

| lfieldlist1 , expr1

 

varlist1 -> var

| varlist1 , var

 

var -> singlevar

| varexp [ expr1 ]

| varexp . name

 

 

singlevar -> name

 

varexp -> var

 

localdeclist -> name

| localdeclist , name

 

decinit -> null

| = exprlist1

 

setdebug -> $debug

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值