Math & Science ⇒ context free grammar
context free grammar
I need to do type setting of simple context-free grammar. i could not find any useful packages dedicated for that. Are there any such packages ?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: context free grammar
can you please attach (or provide a link to) an image showing the kind of things that you want to do?
context free grammar
context free grammar
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{txfonts}
\begin{document}
{\setlength\tabcolsep{4pt}
\begin{tabular}{>{$}l<{$}>{$}r<{$}>{$}l<{$}}
R &\Coloneqq & R\\
&| &R_\ast\\
&| &(R)\\
&| &a\\
&| &b
\end{tabular}}
\end{document}
context free grammar
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{txfonts}
\begin{document}
{\setlength\tabcolsep{4pt}
\begin{tabular}{>{$}l<{$}>{$}r<{$}>{$}l<{$}}
e &\Coloneqq &n\\
&| &x\\
&| &e_1 \; op_b \; e_2\\
&| &op_m \; e\\
&| &(e)\\
&| &f(es)\\
es &\Coloneqq &e\\
&| &e, \; es\\
S &\Coloneqq &x := e;\\
&| &skip;\\
&| &read \; x;\\
&| &write \; e;\\
&| &return \; e;\\
&| &if(e) \; S_1 \; else \; S_2\\
&| &while(e) \; S\\
&| &\{Ds \; Ss\}\\
&| &\{Ss\}\\
Ss &\Coloneqq &S\\
&| &S \; Ss\\
Ds &\Coloneqq &T \; x;\\
&| &T \; x; Ds\\
Fs &\Coloneqq &T \; f(Ds)\{Ss\}\\
&| &T \; f(Ds)\{Ss\} \; Fs\\
T &\Coloneqq &int\\
&| &float\\
P &\Coloneqq &program \; Ds \; Fs \; Ss \; end
\end{tabular}}
$op_b \in \{\&,|,<,>,+,-,*,/\}, op_m \in \{!,-\}$
\end{document}
context free grammar
certain combinations of characters will produce that unwanted space. In the code below I defined the new command \nonter that corrects the problem:
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{txfonts}
\newcommand\nonter[1]{\ensuremath{#1\negthinspace s}}
\begin{document}
{\setlength\tabcolsep{4pt}
\begin{tabular}{>{$}l<{$}>{$}r<{$}>{$}l<{$}}
&| &\{Ds \; Ss\}\\% bad spacing
&| &\{Ds \; \nonter{S} \}\\% corrected spacing
&| &\{Ds \; Fs\}\\% bad spacing
&| &\{Ds \; \nonter{F} \}% corrected spacing
\end{tabular}}
\end{document}