Skip to content
2 changes: 1 addition & 1 deletion gazprea/impl/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ name mangling that occurs to allow class functions. Thus, we recommend
that all runtime functions should be written in C and not in C++. There
is a Makefile in the ``runtime`` folder designed to turn all ``*.c`` and
``*.h`` pairs into part of the unified runtime library ``libruntime.a``.
An example of how to make a runtime function is provided bellow.
An example of how to make a runtime function is provided below.

``functions.c``

Expand Down
23 changes: 11 additions & 12 deletions gazprea/impl/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ new errors. Your compiler is only expected to report the first error it
encounters.

Syntax Errors
~~~~~~~~~~~~~
-------------

ANTLR handles syntax errors automatically, but you are required to override the
behavior and throw the ``SyntaxError`` exception from
Expand Down Expand Up @@ -80,7 +80,7 @@ Here are the compile-time errors your compiler must throw:
* ``TypeError``

Raised during compilation if an operation or statement is applied to or
betweeen expressions with invalid or incompatible types.
between expressions with invalid or incompatible types.

* ``AliasingError``

Expand All @@ -102,7 +102,7 @@ Here are the compile-time errors your compiler must throw:

Raised during compilation if the program detects a function or procedure
with a return value that does not have a return statement reachable by all
control flows. Control flow constructs may be assumed to always be undecideable,
control flows. Control flow constructs may be assumed to always be undecidable,
meaning they may branch in either direction.

If the subroutine has a ``return`` statement with a type that does not
Expand Down Expand Up @@ -146,7 +146,7 @@ Here are the compile-time errors your compiler must throw:
* ``MathError``

May be raised during compile time expression evaluation when division by zero occurs.
Conditions for raising are eqivalent to a runtime ``MathError``.
Conditions for raising are equivalent to a runtime ``MathError``.

* ``IndexError``

Expand All @@ -155,10 +155,9 @@ Here are the compile-time errors your compiler must throw:

* ``SizeError``

May be aised during compilation if the compiler detects an operation or statement
May be raised during compilation if the compiler detects an operation or statement
is applied to or between arrays with invalid or incompatible
sizes. Read more about when a ``SizeError`` should be raised at run-time
instead of compile-time in the :ref:`ssec:errors_sizeErrors` section.
sizes.

* ``StrideError``

Expand Down Expand Up @@ -190,7 +189,7 @@ Run-time errors must be handled by calling the functions defined in
The runtime errors listed below are a subset of compile time errors. Since it is not only impractical,
but undecidable to catch the following errors exclusively at compile time, Gazprea leaves the setting
at which they are raised up to the implementation. To put simply, you can raise runtime errors either
at compile time or at runtime and the tester will accomodate to different implementations.
at compile time or at runtime and the tester will accommodate different implementations.

* ``SizeError``

Expand All @@ -213,7 +212,7 @@ at compile time or at runtime and the tester will accomodate to different implem
``<=0``.

Here is an example invalid program. If your compiler is smart, you may raise the later error, if you
perfer not to implement static analysis, the former error can be emited at runtime.
prefer not to implement static analysis, the former error can be emitted at runtime.

::

Expand All @@ -240,12 +239,12 @@ More Examples
character[3] v = ['a', 'b', 'c']; // Indexing is harder than it looks!
integer i = 10;
v(3) = 'X'; // SyntaxError
v[i] = '?'; // Run-timeerror
v[i] = '?'; // Runtime error
v['a'] = '!'; // TypeError
i[1] = 1; // SymbolError

/* Tuples */
tuple (integerm integer) a = (9, 5);
tuple (integer, integer) a = (9, 5);
integer b;
integer c;
integer d;
Expand Down Expand Up @@ -312,7 +311,7 @@ Additionally, the tester only knows to stop the toolchain prematurely if your pr
terminates with a non-zero exit code. Once you have caught an error make sure to return
a non-zero exit code.

Finally, the tester is lenient towards the type given to a particular errror. Specifically
Finally, the tester is lenient towards the type given to a particular error. Specifically
the tester simply confirms that the substring "Error" is present and for compile
time errors that the correct line is provided.

Expand Down
2 changes: 1 addition & 1 deletion gazprea/impl/part_1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Compiler Implementation — Part 1
This section lists the portions of the *Gazprea* specification that must
be implemented to complete the part 1 of the compiler implementation.
All developers are advised to read the full specification for the
language prior to start the implementation of Part 1 because decisions
language prior to starting the implementation of Part 1 because decisions
made while implementing Part 1 can make the implementation of Part 2
significantly more challenging. Thus, planning ahead for Part 2 is the
recommended strategy.
Expand Down
2 changes: 1 addition & 1 deletion gazprea/impl/part_2.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Compiler Implementation — Part 2
================================

This section list the elements of the *Gazprea* specification that must
This section lists the elements of the *Gazprea* specification that must
be completed for the Part 2 of the compiler implementation. All the
elements of Part 1 must have been completed because Part 2 builds on
Part 1.
Expand Down
1 change: 1 addition & 0 deletions gazprea/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Hardware Acceleration Laboratory in Markham, ON.

spec/keywords
spec/identifiers
spec/namespaces
spec/comments
spec/declarations
spec/type_qualifiers
Expand Down
6 changes: 3 additions & 3 deletions gazprea/spec/built_in_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ reversed version of it.
integer[*] v = 1..5;
integer[*] w = reverse(v);

v -> std_output; /* Prints 12345 */
w -> std_output; /* Prints 54321 */
v -> std_output; /* Prints [1, 2, 3, 4, 5] */
w -> std_output; /* Prints [5, 4, 3, 2, 1] */

.. _ssec:builtIn_format:

Expand Down Expand Up @@ -95,7 +95,7 @@ implicitly defined in every file:

procedure stream_state(var input_stream) returns integer;

This function can only be called with the ``std_input`` as a parameter, but it’s
This procedure can only be called with the ``std_input`` as a parameter, but it’s
general enough that it could be used if the language were expanded to include
multiple input streams.

Expand Down
2 changes: 1 addition & 1 deletion gazprea/spec/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ commas, such as in matrix generators.
/* The "i"s both domain expressions are at the same scope, which is
* the one enclosing the loop. Therefore the matrix is: [[0 0 0] [0 1 2] [0 2 4]]
*/
integer[3,3] mat = [ i in 0..i, j in 0..i | i*j ];
integer[3][3] mat = [ i in 0..i, j in 0..i | i*j ];

The domain for the domain expression is only evaluated once. For
instance:
Expand Down
11 changes: 3 additions & 8 deletions gazprea/spec/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Like Rust, array *slices* may be passed as arguments:

Remember that all function parameters are ``const`` in *Gazprea*, so that all
functions are pure. That means that while it is legal to pass arrays and slices
*be reference*, the array contents cannot be modified inside the function,
*by reference*, the array contents cannot be modified inside the function,
because the change would be visible outside the function. You must check that
the ``const`` requirement is honored.

Expand All @@ -211,10 +211,5 @@ In *Gazprea* function declarations occur in the global scope.
This means that two functions with the same name cannot coexist in the same
gazprea program, nor can you forward declare the same function twice.

Additionally, functions share the following namespaces:

- The ``struct`` namespace: you cannot have a struct and function with the same
name in the same gazprea program.

- The ``procedure`` namespace: You cannot have a procedure and function with
the same name in the same gazprea program.
Additionally, functions and procedures share the same namespace; you cannot
declare a function and procedure with the same name
4 changes: 2 additions & 2 deletions gazprea/spec/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Globals
=======

Valid global scope statements inclulde:
Valid global scope statements include:

* Variable Declarations
* Struct Declarations
Expand All @@ -15,7 +15,7 @@ All global statements are considered declarations. Global statements may occur
in any order, given respective symbols are defined before being referenced.

Variable Declarations
=====================
---------------------

In *Gazprea* values can be assigned to a global identifier. All globals
must be immutable (``const``). If a global identifier is declared with
Expand Down
30 changes: 0 additions & 30 deletions gazprea/spec/identifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,3 @@ a number, contain invalid characters, or are a keyword:

*Gazprea* imposes no restrictions on the length of identifiers.

.. _ssec:namespace:

Namespaces
==========

Identifiers are used by variables, user-defined types, functions and procedures.

For the most part, user-defined types are in their own namespace because their
usage does not collide with variables or functions.
The one exception is that struct literals can look like function calls:

::

struct A (integer i, real j);
A a = A(i, j);

Consequently, struct literals and functions share the same namespace.
In the above example, a definition of function ``A`` should generate a
``SymbolError``, but a definition of variable ``A`` would not.
Outside of types, variables and functions/procedures share the same namespace
in a scope and shadowing is possible between these types.

::

function x() returns integer; // "x" refers to this function in the global scope

procedure main() {
integer x = 3; // "x" refers to this variable in the scope of main
}
...
42 changes: 42 additions & 0 deletions gazprea/spec/namespaces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. _sec:namespaces:

Namespaces
==========

There are two namespaces in *Gazprea*:

- Type namespace: user-defined types (structs and typealiases).
- Variable/Function/procedure namespace: functions and procedures.

Items in separate namespaces may share an identifier. Items within the same namespace cannot share an identifier, this is a ``SymbolError``.

::

// Does not conflict with the other statements
struct x (integer a, integer b);

// These three statements all confict with each other
// Any two of them in the same program produces a SymbolError
integer x = 3;
function x() returns integer;
procedure x() returns integer;

::

// Pro tip: write code that looks like this, employers love it

typealias integer a;
typealias integer main; // Procedure and type do not conflict
struct b (a b, a a, main main); // Struct field identifiers do not conflict with anything

procedure main() returns integer {

a a = 1; // type and variable do not conflict

b b = b(b: a, a: 2, main: 3);

if (true) { // New scope
a a = b.b // New `a` shadows the old `a`
}
return 0;
}
18 changes: 7 additions & 11 deletions gazprea/spec/procedures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ These procedures can be called as follows:
call increment(x); /* x == 13 */
call fibonacci(x,y); /* x == 21 and y == 34 */

It is only possible to call procedures in this way. Functions must
Only procedures may be called with ``call``. Functions must
appear in expressions because they can not cause side effects, so using
a function in a ``call`` statement would not do anything. *Gazprea*
should raise an error if a function is used in a ``call`` statement.
Expand Down Expand Up @@ -235,21 +235,17 @@ Array Parameters and Returns
value of procedures can have both explicit and inferred sizes.

Similarly, slices can be used whereever arrays are declared as parameters, and
unlike functions, array parameters in procedures can be ``var``.
unlike functions, array parameters in procedures can be ``var``, allowing arrays
and slices passed to a procedure to be modified (see :ref:`sssec:array_slices`).

.. _ssec:function_namespacing:
.. _ssec:procedure_namespacing:

Procedure Namespacing
--------------------
---------------------

In *Gazprea* procedure declarations occur in the global scope.
This means that two procedures with the same name cannot coexist in the same
gazprea program, nor can you forward declare the same procedure twice.

Additionally, procedures share the following namespaces:

- The ``struct`` namespace: you cannot have a struct and function with the same
name in the same gazprea program.

- The ``function`` namespace: You cannot have a procedure and function with
the same name in the same gazprea program.
Additionally, functions and procedures share the same namespace; you cannot
declare a function and procedure with the same name
14 changes: 7 additions & 7 deletions gazprea/spec/streams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Streams
=======

*Gazprea* has two streams: ``std_output`` and ``std_input``,
which are used for writting to `stdout` and reading from `stdin` respectively.
which are used for writing to `stdout` and reading from `stdin` respectively.


.. _ssec:output:
Expand Down Expand Up @@ -145,15 +145,15 @@ must be readable.

An ``integer`` from stdin can take any legal format described in the
:ref:`integer literal <sssec:integer_lit>` section. It may also be preceded by
a single negative or positive sign. All preceeding whitespace before the number or
a single negative or positive sign. All preceding whitespace before the number or
sign character may be skipped up to the limit imposed by the 512 byte read restriction.

A ``real`` input from stdin can take any legal format described in the
:ref:`real literal <sssec:real_lit>` section with the exception that no
whitespace may be present. It may also be proceeded by a single negative or
positive sign. Preceeding whitespace may be skipped in the same way as integers.
whitespace may be present. It may also be preceded by a single negative or
positive sign. Preceding whitespace may be skipped in the same way as integers.

A ``boolean`` input from stdin is either ``T`` or ``F``. Preceeding whitespace may be
A ``boolean`` input from stdin is either ``T`` or ``F``. Preceding whitespace may be
skipped in the same way as integers and reals.

For the following program:
Expand Down Expand Up @@ -203,8 +203,8 @@ Reading a ``character`` can never cause an error. The character will either be
successfully read or the end of the stream will be reached and ``-1`` will be
returned on this read.

When an error occurs the the null value is assigned and the input stream
remains pointing to the same position as before the read occured.
When an error occurs the null value is assigned and the input stream
remains pointing to the same position as before the read occurred.

The program below demonstrates 4 reads which set the error
states 1,0,0,2 respectively.
Expand Down
2 changes: 1 addition & 1 deletion gazprea/spec/type_promotion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ converted to ``integer``.
Automatic type conversion follows this table where N/A means no implicit
conversion possible, id means no conversion necessary,
``as<toType>(var)`` means var of type "From type" is converted to type
"toType" using semantics from .
"toType" using semantics from :ref:`sec:typeCasting`.

+----------+-----------+---------+-----------+---------+---------------+
| | **To type** |
Expand Down
4 changes: 2 additions & 2 deletions gazprea/spec/typedef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ new name to refer to the old type. For instance:
typealias integer int;
const int a = 0;

Note that hese new type names can *appear* to conflict with symbol names.
Note that these new type names can *appear* to conflict with symbol names.
However, the compiler can use context to differentiate a type alias from a
symbol. The following is therefore legal:

Expand Down Expand Up @@ -64,7 +64,7 @@ Duplicate alias names should raise a `SymbolError`
Some type aliases may be parameterized with an expression, such as with arrays,
such expressions are restricted to be composed exclusively from arithmetic
operations on scalar literals. Practically speaking, this requires constant
folding but *not* constant propogation.
folding but *not* constant propagation.

::

Expand Down
Loading
Loading