Parsing LANG1
In this section we will investigate the parsing of LANG1, that is, we will
construct a function that will go from the concrete syntax of LANG1
to the abstract syntax of LANG1. Loosely speaking, this function,
call it doparse, will be an inverse
to the function given by the homomorphism h_{syn}
= aitch(alg_LANG1Syn, __ ) . However, since the contextfree
grammar for LANG1 is ambiguous (i.e., h_{syn
}is
not injective), what we will get is h_{syn}doparse
= 1 but doparseh_{syn}
1. The ambiguity is not be a problem since we will get
h_{sem}
doparseh_{syn}=
h_{sem} , where h_{sem }
= aitch(alg_LANG1Sem, __ )
It follows then that the function h_{sem}
doparse is a compiler for LANG1, that is, it is a function
taking expressions written in the concrete syntax to their meanings.
The Programs
We offer the user three programs

doparse(prog) which takes a concrete program, prog,
as argument and returns the corresponding abstract program.

compLANG1(prog) which takes a concrete program, prog,
as argument and returns the corresponding function on states  more
accurately speaking, it returns a JavaScript program that computes that
function. Thus compLANG1 can be viewed as a compiler from LANG1 to
JavaScript. However, the result of applying compLANG1 to a LANG1
program, prog, is a JavaScript program implementing
a function SttStt
rather than a direct translation of prog
into JavaScript.

runLANG1(prog, stt) which takes a concrete program, prog,
and a state, stt, as arguments and returns
the state resulting from applying the function corresponding to prog
to the state stt.
There is a builtin sample state, called samplestt,
with initial value [["a", 10], ["b",
3], ["c", 77]] that can be used to test the following examples.
Note that performing the examples will modify the value of samplestt.
Of course, you can also input states of your own choosing.
Here are some sample concrete LANG1 programs which you can parse,
compile or run:

"b:=1; While (1<=a) do b:=(a*b); a:=(a+(1))
od"  the familiar program for the factorial

"If (a<=b) then c:=1 else c:=2 fi"

"If (a<=b) then c:=(c+(1)) else c:=(c+1)
fi"