github.com/lukasmalkmus/spl (go): Package spl provides a complete compiler toolchain for a simple programming language (SPL). Its (german) specification can be reviewed here: https://homepages.thm.de/~hg52/lv/compiler/praktikum/SPL-1.2.html  SPL ("Simple Programming Language") is a simple procedural programming language. It contains a predefined primitive type for integers and a type constructor for fields. SPL also uses logical values, but variables of this type cannot be created, nor can there be literals of this type.  SPL knows procedures (but no functions), both with value parameters and with reference parameters. Values of composite types must be passed as reference parameters. Procedures can define local variables. There are no global variables, nor are there nested procedure agreements.  You can use the conditional statement (single- and two-armed), the reject loop, the assignment, the call of a procedure, and the compound statement for statement sequences.  Expressions are constructed using integers. Six comparison operators, the four basic arithmetic operations and the negation are available. Parentheses allow any combination of partial expressions. Literals can be noted in different representations for the predefined type "integer".  Fields are indexed by integer expressions, both on the left and right sides of assignments or in argument expressions. Allowed index expressions return a value in the range 0...(n-1) if the field has n elements. Indexing a field outside this range causes a runtime error.  The runtime library provides procedures for entering and outputting whole numbers and individual characters on the text screen. It also provides a procedure for terminating a program immediately. Another procedure returns the time elapsed since the program was started. On the graphics screen, individual pixels, straight lines or circles can be drawn in any color. It is also possible to fill the whole graphic screen with any color.  At the end of this language definition there is an example program in which some of the possibilities of SPL are demonstrated.  A distinction is made between upper and lower case.  Spaces and horizontal tokens separate tokens, but have no other meaning for the program. Line breaks also count as spaces.  A comment is introduced by a double slash ("//") and extends to the end of the line in which it appears. It also separates tokens and has no meaning for the program. Example:  Identifiers consist of any number of letters, digits and underscores. You must start with a letter, where the underscore is considered as a letter. Example:  Numbers are formed by stringing decimal digits together. Alternatively, numbers can be specified in hexadecimal. They begin with the prefix "0x" and contain hexadecimal digits (0-9,a-f). The hexadecimal digits a-f can also be written in capital letters. A third alternative for the representation of numbers is the inclusion of exactly one character in apostrophes. The number shown is then the ASCII code of the character between the apostrophe. The character string \n is considered a character with the meaning "line break" (0x0a). Numbers must be in the range 0..2^31-1; the unary operator "-" is available for displaying negative numbers (see below). The interpretation of numbers that fall outside the specified range is undefined. Examples:  SPL contains the following reserved words that cannot be used as identifiers:  The following characters and character combinations have meaning:  ( ) [ ] { } = # < <= > >= := :  , ; + - * /  All non-permitted characters or character strings are recognized and rejected.  An SPL program consists of a collection of type and procedure agreements without a specific sequence. Identifiers for types must be agreed before they are used. This restriction does not apply to procedure identifiers so that mutually recursive procedures can be formulated.  At least one procedure agreement is required, namely that of the procedure with the specified name "main". This procedure has no parameters and is activated automatically when the program is started.  There is a predefined primitive type for integers ("int"). The identifier "int" is not a reserved word. It is considered implicitly agreed before all user declarations.  The data type constructor "array" constructs a field over a basic type. The field size is defined statically at the time of translation and is part of the type. The basic type can be any type. Examples:  A type agreement combines an identifier with a type. It has the following structure:  Then <name> can be used as an abbreviation for <type>. Examples:  Each type expression constructs a new type. Two types are the same if they were constructed using the same type expression. Example of the same types:  Example of different types:  A procedure agreement combines an identifier with a procedure. It has the following form:  The optional <parameter list> names the formal parameters of the Prodedur. Each parameter is specified in one of two forms:  or  The first form denotes a value parameter, the second form a reference parameter. The individual parameters are separated by commas in the list. The names of the parameters are valid until the end of the procedure. The optional <declarations> define local variables. Each declaration has the following form:  These names are also valid until the end of the procedure. You must not collide with a parameter name. It is possible to declare parameters or local variables with a name that already has a different meaning further outside, i.e. is a type or procedure name. This external meaning is hidden by the local meaning. The optional <statement list> consists of any number of statements. Examples:  Statements are used to achieve an effect (change state, side effect). There are six different instructions. The empty statement consists of only one semicolon and does nothing. The assignment has the form:  where <lhs> must be a variable of type int (indexed field variables are also allowed) and <rhs> an expression of the same type. At runtime, the right side is evaluated and assigned to the left side. Any expressions on the left side are evaluated before any expressions on the right side. Example:  The conditional statement can come in one of two forms:  where <expression> is an expression that returns a logical value and <statement1> or <statement2> is a statement. The statement behind an "else" belongs to the innermost "if", to which no "else" has yet been assigned. At runtime <expression> is evaluated. If it returns "true", the <statement1> is executed. If it returns "wrong", nothing else is done in the first form; in the second form, <statement2> is executed in this case. In any case, execution is continued with the statement following the "if" statement. Examples:  The reject loop is formulated as follows:  where <expression> is an expression that returns a logical value and <statement> is an instruction. At runtime <expression> is evaluated. If it returns "true", it is executed and the loop is executed again. If it returns "wrong", the statement following the "while" statement is continued. Example:  To make a statement sequence appear syntactically as a single statement, there is the compound statement. It consists of any number of statements (possibly not even a single one) that are enclosed in curly brackets. Example:  A procedure call is achieved by the following form:  The optional <argument list> is a comma-separated list of expressions whose number and types must match the number of parameters and their types in the procedure agreement. At runtime, the argument expressions are evaluated from left to right and then the procedure is activated. Only variables (simple variables or field variables) can appear in the argument list for reference parameters, whereas any expressions are permitted for value parameters. Fields must be passed as reference parameters. After the procedure has been executed, the execution returns after the procedure call. Example:  Expressions are used to calculate values. The values are either integer values or truth values.  The four basic arithmetic operations with the usual precedents and associativities are available for calculating integer values. The unary minus is also available; it binds more strongly than multiplication.  The six relational operators are <, <=, >, >=, = and # (not equal). They compare the values of two integer expressions and return a logical value. They bind weaker than the addition. There are no operators available for combining Boolean values.  At any point of an expression, parentheses can be used to override the built-in precedents and associativities.  The operands of an expression are other expressions, and ultimately literals or variables. The latter are either simple variables or indexed field variables. A field is indexed by an expression with an integer value in square brackets after the field variable. Operations with one field as a whole are not allowed (except passing the whole field as a reference).  At runtime, for all expressions with two operands, first the left and then the right operand are evaluated; the operation is then executed. Examples:  Displays the value of i on the text screen:  Outputs the character with the ASCII code i on the text screen:  Reads an integer from the keyboard and stores it in i. The input is buffered line by line with echo:  Reads a character from the keyboard and saves its ASCII code in i. Input is unbuffered and without echo:  Ends the running program and does not return to the caller:  Returns in i the time in seconds since the program was started:  Clears the graphics screen with the color. Colors are formed by specifying the R, G and B components according to the pattern 0x00RRRGGBB. The values 0...255 are therefore available for each component:  Sets the pixel with coordinates x and y to color. Limits: 0 <= x < 640, 0 <= y < 480:  Draws a straight line from (x1|y1) to (x2|y2) with the color. Limits like setPixel:  Draws a circle around the center (x0|y0) with radius radius and color:  The following small SPL program calculates solutions to the well-known "Eight Queens Puzzle":
Keywords: simple-programming-language|spl|university|university-project