Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
28 views3 pages

Assignment - CSC - 461 - C Fall 24

The assignment for CSC 461 involves designing and implementing a Recursive Descent Parser in C for a specified grammar using Backus-Naur Form (BNF). It requires the creation of a lexer, parser, optional evaluation of expressions, error handling, and testing with valid and invalid cases. Submission includes a .c file and a report in both Word and PDF formats, detailing compilation instructions and test cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Assignment - CSC - 461 - C Fall 24

The assignment for CSC 461 involves designing and implementing a Recursive Descent Parser in C for a specified grammar using Backus-Naur Form (BNF). It requires the creation of a lexer, parser, optional evaluation of expressions, error handling, and testing with valid and invalid cases. Submission includes a .c file and a report in both Word and PDF formats, detailing compilation instructions and test cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment

On
Course Name: Programming Languages and Structures
Course Code: CSC 461
Semester: Fall 2024
Course Instructor: Sheekar Banerjee
Lecturer, Dept. of CSE, IUBAT
Assigned: December 31, 2024. Due: January 8, 2025, 11:59 PM

Motivation: Recursive Descent Parser


In computer science, a recursive descent parser is a kind of top-down parser built from a set of
mutually recursive procedures (or a non-recursive equivalent) where each such procedure implements
one of the nonterminals of the grammar. Thus the structure of the resulting program closely mirrors
that of the grammar it recognizes.

A predictive parser is a recursive descent parser that does not require backtracking.[3] Predictive
parsing is possible only for the class of LL(k) grammars, which are the context-free grammars for
which there exists some positive integer k that allows a recursive descent parser to decide which
production to use by examining only the next k tokens of input. The LL(k) grammars therefore exclude
all ambiguous grammars, as well as all grammars that contain left recursion. Any context-free
grammar can be transformed into an equivalent grammar that has no left recursion, but removal of left
recursion does not always yield an LL(k) grammar. A predictive parser runs in linear time.

Recursive descent with backtracking is a technique that determines which production to use by trying
each production in turn. Recursive descent with backtracking is not limited to LL(k) grammars, but is
not guaranteed to terminate unless the grammar is LL(k). Even when they terminate, parsers that use
recursive descent with backtracking may require exponential time.

Objective: Your Task

Your task is to design and implement a Recursive Descent Parser in C Programming Language for
a grammar defined in Backus-Naur Form (BNF). The parser should validate and evaluate input
strings according to the given grammar.

Grammar Specification
You are tasked with implementing a Recursive Descent Parser for the following grammar:

BNF Rules:
<expression> => <term> {("+" | "-") <term>}
<term> => <factor> {("*" | "/") <factor>}
<factor> => <number> | "(" <expression> ")"
<number> => <digit> {<digit>}
<digit> => "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Assignment Requirements
1. Lexer Implementation:
Write a lexer (scanner) function that reads an input string and tokenizes it into:
○ Numbers (e.g., 123, 45)
○ Operators (+, -, *, /)
○ Parentheses ((, ))
2. Parser Implementation:
○ Implement a Recursive Descent Parser that parses the input string based on the grammar
rules.
○ The parser should validate the input and determine whether it is a valid expression according
to the grammar.
3. Evaluation (Optional):
Extend the parser to evaluate valid expressions and output the result. For example:
○ Input: "3 + 5 * (2 - 8)"
○ Output: -13
4. Error Handling:
Implement error-handling mechanisms to gracefully handle invalid input strings, such as missing
parentheses or unexpected tokens.
5. Testing:
Provide test cases to verify the correctness of your implementation. Include both valid and invalid
expressions.

Implementation Details
1. Programming Language: C
2. Input: The parser should accept a mathematical expression as a string (e.g., "3 + 5 * 2").
3. Output:
○ For a valid expression: Print Valid expression and optionally the evaluated result.
○ For an invalid expression: Print an appropriate error message indicating the issue.
4. Submission Format:
○ A single .c file containing the code.
○ A Report file with instructions on how to compile and run the program, as well as a list of
test cases.

Submission Details:

For Report: Submit as a Word and pdf file both to the designated classroom space.
The name of those files should be your serial number then the ID number.
Like: SerialNumber_IDNumber.docx and SerialNumber_IDNumber.pdf.
For Code: Submit as a zip file containing your complete task (.c file containing the code, along
with whatever other files are needed to compile them; sample input and output files) in the
classroom assignment. The name of the zip file should be your serial number then the ID
number Like SerialNumber_IDNumber.
Justification on PO2 (Problem Analysis) Attainment:
Assignment Features Knowledge Profile &
Attributes of Complex
Engineering Problem

The solution required an understanding of mathematics and the basic K1 & K2 P1- Depth
theory of natural science. of
Knowled
The solution required knowledge about the engineering fundamentals K3 ge
Required
like the basic structure of programming language.

The solution required specialized knowledge about the derivation and K4


implementation of that through computer programs.

The solution requires an in-depth analysis of Syntax Analysis. For a P3- Depth of Analysis
variation of the Derivation and the implementation can be in different Required
numbers of programming languages, therefore the solution can be

multiple. Also because of using two different types of language, the


approach to the solution will be different.

The problem or task can be divided into multiple parts like parse tree P7- Interdependence
construction and derivation – the first part is designed through the
leftmost or rightmost parse tree and then the next part is implemented
by programming language.

You might also like