块和语句

最后更新于:2022-04-02 04:08:05

[TOC] ## 定义语句块和语句: ``` program -> stmts -> Stmt Stmts | ε Stmt -> IfStmt | WhileStmt | ForStmt | Function | Block Block -> {Stmts} ``` 整体定义 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/12/8a/128aa51270cbf8c28f6a43dff5d2e2a6_1964x528.png) ## 变量定义 ``` DeclareStmt -> var Variable = Expr ``` ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/41/ff/41ff532f5cd9525a855092c850b77156_221x400.png) ## 变量赋值 ``` AssignStmt -> Variable = Expr ``` ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/d7/a2/d7a2045d3c7e7be177e9b9b1794c8fa3_261x400.png) ## IfStmt ``` IfStmt -> If(Expr) Block | If(Expr) BLock else Block | If(Expr) Block else IfStmt // 简化:提取公共前缀 IfStmt -> If(Expr) BLock Tail Tail -> else {BLock} | else IfStmt | ε ``` ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/72/76/727669d4d7784418926694012c4b6b6d_800x113.png) ## Function 定义 ``` Function ->func (Args) Type Block Args -> Type Variable Args | Type Variable | ε ReturnType -> Type | ε Type : int |string |void | bool |string ```
';