An arithmetic expression language
Arithmetic expressions are a part of every programming language. Here is an example of an arithmetic expression calculation language called calc. The calc expressions are compiled into an application that evaluates the following expression:
with a, b: a * (4 + b)
The used variables in the expression must be declared with the keyword, with
. This program is compiled into an application that asks the user for the values of the a
and b
variables and prints the result.
Examples are always welcome but, as a compiler writer, you need a more thorough specification than this for implementation and testing. The vehicle for the syntax of the programming language is the grammar.
Formalism for specifying the syntax of a programming language
The elements of a language, for example, keywords, identifiers, strings, numbers, and operators, are called tokens. In this sense, a program is a sequence of tokens, and the grammar specifies which sequences are...