- The following codes are written in C and are meant to be compiled with CC or GCC compilers.
LAB Question | Repo Program path |
---|---|
Words,lines,chars,Special Characters | Link |
a^m b^m+n c^n | Link |
Integers and Fractions | Link |
Arithmetic Expression | Link |
Remove comment lines | Link |
Nested For loops | Link |
Number of identifiers and operators | Link |
Nested IF statements | Link |
Variable Declaration | Link |
Three address code | Link |
Function definition | Link |
Assembly code generation | Link |
- Need to have the following installed :
- GCC Compiler
- Flex
- Yacc
lex <filename>.l
gcc lex.yy.c
./a.out
lex <filename>.l
yacc -d <filename>.y
gcc lex.yy.c y.tab.c -lfl
./a.out
Input format for each of the programs
-
a. Count the number of characters, words, lines and special characters in a given input file.
any string with numbers and special characters
b Validate the strings of the type a^m b^m+n c^n where m,n>=0
aabbcc abc ab bc
-
a. Count the number of positive and negetive integers and positive and negetive fractions
> 1 -2 3/4 -5/6 7/-8 -9/-10 +11/12 > // Just give a series fo space separated numbers
b. Evaluate a given arithmetic expression with + - * / operators.
1+2*3/4-5
-
a. Count the number of valid nested FOR loops
for(a;b<c;c); for(i=0;i<10;i){for(j=0;j<10;j);}
b. Validate function defination
int main(){}; int foo(int a){} int bar(int a,int b){return a;}
-
Generate the intermediate 3 address code and quadruples for a given expression
a=b+c*d a+b+c+d+e+f a=(b+d)*(c+e)
-
Generate the assembly code for a given set of arithmetic expressions
./outputfilename.out < input.txt
This program is to print the unoptimised and optimised code for a bubble sort code
# to print the unoptimised assembly code
clang filename.c -S -emit-llvm -o filename
# to print the optimised assembly code
clang filename.c -S -emit-llvm -o filename -O3
This program is to print the unoptimised and optimised code for a binary search code
# to print the unoptimised assembly code
clang filename.c -S -emit-llvm -o filename
# to print the optimised assembly code
clang filename.c -S -emit-llvm -o filename -O3
this is about loop unrolling
# comment out the unroll pragma to see the difference
clang filename.c -S -emit-llvm -o filename
# for unrolled optimisation
clanf filename.c -S -emit-llvm -o filename -O3
- Added all 5 programs
- Had some conflicts in Shift/Reduce and Reduce/ Reduce
- @DeathStroke1991(https://github.com/DeathStroke19891) Fixed the issues in 3a and 3b
- Added comments on grammer.
- Added LLVM programs
- Added the new commands to run the programs
- Added Extra lab codes
- Added lab to repo mapping
This repo is open for contributions. Please open an Issue or open a PR with appropriate edits.