reference manual: misc: language extensions and predefined entities

* source/reference_manual/language_extensions/additional_lexical_specifications/additional_lexical_specifications.rst,
* source/reference_manual/language_extensions/additional_lexical_specifications/additional_lexical_rules -> source/reference_manual/language_extensions/additional_lexical_specifications/reserved_id_rule,
* source/reference_manual/language_extensions/additional_semantics/additional_semantics.rst,
* source/reference_manual/language_extensions/additional_semantics/additionals -> source/reference_manual/language_extensions/additional_semantics/casts_examples,
* source/reference_manual/language_extensions/additional_syntactic_specifications/additional_syntactic_specifications.rst,
* source/reference_manual/language_extensions/additional_syntactic_specifications/additionals -> source/reference_manual/language_extensions/additional_syntactic_specifications/grammar_extensions,
* source/reference_manual/language_extensions/language_extensions.rst,
* source/reference_manual/predefined_entities/predefined_entities.rst,
* source/reference_manual/predefined_entities/predefined_functions/predefined_functions.rst,
* source/reference_manual/predefined_entities/predefined_types/predefined_types.rst: Here.
parent b24f99b1
......@@ -6,16 +6,19 @@ Additional Lexical Specifications
Additional keywords and identifiers.
'_cast'
:code:`_cast`
Used to cast an expression or a l-value to a given type.
'_decs', '_exp', '_lvalue', '_namety'
These keywords are used to plug an existing AST into an AST being built by the parser. There is a keyword per type of pluggable AST (list of declarations, expression, l-value, type name).
:code:`_decs`, :code:`_exp`, :code:`_lvalue`, :code:`_namety`
These keywords are used to plug an existing AST into an AST being
built by the parser. There is a keyword per type of pluggable AST
(list of declarations, expression, l-value, type name).
Reserved identifiers
They start with an underscore, and use the same letters as standard identifiers. These symbols are used internally by the compiler to name or rename entities. Note that **_main** is still a valid identifier, not a reserved one.
They start with an underscore, and use the same letters as standard
identifiers. These symbols are used internally by the compiler to
name or rename entities.
Note that **:code:`_main`** is still a valid identifier, not a reserved one.
.. literalinclude:: additional_lexical_rules
:language: ebnf
.. literalinclude:: reserved_id_rule
:language: ebnf
......@@ -4,18 +4,24 @@ Additional Semantics
====================
Casts
A _cast statement changes the type of an expression or an l-lvalue to a given type. Beware that the type-checker is forced to accept the new type as is, and must trust the programmer about the new semantics of the expression/l-value. Bad casts can raise errors in the next stages of the back-end, or even lead to invalid output code.
A :code:`_cast` statement changes the type of an expression
or an l-lvalue to a given type.
Beware that the type-checker is forced to accept the new type
as is, and must trust the programmer about the new semantics
of the expression/l-value. Bad casts can raise errors in the
next stages of the back-end, or even lead to invalid output code.
Casts work both on expressions and l-values. For instance, these are valid casts:
Casts work both on expressions and l-values. For instance,
these are valid casts:
.. literalinclude:: additionals
.. literalinclude:: casts_examples
:language: tiger
.. warning::
These examples could produce code with a strange behavior at
execution time.
(Although these examples could produce code with a strange behavior at execution time.)
Casts are currently only used in concrete syntax transformations inside the bounds checking extension and, as any language extension, are forbidden in standard Tiger programs.
Casts are currently only used in concrete syntax transformations
inside the bounds checking extension and, as any language extension,
are **forbidden** in standard Tiger programs.
......@@ -4,12 +4,20 @@ Additional Syntactic Specifications
===================================
Grammar extensions
In addition to the rules of the standard Tiger grammar (see :ref:`Syntactic Specifications`), extensions adds the following productions.
In addition to the rules of the standard Tiger grammar
(see :ref:`Syntactic Specifications`), extensions adds
the following productions.
.. literalinclude:: additionals
.. literalinclude:: grammar_extensions
:language: ebnf
Metavariables
The '_decs', '_exp', '_lvalue;, '_namety' keywords are used as metavariables, i.e., they are names attached to an (already built) AST. They don't create new AST nodes, but are used to retrieve existing nodes, stored previously. For instance, upon an _exp(51) statement, the parser fetches the tree attached to the metavariable 51 (an expression) from the parsing context (see the implementation for details).
The :code:`_decs`, :code:`_exp`, :code:`_lvalue`, :code:`_namety`
keywords are used as metavariables, i.e. they are names attached
to an **already built** AST. They don't create new AST nodes, but
are used to retrieve existing nodes, stored previously.
For instance, upon an :code:`_exp(51)` statement, the parser fetches
the tree attached to the metavariable 51 (an expression) from the
parsing context (see the implementation for details).
......@@ -3,7 +3,13 @@
Language Extensions
===================
Numerous extensions of the Tiger language are defined above. These extensions are not accessible to the user: if he uses one of them in a Tiger program, the compiler must reject it. They are used internally by the compiler itself, for example to desugar using concrete syntax. A special flag of the parser must be turned on to enable them.
Numerous extensions of the Tiger language are defined in the
following sections.
These extensions are not accessible to the user: if he uses
one of them in a Tiger program, the compiler must reject it.
They are used internally by the compiler itself, for example
to desugar using concrete syntax.
A special flag of the parser must be turned on to enable them.
......
......@@ -3,8 +3,8 @@
Predefined Entities
-------------------
These entities are predefined, i.e., they are available when you start the
Tiger compiler, but a Tiger program may redefine them.
These entities are predefined, i.e. they are available when you start the
Tiger Compiler, but a Tiger program may redefine them.
.. **Predefined Types**: Built-in types
......
......@@ -6,8 +6,8 @@ Predefined Functions
Some runtime function may fail if some assertions are not fulfilled.
In that case, the program must exit with a properly labeled error message,
and with exit code 120. The error messages must follow the standard.
Any difference, in better or worse, is a failure to comply with the
(**this**) Tiger Reference Manual.
Any difference, in better or worse, is a failure to comply with this
Tiger Reference Manual.
string: chr (code\: int)
| Return the one character long string containing the character which code is
......
......@@ -3,15 +3,15 @@
Predefined Types
----------------
There are three predefined types:
There are three predefined types in Tiger.
‘int’
which is the type of all the literal integers.
int
The type of all the literal integers.
‘string’
which is the type of all the literal strings.
string
The type of all the literal strings.
‘Object’
which is the super class type on top of every class hierarchy
(i.e., the top-most super class in the transitive closure of the
generalization relationship).
Object
The super class type on top of every class hierarchy
(i.e. the top-most super class in the transitive
closure of the generalization relationship).
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment