Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vcalc/impl/assertions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ specification particulars.

**expression-size**:

All expressions will result in a value that will fit in 32 signed
bits. This means the result of an expression can be anywhere in the
Every integer an expression produces, including each vector element,
will fit in 32 signed bits. This means the result of an expression can be anywhere in the
range :math:`[-2^{31}, 2^{31} - 1]` or :math:`[-2147483648, 2147483647]`.
Any operation that results in underflow or overflow
will render the input invalid. For example, the following tests would
Expand Down
30 changes: 27 additions & 3 deletions vcalc/impl/clarifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ specification without cluttering it.
Empty input should result in empty output. This is in keeping with
all of the output rules defined. There are no ``print``
:term:`statements <statement>` so
there would be no numbers, newlines or output of any kind. All that
you are left with is a single empty line, which matches "*should* be
an empty line at the end of your output".
there would be no numbers, newlines or output of any kind.

#.

Expand Down Expand Up @@ -116,3 +114,29 @@ specification without cluttering it.

[1]

#.

.. _clarify:int-div:

.. container::
:name: int-div

**int-div**:

Division is integer division. This means that any decimal portion of
a division operation result is truncated (not rounded). No extra work
is required: this is the default in C++, RISC-V, ARM, and X86. For
example:

::

print(5 / 3);
print((0 - 5) / 3);

produces the following output:

::

1
-1

20 changes: 0 additions & 20 deletions vcalc/impl/output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,3 @@ output file should be overwritten if it already exists.
The output of your compiler is the *LLVM IR* that corresponds to the given
input program. The output file can be used as input to ``llc``, for example,
which compiles *LLVM IR* input into assembly language for a specified machine.

Program Output
==============

Output content is standardized to ensure everyone can pass everyone’s
tests. Follow these specifications:

- Each number printed should be on its own line followed by a new line.

- There *must* be a new line after each ``print`` statement’s printed
value.

- There *must not* be any trailing space after the final number and
before the newline.

- There *must* be an empty line at the end of your output.

**Clarification:** Empty input should result in empty output.
(:ref:`empty-input <clarify:empty-input>`)

40 changes: 40 additions & 0 deletions vcalc/spec/booleans.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Booleans
--------

In this assignment, booleans can only be produced using comparison
operators, there is no :term:`literal` to express them. As well, they are
ephemeral: there is no way to store them. They can only exist when
created using one of the comparison operators.

When printed, booleans take on a value of 1 (true) or 0 (false). For
example:

::

print(1 == 1);
print(1 == 0);

produces the following output:

::

1
0

As well booleans *are* usable in :term:`expressions <expression>` and must
undergo :term:`type promotion` to an integer. This means if a boolean is
used in an arithmetic expression it takes on the integer value described
above. For example:

::

print(1 + (1 == 1));
print(1 + (1 == 0));

produces the following output:

::

2
1

18 changes: 13 additions & 5 deletions vcalc/spec/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Valid formats for expressions are

(<expr>)
<expr> <op> <expr>
<expr>[<expr>]
[<id> in <expr> | <expr>]
[<id> in <expr> & <expr>]
<int>
<id>

Expand All @@ -16,8 +19,9 @@ Valid formats for expressions are

- ``id`` is the identifier of a variable.

| **Assertion:** All expressions will result in a value that fits in a
32 bit signed integer. (:ref:`expression-size <assert:expression-size>`)
| **Assertion:** Every integer an expression produces, including each
vector element, fits in a 32 bit signed integer.
(:ref:`expression-size <assert:expression-size>`)
| **Assertion:** No expression will contain a division by 0.
(:ref:`zero-divide <assert:zero-divide>`)

Expand Down Expand Up @@ -61,6 +65,9 @@ For example, addition and subtraction have an equal level of precedence.
| | is not equal | ``!=`` | ``expr != expr`` | left |
+------------+----------------+------------+------------------+-------------------+

| **Clarification:** Division is integer division.
(:ref:`int-div <clarify:int-div>`)

Binary Operations on Vectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -196,15 +203,16 @@ Vector Indexing
Vectors can be indexed by a scalar to produce the integer value at a
specified index. Vectors in *VCalc* are *zero indexed*. As well,
indexing outside of the bounds of a vector (e.g. ``v[i]`` where
:math:`0 <= |v| < l` and :math:`i < 0` or :math:`i >= l`) is *not an
:math:`|v| = l` and :math:`i < 0` or :math:`i >= l`) is *not an
error*. An index out of bounds *always returns zero*.

Index domains must be vectors:

- Domain can be an :term:`identifier` for a vector.

- Domain can be the result of a range, generator, filter, or another
index expression with a vector index (see below).
- Domain can be the result of a range, generator, filter, binary
operation with a vector operand, or another index expression with a
vector index (see below).

- Domain cannot be an integer. For example, this is :term:`ill-formed`:

Expand Down
6 changes: 3 additions & 3 deletions vcalc/spec/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ The identifier and vector are still called the
:term:`iterator variable` and domain vector, however, the
right-hand-side :term:`expression` is now called the *predicate*.
The iterator variable is an integer typed variable defined only in
the scope of the generator.
the scope of the filter.

As in a generator, the :term:`domain` may be any vector-valued
expression which includes identifiers (that are vector typed),
ranges, generators, filters, and index expressions with a vector
index. The predicate must evaluate to a boolean. This means that if
ranges, generators, filters, index expressions with a vector
index, and binary operations with a vector operand. The predicate must evaluate to a boolean. This means that if
the result of the expression is an integer it will undergo an
:term:`implicit conversion` to a boolean, but a vector result is an
*error*.
Expand Down
5 changes: 3 additions & 2 deletions vcalc/spec/generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ right-hand-side expression. The iterator variable is an integer typed
variable defined only in the scope of the generator.

The domain may be any vector-valued expression which includes
identifiers (that are vector typed), ranges, generators, filters, and
index expressions with a vector index. The expression must evaluate to
identifiers (that are vector typed), ranges, generators, filters,
index expressions with a vector index, and binary operations with a
vector operand. The expression must evaluate to
an integer. This means that if the result of the expression is a boolean
it will undergo :term:`type promotion` to an integer, but a vector
result is an *error*.
Expand Down
28 changes: 28 additions & 0 deletions vcalc/spec/identifiers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Identifiers
-----------

For the purpose of this assignment, identifiers are simple. They must
start with an alphabetical character. This character may be followed by
numbers or alphabetical characters. A keyword cannot be used as an
identifier.

Examples of valid identifiers:

::

hello
h
h3llo
Hi
h3

Examples of invalid identifier:

::

3d
a-bad-variable-name
no@twitter
we.don't.like.punctuation
or_spelling

50 changes: 50 additions & 0 deletions vcalc/spec/integers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Integers
--------

In this assignment, integers are the *only* numerical :term:`type` (there
is no floating point type).

In this assignment integer :term:`literals <literal>` are defined as
being a string that contains only the numerals 0-9 with no spaces.

| **Assertion:** All integer literals will be :math:`\geq 0`.
(:ref:`nonnegative-literals <assert:nonnegative-literals>`)
| Examples of valid integers:

::

1
123
5234
01
10

Examples of invalid integers:

::

1.0
one
1_1
1o

As well, integers *are* usable in conditions and must undergo
:term:`implicit conversion` to booleans. This means in a condtional, an
integer that *is not* zero will be considered true and an integer that
*is* zero will be considered false. For example:

::

if (999)
print(999);
fi;
if (0)
print(0);
fi;

produces the following output:

::

999

4 changes: 1 addition & 3 deletions vcalc/spec/statements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ following form:

- ``expr`` is an expression.

There are a few new important points when dealing with assignments.
There are a few important points when dealing with assignments.

#. The size of a vector may change while the program is executing if a
vector variable is assigned another value. For instance, the
Expand Down Expand Up @@ -231,8 +231,6 @@ tests. Follow these specifications:
- There *must not* be any trailing space after printed value and before
the newline.

- There *must* be an empty line at the end of your output.

- There *must not* be spaces between the first and last number and the
accompanying brackets in a vector.

Expand Down
6 changes: 3 additions & 3 deletions vcalc/spec/vectors.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Vectors
-------

*VCalc* has a new :term:`type`, ``vector``, that is a vector of integer values.
*VCalc* has a :term:`type`, ``vector``, that is a vector of integer values.
Vectors are restricted to the length that can be represented by the
*largest possible index*. Indices are integers and integers are signed
32 bit integers. Because the largest possible integer is
Expand All @@ -12,8 +12,8 @@ the range :math:`[0, 2^{31}-1]`.
:math:`0 \leq l \leq 2^{31}-1`. (:ref:`vector-length <assert:vector-length>`)

There is no way to specify a vector literal, they must be created
through ranges, generators, filters, or index expressions with a vector
index.
through ranges, generators, filters, index expressions with a vector
index, or binary operations with a vector operand.

The only way to create an empty vector is through the use of a filter
whose predicate is evaluated to false at each index of the :term:`domain`
Expand Down
Loading