This project implements a table-driven LL(1) parser for the calculator language with comments. The parser is designed to check the lexical and syntactical correctness of calculator programs provided as input files. The calculator language allows variable declarations, arithmetic operations, and output statements.
scanner.c
: Implementation of the scanner for the calculator language. It reads input files, identifies tokens, and reports lexical errors.parser.c
: Implementation of the LL(1) table-driven parser for the calculator language. It checks for syntactical errors in the input program.scanner.h
: Header file containing declarations for scanner functions and token definitions.README.md
: Documentation file providing instructions, descriptions, and guidelines for the project.
To compile the programs, use the following command:
gcc parser.c scanner.c -o parser
To run the program, execute the compiled binary along with the input program file:
./parser prog1
Replace prog1
with the name of the calculator program file to be checked.
/* prog1 */
read a
read b
area := a * b
perimeter := 2 * (a + b)
write area
write perimeter
/* prog2
read a
read b
area := a * b
perimeter := 2 * (a + b)
write area
write perimeter
/* prog3 */ */
read a
read b
area := a * b
perimeter := 2 * (a + b)
write area
write perimeter
// prog4
read a b
area := a * b
perimeter := 2 * (a + b)
write area
write perimeter
// prog5
read a
read b
area := a * b
perimeter := 2 * (a + b
write area
write perimeter
Lexical errors: The scanner reports lexical errors when encountering invalid characters or token sequences. Syntactical errors: The parser identifies and reports syntactical errors such as unexpected tokens or incorrect program structures.
The scanner implementation needs to be enhanced to handle comments more effectively.