Link Search Menu Expand Document
\( % cbs-katex.sty % \newcommand{\STYLE}[2]{\htmlClass{cbs-#1}{#2}} \newcommand{\DECL}[3]{\htmlId{#1:#2}{#3}} \newcommand{\REF}[3]{\href{###1:#2}{#3}} \newcommand{\HYPER}[5]{\href{#1/#2/index.html###3:#4}{#5}} % \SHADE{MATH} can be defined to produce a shaded background to highlight % inline MATH in running text: \newcommand{\SHADE}[1]{#1} % \KEY{TEXT}, \STRING{TEXT}, \ATOM{TEXT}, \LEX{TEXT} can be used in math mode: \newcommand{\KEY}[1]{\textsf{\textit{\STYLE{Key}{#1}}}} \newcommand{\STRING}[1]{\textsf{``\texttt{#1}''}} \newcommand{\ATOM}[1]{\textsf{`\texttt{#1}'}} \newcommand{\LEX}[1]{\textsf{\STYLE{Key}{`}\texttt{#1}\STYLE{Key}{'}}} % The following commands produce ASCII characters that are treated specially by LaTeX: \newcommand{\HASH}{\char`\#} \newcommand{\DOLLAR}{\char`\$} \newcommand{\PERCENT}{\char`\%} \newcommand{\AMPERSAND}{\char`\&} \newcommand{\APOSTROPHE}{\char`\'} \newcommand{\BACKSLASH}{\char`\\} \newcommand{\CARET}{\char`\^} \newcommand{\UNDERSCORE}{\char`\_} \newcommand{\GRAVE}{\char`\`} \newcommand{\LEFTBRACE}{\char`\{} \newcommand{\RIGHTBRACE}{\char`\}} \newcommand{\TILDE}{\textasciitilde} % {\char`\~} % \NAME{name} highlights the name; % \NAMEDECL{name} declares Name.name as the target of links to name; % \NAMEREF{name} links name to the target Name.name in the current file; % \NAMEHYPER{url}{file}{name} links name to Name.name at url/file/file.pdf. % Similarly for \VAR{partvariable}, \SYN{syntaxname}, \SEM{semanticsName}, % and \SECT{sectionnumber} % The kerns in \SUB and \VAR avoid overlaps with primes: \newcommand{\SUB}[1]{_{\kern-2mu\STYLE{PartVariable}{\textsf{#1}}}} % PLAIN \newcommand{\VAR}[1]{\STYLE{PartVariable}{\textsf{\textit{#1}\kern2mu}}} \newcommand{\NAME}[1]{\STYLE{Name}{\textsf{#1}}} \newcommand{\SYN}[1]{\STYLE{SyntaxName}{\textsf{#1}}} \newcommand{\SEM}[1]{\STYLE{SemanticsName}{\textsf{#1}}} \newcommand{\SECT}[1]{\STYLE{SectionNumber}{\textsf{#1}}} % DECL \newcommand{\VARDECL}[1]{\DECL{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEDECL}[1]{\DECL{Name}{#1}{\NAME{#1}}} \newcommand{\SYNDECL}[1]{\DECL{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMDECL}[1]{\DECL{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTDECL}[1]{\DECL{SectionNumber}{#1}{\textsf{#1}}} % REF \newcommand{\VARREF}[1]{\REF{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEREF}[1]{\REF{Name}{#1}{\NAME{#1}}} \newcommand{\SYNREF}[1]{\REF{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMREF}[1]{\REF{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTREF}[1]{\REF{SectionNumber}{#1}{\SECT{#1}}} % HYPER \newcommand{\VARHYPER}[3]{\HYPER{#1}{#2}{PartVariable}{#3}{\VAR{#3}}} \newcommand{\NAMEHYPER}[3]{\HYPER{#1}{#2}{Name}{#3}{\NAME{#3}}} \newcommand{\SYNHYPER}[3]{\HYPER{#1}{#2}{SyntaxName}{#3}{\SYN{#3}}} \newcommand{\SEMHYPER}[3]{\HYPER{#1}{#2}{SemanticsName}{#3}{\SEM{#3}}} \newcommand{\SECTHYPER}[3]{\HYPER{#1}{#2}{SectionNumber}{#3}{\SECT{#3}}} % \LEFTPHRASE MATH \RIGHTPHRASE produces [[ MATH ]] with proper brackets: \newcommand{\LEFTPHRASE}{\llbracket} \newcommand{\RIGHTPHRASE}{\rrbracket} % \LEFTGROUP MATH \RIGHTGROUP produces ( MATH ) where the parentheses are % highlighted the same as keywords: \newcommand{\LEFTGROUP}{\STYLE{Key}{(}} \newcommand{\RIGHTGROUP}{\STYLE{Key}{)}} % MATH\PLUS produces a superscript + % MATH\STAR produces a superscript * % MATH\QUERY produces a superscript ? \newcommand{\PLUS}{{}^{\texttt{+}}} \newcommand{\STAR}{{}^{\texttt{*}}} \newcommand{\QUERY}{{}^{\texttt{?}}} % \RULE{& PREMISE \\ & ...}{& FORMULA ... \\ & ...} produces an inference rule % with separately aligned premises and conclusion % PREMISE % ... % ----------- % FORMULA ... % ... \newcommand{\RULE}[2] {\frac{\begin{aligned}#1\end{aligned}}{\begin{aligned}#2\end{aligned}}} % \AXIOM{& FORMULA ... \\ & ...} produces an aligned formula % % FORMULA ... % ... \newcommand{\AXIOM}[1]{\begin{aligned}#1\end{aligned}} % \TO TYPE produces => TYPE \newcommand{\TO}{\mathop{\Rightarrow}} % TERM \TRANS TERM produces TERM ---> TERM \newcommand{\TRANS}{\longrightarrow} % TERM \xrightarrow{LABEL} TERM puts the label above the long arrow % \)

Languages-beta : SIMPLE-4-Declarations.cbs | PLAIN | PDF

OUTLINE

\[\KEY{Language} \quad \STRING{SIMPLE}\]

\(\SECT{4}\) Declarations

\[\begin{align*} \KEY{Syntax} \quad \VARDECL{Decl} : \SYNDECL{decl} \ ::= \ & \ \SYNREF{vars-decl} \mid \SYNREF{func-decl} \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{declare} \LEFTPHRASE \ \_ : \SYNREF{decl} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{environments} \end{align*}\]

\(\SECT{4.1}\) Variable Declarations

\[\begin{align*} \KEY{Syntax} \quad \VARDECL{VarsDecl} : \SYNDECL{vars-decl} \ ::= \ & \ \LEX{var} \ \SYNREF{declarators} \ \LEX{{;}} \\ \VARDECL{Declarators} : \SYNDECL{declarators} \ ::= \ & \ \SYNREF{declarator} \ \LEFTGROUP \LEX{{,}} \ \SYNREF{declarators} \RIGHTGROUP\QUERY \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{var} \ \VARREF{Declarator} \ \LEX{{,}} \ \VARREF{Declarators} \ \LEX{{;}} \ \VARHYPER{../.}{SIMPLE-3-Statements}{Stmts}\QUERY \ \RIGHTPHRASE : \SYNHYPER{../.}{SIMPLE-3-Statements}{stmts} = \\& \LEFTPHRASE \ \LEX{var} \ \VAR{Declarator} \ \LEX{{;}} \ \LEX{var} \ \VAR{Declarators} \ \LEX{{;}} \ \VAR{Stmts}\QUERY \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{var} \ \VARREF{Declarator} \ \LEX{{,}} \ \VARREF{Declarators} \ \LEX{{;}} \ \VARHYPER{../.}{SIMPLE-5-Programs}{Decls}\QUERY \ \RIGHTPHRASE : \SYNHYPER{../.}{SIMPLE-5-Programs}{decls} = \\& \LEFTPHRASE \ \LEX{var} \ \VAR{Declarator} \ \LEX{{;}} \ \LEX{var} \ \VAR{Declarators} \ \LEX{{;}} \ \VAR{Decls}\QUERY \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{declare} \LEFTPHRASE \ \LEX{var} \ \VARREF{Declarator} \ \LEX{{;}} \ \RIGHTPHRASE = \SEMREF{var-declare} \LEFTPHRASE \ \VAR{Declarator} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Syntax} \quad \VARDECL{Declarator} : \SYNDECL{declarator} \ ::= \ & \ \SYNHYPER{../.}{SIMPLE-1-Lexical}{id} \\ \ \mid \ & \ \SYNHYPER{../.}{SIMPLE-1-Lexical}{id} \ \LEX{{=}} \ \SYNHYPER{../.}{SIMPLE-2-Expressions}{exp} \\ \ \mid \ & \ \SYNHYPER{../.}{SIMPLE-1-Lexical}{id} \ \SYNREF{ranks} \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{var-declare} \LEFTPHRASE \ \_ : \SYNREF{declarator} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{environments} \\ \KEY{Rule} \quad & \SEMREF{var-declare} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bind} ( \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-variable} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values} ) ) \\ \KEY{Rule} \quad & \SEMREF{var-declare} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \LEX{{=}} \ \VARHYPER{../.}{SIMPLE-2-Expressions}{Exp} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bind} ( \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-initialised-variable} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values}, \SEMHYPER{../.}{SIMPLE-2-Expressions}{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE ) ) \\ \KEY{Rule} \quad & \SEMREF{var-declare} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \VARREF{Ranks} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bind} ( \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \NAMEREF{allocate-nested-vectors} ( \SEMREF{ranks} \LEFTPHRASE \ \VAR{Ranks} \ \RIGHTPHRASE ) ) \end{align*}\]

\(\SECT{4.2}\) Arrays

\[\begin{align*} \KEY{Syntax} \quad \VARDECL{Ranks} : \SYNDECL{ranks} \ ::= \ & \ \LEX{{[}} \ \SYNHYPER{../.}{SIMPLE-2-Expressions}{exps} \ \LEX{{]}} \ \SYNREF{ranks}\QUERY \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{[}} \ \VARHYPER{../.}{SIMPLE-2-Expressions}{Exp} \ \LEX{{,}} \ \VARHYPER{../.}{SIMPLE-2-Expressions}{Exps} \ \LEX{{]}} \ \VARREF{Ranks}\QUERY \ \RIGHTPHRASE : \SYNREF{ranks} = \\& \LEFTPHRASE \ \LEX{{[}} \ \VAR{Exp} \ \LEX{{]}} \ \LEX{{[}} \ \VAR{Exps} \ \LEX{{]}} \ \VAR{Ranks}\QUERY \ \RIGHTPHRASE \end{align*}\]

Compare this with p28 of the K version.

\[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{ranks} \LEFTPHRASE \ \_ : \SYNREF{ranks} \ \RIGHTPHRASE : ( \TO \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{nats} )\PLUS \\ \KEY{Rule} \quad & \SEMREF{ranks} \LEFTPHRASE \ \LEX{{[}} \ \VARHYPER{../.}{SIMPLE-2-Expressions}{Exp} \ \LEX{{]}} \ \RIGHTPHRASE = \SEMHYPER{../.}{SIMPLE-2-Expressions}{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{ranks} \LEFTPHRASE \ \LEX{{[}} \ \VARHYPER{../.}{SIMPLE-2-Expressions}{Exp} \ \LEX{{]}} \ \VARREF{Ranks} \ \RIGHTPHRASE = \SEMHYPER{../.}{SIMPLE-2-Expressions}{rval} \LEFTPHRASE \ \VAR{Exp} \ \RIGHTPHRASE , \SEMREF{ranks} \LEFTPHRASE \ \VAR{Ranks} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{allocate-nested-vectors}( \_ : \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{nats}\PLUS) : \TO \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{variables} \\ \KEY{Rule} \quad & \NAMEREF{allocate-nested-vectors} ( \VAR{N} : \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{nats} ) \leadsto \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-initialised-variable} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vectors} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{variables} ), \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vector} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{left-to-right-repeat} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-variable} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values} ), 1, \VAR{N} ) ) ) \\ \KEY{Rule} \quad & \NAMEREF{allocate-nested-vectors} ( \VAR{N} : \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{nats}, \VAR{N}\PLUS : \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Integers}{nats}\PLUS ) \leadsto \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-initialised-variable} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vectors} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{variables} ), \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Vectors}{vector} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{left-to-right-repeat} ( \NAMEREF{allocate-nested-vectors} ( \VAR{N}\PLUS ), 1, \VAR{N} ) ) ) \end{align*}\]

\(\SECT{4.3}\) Function Declarations

\[\begin{align*} \KEY{Syntax} \quad \VARDECL{FuncDecl} : \SYNDECL{func-decl} \ ::= \ & \ \LEX{function} \ \SYNHYPER{../.}{SIMPLE-1-Lexical}{id} \ \LEX{{(}} \ \SYNREF{ids}\QUERY \ \LEX{{)}} \ \SYNHYPER{../.}{SIMPLE-3-Statements}{block} \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \SEMREF{declare} \LEFTPHRASE \ \LEX{function} \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \LEX{{(}} \ \VARREF{Ids}\QUERY \ \LEX{{)}} \ \VARHYPER{../.}{SIMPLE-3-Statements}{Block} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bind} ( \\&\quad\quad \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-variable} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Functions}{functions} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Tuples}{tuples} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values}\STAR ), \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values} ) ) ) \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{initialise} \LEFTPHRASE \ \_ : \SYNREF{decl} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Null}{null-type} \\ \KEY{Rule} \quad & \SEMREF{initialise} \LEFTPHRASE \ \LEX{var} \ \VARREF{Declarators} \ \LEX{{;}} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Primitive}{Null}{null} \\ \KEY{Rule} \quad & \SEMREF{initialise} \LEFTPHRASE \ \LEX{function} \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \LEX{{(}} \ \VARREF{Ids}\QUERY \ \LEX{{)}} \ \VARHYPER{../.}{SIMPLE-3-Statements}{Block} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{assign} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bound} ( \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE ), \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Functions}{function} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Generic}{closure} ( \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{scope} ( \\&\quad\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{match} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given}, \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Tuples}{tuple} ( \SEMREF{patts} \LEFTPHRASE \ \VAR{Ids}\QUERY \ \RIGHTPHRASE ) ), \\&\quad\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Abnormal}{Returning}{handle-return} ( \SEMHYPER{../.}{SIMPLE-3-Statements}{exec} \LEFTPHRASE \ \VAR{Block} \ \RIGHTPHRASE ) ) ) ) \end{align*}\] \[\begin{align*} \KEY{Syntax} \quad \VARDECL{Ids} : \SYNDECL{ids} \ ::= \ & \ \SYNHYPER{../.}{SIMPLE-1-Lexical}{id} \ \LEFTGROUP \LEX{{,}} \ \SYNREF{ids} \RIGHTGROUP\QUERY \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{patts} \LEFTPHRASE \ \_ : \SYNREF{ids}\QUERY \ \RIGHTPHRASE : \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{patterns}\STAR \\ \KEY{Rule} \quad & \SEMREF{patts} \LEFTPHRASE \ \ \RIGHTPHRASE = ( \ ) \\ \KEY{Rule} \quad & \SEMREF{patts} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Generic}{closure} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{bind} ( \\&\quad\quad\quad \SEMHYPER{../.}{SIMPLE-1-Lexical}{id} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Storing}{allocate-initialised-variable} ( \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{values}, \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ) ) ) \\ \KEY{Rule} \quad & \SEMREF{patts} \LEFTPHRASE \ \VARHYPER{../.}{SIMPLE-1-Lexical}{Id} \ \LEX{{,}} \ \VARREF{Ids} \ \RIGHTPHRASE = \\&\quad \SEMREF{patts} \LEFTPHRASE \ \VAR{Id} \ \RIGHTPHRASE , \SEMREF{patts} \LEFTPHRASE \ \VAR{Ids} \ \RIGHTPHRASE \end{align*}\]