A C programming language preprocessor to perform arithmetic operations on matrices. Yeditepe University CSE232 course group term project.
| Group Members | Tasks |
|---|---|
| Leader - Emirhan Tala | main.c, @int, @read |
| Nika Golestani | makefile, sh, @copy, find_array_index() |
| Eylül Akar | @dotp, @add, @mmult |
| Samet Alper Özdemir | @sum, @aver |
| Dilara Zeynep Kesgün | @init, @read |
P232 is a preprocessor designed to expand C programs containing special operation directives. This document outlines how to use the p232.sh script and the Makefile to process C programs with your custom preprocessor directives.
- Linux environment with a Bash shell
- GCC compiler
To use the preprocessor, you need to pass a single C source file with a .c extension as an argument to the p232.sh script. Here is how you can run it:
./p232 myCprog.cThe script performs the following operations:
- Checks if exactly one argument is provided.
- Verifies that the file has a
.cextension. - Compiles the program if it's not already compiled.
- Executes the preprocessor on the provided file, generating an expanded C program saved as
expanded.c.
To clean up object files and the executable, run:
make cleanIf you also want to remove the expanded.c file generated by the preprocessor, run:
make clean-all@int B(10)declares 1D integer array B with 10 elements@int A(3,5)declares 2D integer array A with 3x5 elements@read B < f1Reads all elements of an array from a file.@copy C = ACopies all elements of an array to another array.@init A = 2Initializes all elements of an array to a value.@print APrints the array elements on the screen.@dotp C = A . BCalculates the dot product of two 1D arrays and assigns the result to the preprocessor variable P_dot@add C = A + BAdds two arrays and assigns the result to an array@mmult C = A * BMultiplies two 2D arrays and assigns the result to a 2D array@sum ASums all elements of an array and assigns the result to the preprocessor variable P_sum@aver ACalculates the average of all elements in an array and assigns the result to the preprocessor variable P_aver.
Here's a simple example of a C program using preprocessor directives:
#include "P_header.h"
int main() {
@int X(10)
@init X = 0
@print X
return 0;
}
Running ./p232.sh on this file would generate an expanded.c file with the expanded C code.
#include “P_header.h”
int main() {
int X[10];
for (int i=0; i<10; ++i)
X[i]=0;
for (int i=0; i<10; ++i)
printf(“%d “, X[i]);
printf(“\n”);
return 0;
}