Link Search Menu Expand Document

SIMPLE-3-Statements.md

{::comment}{:/}


----

$$\KEY{Language} \quad \LANG{\STRING{SIMPLE}}$$

# $$\SECT{3}$$ Statements {#SectionNumber:3}


$$\begin{align*}
  \KEY{Syntax} \quad
    \VARDEC{Block} : \SYNDEC{block}
      \ ::= \ & \
      \LEX{{\LEFTBRACE}} \ \SYN@stmts\QUERY \ \LEX{{\RIGHTBRACE}}
    \\
    \VARDEC{Stmts} : \SYNDEC{stmts}
      \ ::= \ & \
      \SYN@stmt \ \SYN@stmts\QUERY
    \\
    \VARDEC{Stmt} : \SYNDEC{stmt}
      \ ::= \ & \
      \SYN@imp@stmt \mid \SYN@vars@decl
    \\
    \VARDEC{ImpStmt} : \SYNDEC{imp-stmt}
      \ ::= \ & \
      \SYN@block \\
      \ \mid \ & \ \SYN@exp \ \LEX{{;}} \\
      \ \mid \ & \ \LEX{if} \ \LEX{{(}} \ \SYN@exp \ \LEX{{)}} \ \SYN@block \ \LEFTGROUP \LEX{else} \ \SYN@block \RIGHTGROUP\QUERY \\
      \ \mid \ & \ \LEX{while} \ \LEX{{(}} \ \SYN@exp \ \LEX{{)}} \ \SYN@block \\
      \ \mid \ & \ \LEX{for} \ \LEX{{(}} \ \SYN@stmt \ \SYN@exp \ \LEX{{;}} \ \SYN@exp \ \LEX{{)}} \ \SYN@block \\
      \ \mid \ & \ \LEX{print} \ \LEX{{(}} \ \SYN@exps \ \LEX{{)}} \ \LEX{{;}} \\
      \ \mid \ & \ \LEX{return} \ \SYN@exp\QUERY \ \LEX{{;}} \\
      \ \mid \ & \ \LEX{try} \ \SYN@block \ \LEX{catch} \ \LEX{{(}} \ \SYN@id \ \LEX{{)}} \ \SYN@block \\
      \ \mid \ & \ \LEX{throw} \ \SYN@exp \ \LEX{{;}}
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \LEFTPHRASE \
        \LEX{if} \ \LEX{{(}} \ \VAR@Exp \ \LEX{{)}} \ \VAR@Block \
      \RIGHTPHRASE : \SYN@stmt = \\&
      \LEFTPHRASE \
        \LEX{if} \ \LEX{{(}} \ \VAR{Exp} \ \LEX{{)}} \ \VAR{Block} \ \LEX{else} \ \LEX{{\LEFTBRACE}} \ \LEX{{\RIGHTBRACE}} \
      \RIGHTPHRASE
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \LEFTPHRASE \
        \LEX{for} \ \LEX{{(}} \ \VAR@Stmt \ \VAR@Exp\SUB{1} \ \LEX{{;}} \ \VAR@Exp\SUB{2} \ \LEX{{)}} \\&\quad
        \LEX{{\LEFTBRACE}} \ \VAR@Stmts \ \LEX{{\RIGHTBRACE}} \
      \RIGHTPHRASE : \SYN@stmt = \\&
      \LEFTPHRASE \
        \LEX{{\LEFTBRACE}} \ \VAR{Stmt} \\&\quad
        \LEX{while} \ \LEX{{(}} \ \VAR{Exp}\SUB{1} \ \LEX{{)}} \\&\quad
        \LEX{{\LEFTBRACE}} \ \LEX{{\LEFTBRACE}} \ \VAR{Stmts} \ \LEX{{\RIGHTBRACE}} \ \VAR{Exp}\SUB{2} \ \LEX{{;}} \ \LEX{{\RIGHTBRACE}} \\&\quad
        \LEX{{\RIGHTBRACE}} \
      \RIGHTPHRASE
\end{align*}$$

$$\begin{align*}
  \KEY{Semantics} \quad
  & \SEMDEC{exec} \LEFTPHRASE \ \_ : \SYN@stmts \ \RIGHTPHRASE  
    :  \TO \FUN@null@type 
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{{\LEFTBRACE}} \ \LEX{{\RIGHTBRACE}} \
                          \RIGHTPHRASE  = 
      \FUN@null
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{{\LEFTBRACE}} \ \VAR@Stmts \ \LEX{{\RIGHTBRACE}} \
                          \RIGHTPHRASE  = 
      \SEM@exec \LEFTPHRASE \
                \VAR{Stmts} \
              \RIGHTPHRASE 
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \VAR@ImpStmt \ \VAR@Stmts \
                          \RIGHTPHRASE  = \\&\quad
      \FUN@sequential
        (  \SEM@exec \LEFTPHRASE \
                        \VAR{ImpStmt} \
                      \RIGHTPHRASE , 
               \SEM@exec \LEFTPHRASE \
                        \VAR{Stmts} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \VAR@VarsDecl \ \VAR@Stmts \
                          \RIGHTPHRASE  = \\&\quad
      \FUN@scope
        (  \SEM@declare \LEFTPHRASE \
                        \VAR{VarsDecl} \
                      \RIGHTPHRASE , 
               \SEM@exec \LEFTPHRASE \
                        \VAR{Stmts} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \VAR@VarsDecl \
                          \RIGHTPHRASE  = 
      \FUN@effect
        (  \SEM@declare \LEFTPHRASE \
                        \VAR{VarsDecl} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \VAR@Exp \ \LEX{{;}} \
                          \RIGHTPHRASE  = 
      \FUN@effect
        (  \SEM@rval \LEFTPHRASE \
                        \VAR{Exp} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{if} \ \LEX{{(}} \ \VAR@Exp \ \LEX{{)}} \ \VAR@Block\SUB{1} \ \LEX{else} \ \VAR@Block\SUB{2} \
                          \RIGHTPHRASE  = \\&\quad
      \FUN@if@else
        (  \SEM@rval \LEFTPHRASE \
                        \VAR{Exp} \
                      \RIGHTPHRASE , 
               \SEM@exec \LEFTPHRASE \
                        \VAR{Block}\SUB{1} \
                      \RIGHTPHRASE , 
               \SEM@exec \LEFTPHRASE \
                        \VAR{Block}\SUB{2} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{while} \ \LEX{{(}} \ \VAR@Exp \ \LEX{{)}} \ \VAR@Block \
                          \RIGHTPHRASE  = 
      \FUN@while
        (  \SEM@rval \LEFTPHRASE \
                        \VAR{Exp} \
                      \RIGHTPHRASE , 
               \SEM@exec \LEFTPHRASE \
                        \VAR{Block} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{print} \ \LEX{{(}} \ \VAR@Exps \ \LEX{{)}} \ \LEX{{;}} \
                          \RIGHTPHRASE  = 
      \FUN@print
        (  \SEM@rvals \LEFTPHRASE \
                        \VAR{Exps} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{return} \ \VAR@Exp \ \LEX{{;}} \
                          \RIGHTPHRASE  = 
      \FUN@return
        (  \SEM@rval \LEFTPHRASE \
                        \VAR{Exp} \
                      \RIGHTPHRASE  )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{return} \ \LEX{{;}} \
                          \RIGHTPHRASE  = 
      \FUN@return
        (  \FUN@null )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{try} \ \VAR@Block\SUB{1} \ \LEX{catch} \ \LEX{{(}} \ \VAR@Id \ \LEX{{)}} \ \VAR@Block\SUB{2} \
                          \RIGHTPHRASE  = \\&\quad
      \FUN@handle@thrown
        ( \\&\quad\quad \SEM@exec \LEFTPHRASE \
                        \VAR{Block}\SUB{1} \
                      \RIGHTPHRASE , \\&\quad\quad
               \FUN@scope
                ( \\&\quad\quad\quad \FUN@bind
                        (  \SEM@id \LEFTPHRASE \
                                        \VAR{Id} \
                                      \RIGHTPHRASE , 
                               \FUN@allocate@initialised@variable
                                (  \FUN@values, 
                                       \FUN@given ) ), \\&\quad\quad\quad
                       \SEM@exec \LEFTPHRASE \
                                \VAR{Block}\SUB{2} \
                              \RIGHTPHRASE  ) )
\end{align*}$$

$$\begin{align*}
  \KEY{Rule} \quad
    & \SEMREF{exec} \LEFTPHRASE \
                            \LEX{throw} \ \VAR@Exp \ \LEX{{;}} \
                          \RIGHTPHRASE  = 
      \FUN@throw
        (  \SEM@rval \LEFTPHRASE \
                        \VAR{Exp} \
                      \RIGHTPHRASE  )
\end{align*}$$



[Funcons-beta]: /CBS-beta/math/Funcons-beta
  "FUNCONS-BETA"
[Unstable-Funcons-beta]: /CBS-beta/math/Unstable-Funcons-beta
  "UNSTABLE-FUNCONS-BETA"
[Languages-beta]: /CBS-beta/math/Languages-beta
  "LANGUAGES-BETA"
[Unstable-Languages-beta]: /CBS-beta/math/Unstable-Languages-beta
  "UNSTABLE-LANGUAGES-BETA"
[CBS-beta]: /CBS-beta
  "CBS-BETA"
[SIMPLE-3-Statements.cbs]: https://github.com/plancomps/CBS-beta/blob/math/Languages-beta/SIMPLE/SIMPLE-cbs/SIMPLE/SIMPLE-3-Statements/SIMPLE-3-Statements.cbs
  "CBS SOURCE FILE ON GITHUB"
[PLAIN]: /CBS-beta/docs/Languages-beta/SIMPLE/SIMPLE-cbs/SIMPLE/SIMPLE-3-Statements
  "CBS SOURCE WEB PAGE"
 [PRETTY]: /CBS-beta/math/Languages-beta/SIMPLE/SIMPLE-cbs/SIMPLE/SIMPLE-3-Statements
  "CBS-KATEX WEB PAGE"
[PDF]: /CBS-beta/math/Languages-beta/SIMPLE/SIMPLE-cbs/SIMPLE/SIMPLE-3-Statements/SIMPLE-3-Statements.pdf
  "CBS-LATEX PDF FILE"
[PLanCompS Project]: https://plancomps.github.io
  "PROGRAMMING LANGUAGE COMPONENTS AND SPECIFICATIONS PROJECT HOME PAGE"
{::comment}{:/}