0

I hope you can you help me. I am writing my homework with LaTeX (using TexStudio as environment).

enter image description here

This table contains three columns: Syntax, Strictness and Semantics. For my homework, I need to describe these table and the most important thing is the Semantics column. The developers used special algebraic symbols which I cannot find in the math package. Take for example the first line. The variable "i" underneath the "x" means that "i" will replace "x". But the fraction symbol is not really a fraction, isn't it? How can I use this in LaTeX? If you go futher until the "while" condition, you will realize the long dashed line, how can I use this?

It will be my first table in LaTeX because I have not used LaTeX for writing my essays/projects. I need also to know how tables are generated using LaTeX.

Please help.

4

Not really a beginner's task. Anyway, I think that this is a good occasion for learning something about LaTeX.

  1. Define commands for the various subtasks, after deciding what are the more frequent constructions and dividing them by kind;
  2. look at the table layout: we recognize three columns (r, c and l) in the “Original language syntax” part;
  3. add the items in a consistent way.

The structure I recognize are “metavariables”, “keys” (subdivided into words, operators, binary operations, relations and punctuation). In the last column, we can see the constructs in angle brackets; the fraction-like objects have been dealt with an array, with solid or dotted separator.

Finally, for the few cases a line has to be broken up, I define an ad hoc \dbl command. In a couple of cases, manual intervention is necessary.

\documentclass{article}
\usepackage{amsmath,mathtools,amssymb,array,arydshln}

\newcommand{\meta}[1]{\mathit{#1}}
\newcommand{\kword}[1]{\mathtt{#1}}
\newcommand{\kop}[1]{\mathop{{}\texttt{#1}}}
\newcommand{\kbin}[1]{\mathbin{\texttt{#1}}}
\newcommand{\krel}[1]{\mathrel{\texttt{#1}}}
\newcommand{\kpun}[1]{\mathpunct{\texttt{#1}}}
\newcommand{\str}[1]{[\textit{#1}]}
\newcommand{\sem}[2]{\langle #1\rangle_{\mathsf{#2}}}
\newcommand{\sop}[2]{#1_{\mathit{#2}}}
\newcommand{\Ceq}{\Coloneqq}
\newcommand{\dbl}[1]{\begin{array}[t]{@{}l@{}}#1\end{array}}
\newcommand{\subexp}[2]{\begin{array}[t]{@{}c@{}}#1\\\hline#2\end{array}}
\newcommand{\sv}{\subexp{\mbox{\enspace}}{\mbox{\enspace}}}
\newcommand{\dsubexp}[2]{%
  \begin{array}[t]{@{}c@{}}#1\\\cdashline{1-1}[.4pt/1pt]#2\end{array}%
}

\begin{document}

\begin{tabular}{
  |
  >{$}r<{$}
  @{}
  >{${}}c<{{}$}
  @{}
  >{$}l<{$}
  |
  l
  |
  >{$}l<{$}
  |
}
\hline
\multicolumn{3}{|c|}{Original language syntax} &
\multicolumn{1}{c|}{Strictness} &
\multicolumn{1}{c|}{Semantics} \\
\hline
\meta{AExp}
& \Ceq & \meta{Int}\mid \meta{Id} &
&
\sem{\subexp{x}{i}\quad \sv}{k} \quad \sem{\sv\quad x\mapsto i\quad \sv}{state} \\
& \mid & \meta{AExp}\kbin{+}\meta{AExp} &
\str{strict} &
i_1\kbin{+}i_2 \to i_1 \sop{+}{Int} i_2 \\
& \mid & \meta{AExp}\kbin{/}\meta{AExp} &
\str{strict} &
i_1\kbin{/}i_2 \to i_1 \sop{/\!}{Int} i_2 \qquad \text{when $i_2\ne0$} \\
\meta{BExp}
& \Ceq & \meta{AExp}\krel{<=}\meta{AExp} &
\str{seqstrict} &
i_1\krel{<=}i_2 \to i_1 \sop{\le}{Int} i_2 \\
& \mid & \kop{not}\meta{BExp} &
\str{strict} &
\kop{not} t \to \sop{\lnot}{Bool} t \\
& \mid & \meta{BExp}\krel{and}\meta{BExp} &
\str{strict\textup{(1)}} &
\dbl{
  \meta{true}\krel{and} b \to b \\
  \meta{false}\krel{and} b \to \kword{false}
} \\
\meta{Stmt}
& \Ceq & \kword{skip}\kpun{;} &
&
\kword{skip}\kpun{;} \to {\cdot} \\
& \mid & \meta{Id}\krel{=}\meta{AExp}\kpun{;} &
\str{strict\textup{(2)}} &
\sem{\subexp{x\krel{=}i\kpun{;}}{\cdot}\quad \sv}{k}
  \quad \sem{\sv\quad x\mapsto \subexp{{\!\underline{\quad }\!}}{\,i\,}\quad \sv}{state} \\
& \mid & \meta{Stmt}\quad \meta{Stmt} &
&
s_1\quad s_2 \rightharpoonup s_1 \curvearrowright s_2 \\
& \mid & \krel{if}\meta{BExp}\;\dbl{\krel{then}\meta{Stmt}\\\krel{else}\meta{Stmt}} &
\str{strict\textup{(1)}} &
  \dbl{
    \krel{if}\meta{true}\krel{then} s \krel{else} \_ \to s \\
    \krel{if}\meta{false}\krel{then} \_ \krel{else} s \to s
  } \\
& \mid & \krel{while}\meta{BExp}\krel{then}\meta{Stmt} &
&
\sem{
  \dsubexp
    {\krel{while} b \krel{do} s}
    {\krel{if} b \krel{then} (s\krel{while} b \krel{do} s)
     \krel{else}\kword{skip}\kpun{;}}
  \quad \sv}{k} \\
\meta{Pgm}
& \Ceq & \kop{var}\mathsf{List}[\meta{Id}]\kpun{;}\quad \meta{Stmt} &
&
\sem{\dsubexp{\kop{var}xl\kpun{;}\quad s}{s}}{k}
  \quad \sem{\dsubexp{\cdot}{xl\mapsto 0}}{state} \\
\hline
\end{tabular}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.