miniC is a case sensitive language and all keywords are in lowercase.
Identifiers are terminals used for naming functions and variables, they
can consist of alphanumeric characters and underscores but they must not
begin with a digit. Since miniC is case sensitive, foo
and FOO
are
treated as distinct identifiers.
Keywords are special sequences used as a part of the language itself. The following keywords are reserved in miniC:
if
else
for
integer
bool
float
char
while
The language will contain the following primitive data types:
In order to reduce diversity of data types, we introduce only one data type per format.
We assume that maximum input while testing an algorithm would be
10^18 but the calculation can involve multiplication so maximum
value can be 10^36. There is only one data type called integer
which is 128-bit wide and stores signed numbers.
Integers would also support bitwise boolean operations such as and
,
or
, xor
, not
by using words themselves in lowecase as the operator
name.
We would also need floating point numbers, we call this data type
float
and it would store floating point numbers in the IEEE format.
This would correspond to a long double
in C.
Arithmetic operations can be done by using their respective symbols, +
for addition, -
for subtraction, *
for multiplication and /
for
division.
Operator | Note |
---|---|
+ ,- |
Unary Operators |
* ,/ ,mod |
Multiplicative Group |
+ ,- |
Additive Group |
We call this data type bool
that stores only true
or false
values.
This data type would also support boolean operations such as and
,
or
, xor
, not
by using words themselves in lowecase as the operator
name.
We call this data type char
which stores UTF-8 8-bit wide characters,
capable of supporting most languages.
Fixed-size arrays could be declared by appending size in square brackets
([SIZE]
) at the end of the data type itself. Note that this is
different from C/C++ where []
are appended at the end of the
identifier. For example, int a[100]
in C/C++ would be integer[100] a
. 2-D arrays could also be declared similarly like integer[100][100] b
.
The control statements could be used to make decisions.
if(x > 0) {
// Code block enclosed in curly braces
x = 3;
}
The if
command is followed by parentheses, which contain the
comparison that the if keyword tests. The comparison should result in a
bool
output. The statements that follow if the comparison is true are
enclosed in the curly braces. It can be referred to as a code block.
We introduce the else
keyword for this. The else
keyword is a
second, optional part of an if
cluster of statements. It groups
together statements that are to be executed when the condition that if
tests for isn’t true.
if(x > 0) {
// Code block enclosed in curly braces
x = 3;
} else {
x = -3;
}
Similar, to the if-then-else there is an inline alternative called the
Ternary Operator. It is of the form condition ? option1 :option2
where the result of the operator is option1
if the condition is true
and option2
otherwise.
A loop repeats a code block certain number of times or until a condition is true.
The for
-loop is generally used for repeating a code several times in
conjunction with a counter. The for
keyword defines a starting
condition, an ending condition, and the statement that is run on while
the loop is being executed over and over.
for(starting; while_true; do_this)
statement;
Similar to the for
-loop, the while
-loop also repeats a block of code
several times. However, it only comes with one conditional statement
while(condition)
statement;
A function can be declared by specifying the return type, the name of the function and arguments in parenthesis preceded by their respective data types. A function declared without a return type returns nothing.
integer foo(integer x, integer y) {
// statements
return x+y;
}
The program consists of two parts: preamble and main.
The preamble consists of headers that tell the compiler which library to import (we assume that the miniC language has similar libraries as C) and contain function definitions.
The main section is written inside the function main()
which can
optionally take two arguments, first the count of command line arguments
and second the respective arguments. Its return type is integer
, the
exit code of the program. When a program starts its execution it
executes the code inside the main()
function.
-
The program must contain exactly one
main()
function which must return an exit code. -
A variable must be explicitly declared in the same context before being referred.
-
Check for ambiguity such as the Dangling Else
-
Anytime the index of an array is accessed the index must be of type
integer
. -
All the included header files must exist in the current system.
- This programming language is designed to be similar to C but has a
few modifications to make it more suitable for quick problem
solving such as testing algorithms etc. In order to do this, there
is less diversity of data types (like
int
,unsigned int
,int64_t
etc.) so that the programmer can focus on the logic of the code.