40 lines
826 B
TeX
Raw Normal View History

2023-03-23 10:23:44 -07:00
\documentclass[
solutions,
2023-05-25 21:44:07 -07:00
hidewarning,
2023-03-23 10:23:44 -07:00
singlenumbering,
nopagenumber
]{../../resources/ormc_handout}
\usepackage[linguistics]{forest}
2023-05-25 21:44:07 -07:00
\title{Warm-Up: What's an AST?}
\subtitle{Prepared by Mark on \today. \\ Based on a true story.}
2023-03-23 10:23:44 -07:00
\begin{document}
\maketitle
Say you have a valid string of simple arithmetic that contains no unary operators (like $3!$ or $-4$) and no parenthesis:
$$
3 + 9 \times 8 \div 5 \land 6
$$
You may assume that all numbers and operators in this string consist of exactly one character. \\
Devise an algorithm that turns this string into a tree (as shown below), respecting the order of operations $[\land, \times, \div, +, -]$.
\begin{center}
\begin{forest}
[$+$
[3]
[$\div$
[$\times$[9][8]]
[$\land$[5][6]]
]
]
\end{forest}
\end{center}
\end{document}