This project implements an interpreter for the IPLI language. I did this project in 2021 as an assignment in the course "Introduction to Programming". The interpreter consists of three main components:
- Tokenization – Handled in
tokenizer.c. - Parse Tree Construction – Handled in
parser.c. - Evaluation – Also handled in
parser.c.
The project consists of the following source files:
- Core implementation:
bcc.c,tokenizer.c,parser.c,varfun.c - Header files:
tokenizer.h,parser.h,varfun.h
To compile the project, run:
make ipliTo run tests, execute:
make testsThe interpreter can be executed using:
./ipli [-t] <iplfilename> [<arg1>] [<arg2>] ... [<argn>]- The
-tflag enables a custom random number generator. - The
-vflag cannot be used simultaneously with-t.
- The tokenizer processes an
.iplfile and stores each non-empty line in a struct Line array. - Each line contains a struct Token array representing different tokens (operators, variables, commands, etc.).
- The interpreter constructs a tree-based structure to execute commands.
- Each line corresponds to a node in the tree.
- Nodes have two pointers:
rightbro→ Points to the next node at the same indentation level.child→ Points to the first command insideif,else, andwhileloops.
- The first token of each node determines the command type.
- Each command has a dedicated function to handle its execution.
- If an error occurs,
print_error()prints an error message and terminates the program.
- Variables are stored in an array for efficient lookup (
O(1)). - New variable insertion takes
O(n). - Arrays are stored as tokens of type
kVariable. - Errors are raised if:
- A user redefines an existing array.
- A freed array is accessed without reinitialization.
✔ Break & Continue with arguments (break <n>, continue <n>)
✔ 1D Arrays & Nested Expressions (a[b[i]])
✔ Logical Operators (&&, ||)
✔ Complex Expressions with Parentheses
- Expressions are processed using the Shunting Yard Algorithm (Wikipedia).
- Operator precedence follows the C standard:
Operator Precedence Table. - Supported operators:
*, /, %, +, -, >, >=, <, <=, ==, !=, &&, ||
- Break/Continue →
tests/doubledigits/doubledigits.ipl - Counting Sort →
tests/contingsort/countingsort.ipl - Complex Expressions →
tests/expres/expres.ipl