Pascal¶
The ppci.lang.pascal module contains functionality to transform
pascal code into IR-code.
Warning
This module is a work in progress.
Module¶
Pascal front-end
-
class
ppci.lang.pascal.PascalBuilder(diag, arch_info)¶ Generates IR-code from pascal source.
-
build(sources)¶ Build the given sources.
Raises compiler error when something goes wrong.
-
do_parse(src, context)¶ Lexing and parsing stage (phase 1)
-
-
class
ppci.lang.pascal.Parser(diag)¶ Parses pascal into ast-nodes
-
add_symbol(sym)¶ Add a symbol to the current scope
-
do_coerce(expr: ppci.lang.pascal.nodes.expressions.Expression, to_type: ppci.lang.pascal.nodes.types.Type)¶ Try to convert expression into the given type.
expr: the expression value with a certain type typ: the type that it must be Raises an error is the conversion cannot be done.
-
enter_scope()¶ Enter a lexical scope.
-
get_common_type(a, b, loc)¶ Determine the greatest common type.
This is used for coercing binary operators. For example:
- int + float -> float
- byte + int -> int
- byte + byte -> byte
- pointer to x + int -> pointer to x
-
leave_scope()¶ Leave the current lexical scope.
-
parse_actual_parameter_list(parameter_types)¶ Parse a list of parameters
-
parse_binop_with_precedence(priority) → ppci.lang.pascal.nodes.expressions.Expression¶ Parse binary operators using a binding strength.
This is a neat trick to parse expressions without a whole bunch of similar looking functions for each operator. We use the concept of binding strength, or priority to group expressions according to operator precendence.
-
parse_block()¶ Parse a block.
A block being constants, types, variables and statements.
-
parse_builtin_procedure_call(func: str, location)¶ Do sort of macro expansion of built-in procedure call.
-
parse_case_of() → ppci.lang.pascal.nodes.statements.CaseOf¶ Parse case-of statement
-
parse_compound_statement()¶ Parse a compound statement
-
parse_constant_definitions()¶ Parse constant definitions.
This has the form:
- ‘const’
- ‘ID’ ‘=’ expr; ‘ID’ ‘=’ expr;
-
parse_designator()¶ A designator designates an object with a name.
-
parse_enum_type_definition()¶ Parse enumerated type definition.
This looks like:
colors = (red, green, blue)
-
parse_expression() → ppci.lang.pascal.nodes.expressions.Expression¶ Parse a an expression.
-
parse_expression_list()¶ Parse one or more expressions seperated by ‘,’
-
parse_for() → ppci.lang.pascal.nodes.statements.For¶ Parse a for statement
-
parse_formal_parameter_list()¶ Parse format parameters to a subroutine.
These can be immutable values, variables, or function pointers.
-
parse_function_declarations()¶ Parse all upcoming function / procedure definitions
-
parse_function_def()¶ Parse function definition
-
parse_id_sequence()¶ Parse one or more identifiers seperated by ‘,’
-
parse_if_statement()¶ Parse if statement
-
parse_one_or_more(parse_function, seperator: str)¶ Parse one or more occurences parsed by parse_function seperated by seperator.
-
parse_primary_expression() → ppci.lang.pascal.nodes.expressions.Expression¶ Literal and parenthesis expression parsing
-
parse_procedure_call(symbol, location)¶ Procedure call.
This can be either a builtin procedure, or a user defined procedure. Builtin procedure are somewhat magical in that they are sort-of-macro-expanded at compile time.
-
parse_program(context)¶ Parse a program
-
parse_record_fixed_list()¶ Parse fixed parts of a record type definition.
-
parse_record_type_definition(packed)¶ Parse record type description.
-
parse_record_variant()¶ Parse case .. of part.
-
parse_repeat()¶ Parses a repeat statement
-
parse_return() → ppci.lang.pascal.nodes.statements.Return¶ Parse a return statement
-
parse_single_variable_declaration()¶ Parse a single variable declaration line ending in ‘;’
-
parse_single_with_variable()¶ Parse a single with statement variable.
-
parse_source(tokens, context)¶ Parse a module from tokens
-
parse_statement() → ppci.lang.pascal.nodes.statements.Statement¶ Determine statement type based on the pending token
-
parse_type_definitions()¶ Parse type definitions.
These have the form:
‘type’ ‘ID’ ‘=’ type-spec ‘;’ ‘ID’ ‘=’ type-spec ‘;’ …
-
parse_type_spec(packed=False)¶ Parse type specification.
This can be any type, from record to ordinal or boolean.
-
parse_uses()¶ Parse import construct
-
parse_variable()¶ Parse access to a variable with eventual accessor suffixes.
-
parse_variable_access(symbol, location)¶ Process any trailing variable access.
-
parse_variable_declarations()¶ Parse variable declarations
-
parse_while() → ppci.lang.pascal.nodes.statements.While¶ Parses a while statement
-
require_boolean(expr)¶ Check the type of expression to be boolean, and raise an error if not.
-