Theory of Automata Fall 2010

Semester Project
Marks: 15 Submission deadline: 30-11-2010

The objective of this project is to use your knowledge of automata and create a parser that inputs a simple C++ code and simulates the execution similar to the output of an interpreter.

The project requires you to create a parser and use it to read a program/ code written in C++ from a file and parse it while creating a syntax tree for the language.

Parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens. A parser usually calls a lexical analyzer function. A token is a string of characters, categorized according to the rules as a symbol (e.g. IDENTIFIER, NUMBER, COMMA, etc.). The process of forming tokens from an input stream of characters is called tokenization. A token can look like anything that is useful for processing an input text stream or text file.

For every possible expression, an automata needs to be made which will be used to judge if the given expression is valid. Let¶s say that the following automaton is used to check if the increment operator has been used properly (Note: This is not the final form of the automata):





+ Q2

The expression will be passed through the above automata to find out if the given expression on a particular line is valid or not. It will be executed if its valid otherwise an error message will be shown which will include the state of the automata on which the expression was terminated. Your interpreter should be able to execute the following expressions: y y y if else statement variable declarations mathematical operators and expression evaluation

The parser will read the file line by line and it will break down the file by calling the lexical analyzer function to tokenize the code written in a line.y display output statements Implementation of any other expressions will result in bonus marks. int b=4. Some examples of a syntax tree have been given below: These syntax trees are created as a result of mathematical expressions given above. the tree will be solved and the syntax will be executed and the result will be similar to what a regular interpreter will compile. int c=5. After the tree has been created. Your program which will be simulation of aninterpreter will input a text file. Then code on a line will be translated into a syntax tree. cout<<a. . The expression tree needs to be made using a tree data structure but for all other purposes. any data structures can be made. a = b + c. Example: Let¶s say a file is given as input to the parser as follows: int a.

The coding practices should be professional and understandable to facilitate the evaluation.The parser will read the first line. If there are any ambiguities in the statement. It will make a tree for each line. should evaluate the expression by using the values from the specified variables and storing the value in the variable µa¶. Good Luck . so the interpreter based upon the mathematical operators: µ+¶ and µ=¶. it should recognize the keyword and allocate memory for the integers and also it should assign the specified values. The third line has no keyword.A. Conclusion: In short your program will read a file line by line.It will create a syntax tree and then finally the expression will be evaluated according to the tree from bottom to top. Maximum three students are allowed in a group. it will break it into tokens and run that tokenized line on the automata to check its validity. For every line it reads. Finally the last statement should recognize the keyword and should output the value stored in the memory. A written report in hard form should be submitted along with the submission containing the automaton used and all the other technical aspects of the project. and do not make any assumptions on your own. For the first three lines. Guidelines: y y y y y Any programing language can be used as long as the requirements are being achieved. contact the T.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.