IMP is a simple, minimal programming language. It was taught to me in a class in grad school on proving semantics of programming languages. I decided to write a simple interpreter for it as a running example in a series of blog posts on building interpreters.
IMP programs have three syntactic entities:
A program consists of a single statement, but statements can contain other statements. Arithmetic expressions are simple expressions that evaluate to integers. Boolean expressions evaluate to true or false. There are no values, other than integers and Booleans.
Variables may be assigned in IMP. All variables are global. There are no functions or scopes, so non-global variables wouldn't really make sense anyway. When an IMP program is finished executing, the interpreter prints the value of each variable. There is no other way for IMP programs to interact with the outside world.
else
. If the condition evaluates to true
, the first statement is executed. Otherwise, the second statement is executed.if a < b then
x := 1
else
y := 2
end
true
, the loop body is executed. This is repeated until the condition evaluates to false
.while x > 0 do
x := x - 1
end
Arithmetic expressions (aexps)
+
, -
, *
, /
) on two sub-aexps.<
, <=
, >
, >=
, =
, !=
) on two sub-aexps.and
. Evaluates to true
if both sub-expressions evaluate to true.or
. Evaluates to true
if either sub-expression evaluates to true.not
. Evaluates to the opposite of whatever the sub-expression evaluates to.TODO: write this section after refactoring.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4