Skip to content
Abdelrahman Aly Abounegm edited this page Oct 10, 2020 · 2 revisions

Frequently Asked Questions

For anything not listed below and not clear in the document, just assume a reasonable solution and mention it in the presentation.

if statement's condition

The grammar specifies that it can be any Expression, which includes real and integer. What to do?

Convert the expression to a boolean using the normal casting rules.

Expression in Range

The grammar defines the range as Range :: Expression '..' Expression. What if the expression is a boolean or a real number?

Convert the expresion to an integer using the normal casting rules.

So is x=4..3+1 a valid range?

Yes. Depending on the value of x, it will be equivalent to either 0..4 or 1..4.

[not] IntegerLiteral

What does [not] IntegerLiteral in the grammar mean, and why is it not BooleanLiteral?

I am not sure, but it is a mistake. You can use not with booleans, and integers can be cast to booleans.

reverse invalid range

What would be the range expressed by reverse x..y, where x > y?

The range is evaluated first before the reversing. A Range where the first number is larger is an empty range. Consider the examples below:

Range Values taken by loop variable (in order)
2..5 [2, 3, 4, 5]
5..2 []
reverse 2..5 [5, 4, 3, 2]
reverse 5..2 []

Routine with no params

Is it possible to define a routine without any parameters?

Yes. There is a mistake in the grammar. Just declare a routine as normal and keep the parentheses empty.

Assigning integer to boolean

What kind of error should assigning an integer (that is not 0 or 1) throw?

A run-time error, as it cannot be detected in compile-time.

Types do not exist in run-time

Whenever such an assignment is detected, inject some code into the compiled program that detects for erroneous assignment.

Garbage collection

If user-defined types are assigned by reference, this can leave objects without a reference

Either implement garbage collection or just let the memory leak.

Variable/Type redeclaration

Can variables or types be redeclared?

Variables and types cannot be redeclared in the same scope. Declarations with the same name can only occur in different scopes, and the nested scope shadows the outer one.