Commit cb1b8a02 authored by Pierre Brandone's avatar Pierre Brandone
Browse files

compiler_stages: tc_1 updated

* source/compiler_stages/tc_1/code_to_write.rst,
* source/compiler_stages/tc_1/faq.rst,
* source/compiler_stages/tc_1/improvements.rst: Here.
parent 55d0c791
......@@ -24,14 +24,11 @@ Makefile.am
to :code:`make check`.
src/parse/scantiger.ll
The scanner must be completed to read strings, identifiers, etc. and
track locations.
Complete scanner
The scanner must be able to scan inputs as described in
:ref:`Lexical Specifications` and :ref:`Additional Lexical Specifications`.
- If the environment variable :code:`SCAN` is defined (to whatever value)
Flex scanner debugging traces are enabled, i.e. set the variable
:code:`yy_flex_debug` to 1.
- Strings will be stored as C++ :code:`std::string`. See the following
Strings will be stored as C++ :code:`std::string`. See the following
code for the basics.
.. code-block:: none
......@@ -51,10 +48,19 @@ src/parse/scantiger.ll
...
}
- Symbols (i.e. *identifiers*) must be returned as :code:`misc::symbol`
Symbols (i.e. *identifiers*) must be returned as :code:`misc::symbol`
objects, not strings.
- The locations are tracked. The class :code:`Location` to use is produced
Be carefull, metavariable keywords should only be scanned when extensions
are enabled, i.e. not on direct user input.
Trace the lexing
If the environment variable :code:`SCAN` is defined (to whatever value)
Flex scanner debugging traces are enabled, i.e. set the variable
:code:`yy_flex_debug` to 1.
Location tracking
The locations are tracked. The class :code:`Location` to use is produced
by Bison: :file:`src/parse/location.hh`.
To track locations, adjust your scanner, use :code:`YY_USER_ACTION` and
......@@ -75,21 +81,29 @@ src/parse/scantiger.ll
%%
src/parse/parsetiger.yy
- The grammar must be complete but without actions.
- Use :code:`%skeleton "lalr1.cc"` to have Bison generate a LALR(1) parser.
- Use :code:`%expect 0` to have Bison report conflicts are genuine errors.
- Use the environment variable :code:`PARSE` to enable parser traces, i.e.
Complete parser
The parser must be able to parse tokens as described in
:ref:`Syntactic Specifications` and
:ref:`Additional Syntactic Specifications` and must not produce comportment
yet.
GLR parser
Use :code:`%skeleton "glr.cc"` and use the :code:`%glr-parser` directive to
have Bison generate a GLR parser. Thanks to GLR, conflicts (S/R and/or R/R)
can be accepted. Use :code:`%expect` and :code:`%expect-rr` to specify
their number. For information, we allow zero R/R conflicts, and one
S/R related to the "big lvalue" issue.
Trace the parsing
Use the environment variable :code:`PARSE` to enable parser traces, i.e. \
to set :code:`yydebug` to 1, run:
.. code-block:: none
PARSE=1 tc foo.tig
- Use :code:`%printer` to implement :code:`--parse-trace` support for
terminals (see :ref:`TC-1 Samples`). For instance,
Use :code:`%printer` to implement :code:`--parse-trace` support
for terminals and non terminals (see :ref:`TC-1 Samples`). For instance,
.. code-block:: none
......@@ -97,6 +111,12 @@ src/parse/parsetiger.yy
%token <int> INT "integer"
%printer { yyo << $$; } <int>
Error recovery
There should be at least three uses of the token error. Read the Bison
documentation about it. Use :code:`%destructor` to reclaim the memory bound
to semantic values thrown away during error recovery.
src/parse/tiger-parser.cc
The class :code:`TigerParser` drives the lexing and parsing of input file.
Its implementation in :file:`src/parse/tiger-parser.cc` is incomplete.
......
......@@ -19,10 +19,9 @@ Translating escapes in the scanner (or not)
You must check for bad escapes whatever solution you choose (see
:ref:`Lexical specifications`).
What is this :code:`chunks` rule? And where is the :code:`decs` one?
What is the :code:`chunks` rule?
In the given code, we specify that a program is either :code:`exps` or
:code:`chunks`, whereas the reference grammar states that a program is either
:code:`exps` or :code:`decs`.
:code:`chunks`.
In the Tiger language, a *chunk* is a set of declarations which work as a
group, and must be processed together during static analysis. These can be
......@@ -31,21 +30,6 @@ What is this :code:`chunks` rule? And where is the :code:`decs` one?
method is to directly parse the declaration chunks, which is what we chose to
do in our implementation.
Chunks only have to be handled starting from |COMPILER|-2, so for now you can
consider that the :code:`chunks` rule in :file:`parsetiger.yy` is an alias for
the :code:`decs` rule of the grammar.
Must lexical and syntactic extensions be implemented?
No. Language extensions (see :ref:`Language Extensions`) such as
metavariables keywords (:code:`_chunks`, :code:`_exp`, :code:`_lvalue`,
:code:`_namety`) and casts (:code:`_cast`) are not required until
|COMPIlER|-2.
Handling metavariables constructs becomes mandatory at |COMPILER|-2
(:ref:`TC-2 Code to Write`) where they are used within TWEASTs (Text
With Embedded AST), while casts are only
needed for the optional bounds checking assignment (:ref:`TC-B`).
What values can be represented by an :code:`int`?
The set of valid integer values is the set of signed 32-bit integers
in two's complement, that is the integer interval :math:`[-2^{31},
......
......@@ -9,18 +9,17 @@ configure.ac
Customize your compiler’s version and group’s name in the `AC_INIT` macro at
the start of the `configure.ac`.
Using :code:`%destructor`
You may use :code:`%destructor` to reclaim the memory lost during the
error recovery. It is mandatory in |COMPILER|-2, see :ref:`TC-2 FAQ`.
Handling object-related constructs
Your scanner and parser are not required to support OO constructs but
you can implement them in your LALR(1) parser if you want (fully
supporting them at TC-2 is highly recommended though, during the
conversion of your LALR(1) parser to a GLR one).
Your scanner and parser are not required to support OO constructs, but
you are encouraged to do so because it will be the basis for later interesting
object bonuses.
Object-related productions from the :ref:`Syntactic Specifications`:
.. literalinclude:: objects
:language: ebnf
Be carefull, you should only allow OO constructs when object extensions
is enabled (:code:`-o | --object`).
Supports Markdown
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