https://drive.google.com/file/d/1oxuPQWIQ4IBvrRU8VJKiEd8ttIrB8DJ3/view?usp=sharing
This laboratory manual is for the Compiler Design course offered by the Department of Information Technology at Sri Indu College of Engineering & Technology for the 2025-26 academic year. Course Objectives and Outcomes
The manual emphasises general laboratory instructions, including:
The curriculum comprises 11 experiments focusing on practical implementation:
- Objectives: The course aims to help students understand the various phases of compiler design, top-down and bottom-up parsing techniques, and syntax-directed translation schemes. Students are also introduced to lex and yacc tools.
- Outcomes: Upon completion, students should be able to design and implement compilers, develop scanners and parsers using lex and yacc, and implement LL and LR parsers.
- Strict adherence to timings and dress code.
- Preparation of laboratory observation notes before the session.
- Maintaining discipline and proper utilisation of equipment.
- Turning off mobile phones and shutting down systems properly after tasks.
- Lexical Analysis: Simulating Deterministic Finite Automata (DFA) and dividing input programs into lexemes.
- Parsing Algorithms: Implementing Predictive Parsing, SLR(1) Parsing, and LALR bottom-up parsing.
- Code Generation: Generating three-address code.
- Grammar Manipulation: Removing left recursion from a given grammar.
Comments
#include
#include
#include
char input[100];
int j;
i++;
f(s,j);
}
void f(int s, int j)
{
if (input[j] == '0')
{
if (s == 0)
f(1, j);
else if (s == 1)
f(2, j);
else if (s == 2)
f(2, j);
}
else
{
if (s == 0)
f(0, j);
else if (s == 1)
f(1, j);
else if (s == 2)
f(1, j);
}
}
int main()
{
printf("Enter input string: ");
scanf("%s", input);
f(0, 0);
if (input[j] == '\0')
printf("String accepted\n");
}
#include
#include
#include
void generateTAC(char expression[]) {
char tempVar = 't'; // Temporary variable prefix
int tempCount = 1; // Counter for temporary variables
char stack[100][10]; // Stack to hold intermediate results
int top = -1;
printf("Three Address Code:\n");
for (int i = 0; expression[i] != '\0'; i++) {
if (isalnum(expression[i])) {
// Push operand onto the stack
char operand[2] = {expression[i], '\0'};
strcpy(stack[++top], operand);
} else if (strchr("+-*/", expression[i])) {
// Pop two operands from the stack
char op2[10], op1[10];
strcpy(op2, stack[top--]);
strcpy(op1, stack[top--]);
// Generate TAC for the operation
printf("%c%d = %s %c %s\n", tempVar, tempCount, op1, expression[i], op2);
// Push the result back onto the stack
char result[10];
sprintf(result, "%c%d", tempVar, tempCount++);
strcpy(stack[++top], result);
}
}
// Final result
printf("Result: %s\n", stack[top]);
}
int main() {
char expression[100];
printf("Enter a postfix expression (e.g., ab+c*): ");
scanf("%s", expression);
generateTAC(expression);
return 0;
}