Tag archive for "expressions"

Expressions are one of the core elements of Turbo Pascal. Expression is everything from variables, calculations, addresses or functions. Most of the code generated by Turbo Pascal comes from expressions. Therefore, expression processing needs a lot of functions and procedures that deal with all possible cases.

These routines provide basic expression processing. Each expression is divided into simpler elements according to the operator precedence: Expression, Simple Expression, Term and Factor. Once the operation and operands are determined, the mathematical operation can be performed.

Turbo Pascal expects different expression types depending on the context or language syntax. For this purposes there are many functions and procedures that¬†process expression¬†and report error if the expression doesn’t meet expectations.

This procedure converts expression between compatible types. For example, Integer values can be assigned to Real variables, only the expression and type need to be converted.

This procedure checks type compatibility between expression and specified type and sets expression to the specified type if needed.

This procedure extends integers to the new integer type.

Assembler expressions (instruction parameters) are processed similarly to Pascal expressions. The expression is divided into smaller parts according to the operator precedence. For assembler expressions Turbo Pascal uses few data structures and procedures. TAsmExpression contains fields that hold data for each expression (instruction parameter).

Turbo Pascal uses few functions and procedures to process, check and convert strings – Char type and zero-based character arrays can also be considered as strings.

Turbo Pascal sometimes needs to convert number types. Integer and Real can be used as Extended and Integer or Extended can be used as Real.

Turbo Pascal checks if values are within limits. If the value is constant it is immediately checked for lower and upper limit. If it is not constant and range checking is enabled, Turbo Pascal will generate range checking code. Botl limits will be stored in code and compiler procedure will be called to check range …

Turbo Pascal uses a very interesting way of dealing with boolean expressions. Each boolean expression contains a conditional opcode to jump if the expression evaluates to True and two linked lists of jumps. One list contains jumps to code which executes when the expression evaluates to True while the other list contains jumps to code …

Loading an expression into registers is a very common task in Turbo Pascal compiler. These two functions take care for this. They generate instructions to load the expression regardless where it is located.

During expression calculation Turbo Pascal stores the value in registers. However, they are limited and some operations can be performed only with specific registers. Therefore, Turbo Pascal compiler needs some way to save and restore expressions.

This procedure processes qualifiers: caret (^) to dereference pointers, period as separator for fields and brackets ([]) for arrays.

Calls to all procedures, functions and methods are processed from this procedure. It takes care for pushing all parameters and generates instruction to call the procedure.

This procedure processes both syntaxes for New as procedure or as function. It either allocates space in heap or calls constructor to create the object in heap.