From 3ccd4a85989d1b2cb463151c5f0f7bc571a3812c Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 20 Jun 2018 14:39:47 +0200 Subject: Show program code with AST for divisors --- aied2018/presentation/aied_poster.tex | 4 +++- aied2018/presentation/patterns.tex | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aied2018/presentation/aied_poster.tex b/aied2018/presentation/aied_poster.tex index 6956fdc..73de0e6 100644 --- a/aied2018/presentation/aied_poster.tex +++ b/aied2018/presentation/aied_poster.tex @@ -11,7 +11,7 @@ \newunicodechar{⋯}{\ensuremath{\cdots}} \usepackage{color} -\newcommand\red[1]{{\begingroup\color[rgb]{0.8,0.15,0.15}#1\endgroup}} +\newcommand\red[1]{{\begingroup\color[rgb]{0.9,0.2,0.2}#1\endgroup}} \newcommand\blue[1]{{\begingroup\color[rgb]{0.15,0.15,0.8}#1\endgroup}} \newcommand\green[1]{{\begingroup\color[rgb]{0.15,0.8,0.15}#1\endgroup}} @@ -24,6 +24,8 @@ \usepackage{mathtools} +\usepackage{textpos} + \newcommand\code[1]{\texttt{#1}} \newcommand\pattern[1]{\textsf{#1}} diff --git a/aied2018/presentation/patterns.tex b/aied2018/presentation/patterns.tex index b581157..8c701e9 100644 --- a/aied2018/presentation/patterns.tex +++ b/aied2018/presentation/patterns.tex @@ -37,6 +37,15 @@ for tree={ Such patterns can represent a program’s control structure, relationships between variables, etc. The red pattern below matches nested \code{for} and \code{if} statements, while the blue pattern relates two occurrences of the variable~\code{n}. +\begin{textblock}{0}(4,0.5) +\begin{Verbatim} +\textbf{\red{def}} divisors(\textbf{\blue{n}}): + \textbf{\red{for}} d \textbf{in} range(1,\textbf{\blue{n}}): + \textbf{\red{if}} n % d == 0: + \textbf{print}(d) +\end{Verbatim} +\end{textblock} + \begin{figure}[htb] \centering \vspace{0.8cm} @@ -49,8 +58,8 @@ for tree={ [name, name=name1 [divisors, name=divisors, font=\bfseries\sffamily]] [args, name=args1 [Var, name=args1-1, draw,rectangle,blue,line width=2pt [n, font=\bfseries\sffamily, l=0.7cm]]] - [body, name=body1, before computing xy={s=10cm} - [For, name=for, l=5cm, draw,rectangle,red,line width=2pt + [body, name=body1, before computing xy={s=6cm} + [For, name=for, l=7cm, draw,rectangle,red,line width=2pt [target [Var, l=0.9cm [d, font=\bfseries\sffamily, l=0.7cm]]] [iter, name=iter @@ -72,7 +81,7 @@ for tree={ [func [print, font=\bfseries\sffamily, l=0.7cm]] [args [Var, l=0.7cm [d, font=\bfseries\sffamily, l=0.6cm]]]]]]]]]] % first pattern - \path[-{Latex[length=5mm,width=2mm]},thick,relative,red] (def) edge[line width=2pt,transform canvas={xshift=1.1mm,yshift=1.5mm}] (body1); + \path[-{Latex[length=5mm,width=2mm]},thick,relative,red] (def) edge[line width=2pt,transform canvas={xshift=3.3mm,yshift=0mm}] (body1); \path[-{Latex[length=5mm,width=2mm]},thick,relative,red] (body1) edge[line width=2pt,transform canvas={xshift=2mm}] (for); \path[-{Latex[length=5mm,width=2mm]},thick,relative,red] (for) edge[line width=2pt,transform canvas={xshift=1.1mm,yshift=1.5mm}] (body2); \path[-{Latex[length=5mm,width=2mm]},thick,relative,red] (body2) edge[line width=2pt,transform canvas={xshift=2mm}] (if); -- cgit v1.2.1