0% found this document useful (0 votes)
25 views

CS416 Compiler Design: Programming Assignment 2 Due Date: April 2, 2007

This programming assignment requires students to create a menu-driven program that can: 1) Read a context-free grammar from a text file and create its LL(1) parsing table, reporting any errors. 2) Parse input strings using the LL(1) parser, printing leftmost derivations for valid strings or error messages. 3) Quit the program. Students must submit their source code, test runs, and executable to the teaching assistant by the due date.

Uploaded by

cvinay24
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

CS416 Compiler Design: Programming Assignment 2 Due Date: April 2, 2007

This programming assignment requires students to create a menu-driven program that can: 1) Read a context-free grammar from a text file and create its LL(1) parsing table, reporting any errors. 2) Parse input strings using the LL(1) parser, printing leftmost derivations for valid strings or error messages. 3) Quit the program. Students must submit their source code, test runs, and executable to the teaching assistant by the due date.

Uploaded by

cvinay24
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS416 Compiler Design

Spring 2007 Programming Assignment 2 Due Date: April 2, 2007


In this homework, you are going to write a menu-driven program. The menu should have the following parts: Create A New LL(1) Parser - When this option is selected your program should read a CFG from a text file whose name is given, and create its LL(1) parsing table. If the given CFG is not a LL(1) grammar your program should be able to give a message indicating this fact. Parse A String If a LL(1) parsing table is created using the first option, read a string from keyboard (or from a file) and parse that string with the current LL(1) parser. If the given string is a syntactically correct, your program should print its leftmost derivation. If it is not, it should print error messages. Quit Quit from your system. The details of your system should be as follows: Create A New LL(1) Parser Your program should read a CFG from a text file whose file name is given. You may assume that all upper case letters are non-terminals (S is the starting symbol) and all other printable characters are terminals. Each line of this text file contains a single production rule. A production rule should be in the following form: anonterminal -> astring where is anonterminal is a non-terminal (an upper case letter) and astring is a string of terminals and non terminals (including the empty string).

For example, the followings are some possible production rules for a CFG: S S S A A -> -> -> -> -> aS bA This means that the production rule is c bAb S

The non-terminals and the terminals of the given CFG are the non-terminals and the terminals appearing in the given production rules. The starting non-terminal is S. You may assume that the syntax of the production rules (as described above) is correct, and you do not have to handle the incorrect ones. If the given CFG is not a LL(1) grammar, your program should print a message indicating this fact together with the reason (which entries contain more than one production rule). If the given CFG is a LL(1) grammar, it should create its LL(1) parsing table, and store it internally. Your program should also print that LL(1) parsing table into a file. For example, your program should print the following LL(1) parsing table into a file for the CFG above. a S -> aS b S -> bA A -> bAb c A -> c $ S ->

S A

Parse A String If there is a LL(1) parsing table that is created, your program should read a string and should parse using that LL(1) parsing table. If the given string is in the language of the current grammar, your program should print its leftmost derivation. If it is not, your program should give error messages. Your program should give the positions of the errors together with error messages. Your program should use panic-mode error recovery to give error messages, and it should be able to handle multiple errors in the input (i.e. you program should be able to give multiple errors).

For example, if the current grammar is the CFG above and the given string is abc , your program should print the following leftmost derivation below: S => aS => abA => abc For example, if the given string is an erroneous string abbab, it should print the following error message Error: Unexpected a at the position 4. You should hand-in: Your source program (email to your assistant (Turhan Daybelge) ( [email protected] )) Some test runs of your program with correct and incorrect strings (email to the assistant) Executable of the your program by email and a message indicating how to run your executable on a PC or a Unix machine which is available at our department.

DO IT YOURSELF CHEATING WILL BE PUNISHED

You might also like