Recursive_Descent_Parser_Assignment_Report
Recursive_Descent_Parser_Assignment_Report
Objective
The primary objective of this assignment is to design and implement a Recursive Descent Parser in C
capable of parsing and validating simple control structures (if, else, and while) and arithmetic expressions
with support for nested parentheses. A unique feature includes the recognition of a special token LTD, which
stands for the "Last Three Digits" of the student ID and is substituted during evaluation. This parser aims to
simulate compiler front-end syntax analysis using recursive procedures, token streams, and error detection
mechanisms.
Grammar Summary
Lexer (Tokenizer):
Parser Structure:
Error Handling:
- Detects mismatched brackets, missing semicolons, unexpected tokens, invalid identifiers, misplaced
relational operators.
LTD Handling:
- Treated as a special identifier, replaced with the last 3 digits of the student ID.
Valid Case:
if (a == LTD) {
(a + b) * (b - LTD);
} else {
Recursive Descent Parser in C - Assignment Report
(x + y) * (a - b);
a+b
if (a == b) {
a + b;
3a + 5;
File: parser.c
Recursive Descent Parser in C - Assignment Report
To compile:
To run:
./parser
Input Method:
Copy-paste the input code block or read from a file using redirection.
Conclusion
This assignment simulates a basic front-end compiler parser using recursive descent. It helps develop a deep
understanding of parsing control structures and expressions. Through modular design, error handling, and
careful matching of grammar rules, this parser successfully validates simple source code fragments and
forms the foundation for more advanced compiler features in the future.