Regular expressions, Theory of Computation

The project 2 involves completing and modifying the C++ program that evaluates statements of an expression language contained in the Expression Interpreter that interprets fully parenthesized arithmetic expressions that contain either literal values or variables. For example, the grammar for the language that this interpreter accepts is defined by the following grammar:

, ;

→ ( )

| |

, |

=

The regular expressions defining the three tokens are the following:

[+-*/]

[a-zA-Z][a-zA-Z0-9]*

[0-9]+

So, if you were to enter the following expression:

(x + (y * 3)), x = 2, y = 6;

the interpreter would respond:

Value = 20

The statements of that expression language consist of an arithmetic expression followed by a list of assignments. Assignments are separated from the expression and each other by commas. A semicolon terminates the expression. The arithmetic expressions are fully parenthesized infix expressions containing integer literals and variables. The valid operators are +, -, *, /. Tokens can be separated by any number of spaces. Variable names begin with an alphabetic character, followed by any number of alphanumeric characters. Variable names are case sensitive. This syntax is described by BNF and regular expressions.

The program reads in the arithmetic expression and encodes the expression as a binary tree. After the expression has been read in, the variable assignments are read in and the variables and their values of the variables are placed into the symbol table. Finally the expression is evaluated recursively.

Your first task is to complete the program provided by providing the three missing classes, Minus, Times and Divide.

Next, you should modify the program to detect and report the following error conditions:

• Division by zero should be reported as a division error and the program should proceed to the next expression.

• Input containing uninitialized variables should be reported as an initialization error and the program should proceed to the next expression.

• Variables initialized but never used should be reported as a warning.

• Syntax errors including mismatched parentheses, invalid operator, missing comma, semicolon or assignment operator should be reported as a syntax error and the program should proceed to the next expression.

Your final task is to make the following three modifications to the program:

• The program should accept input from a file, allowing for multiple expressions arranged one per line.

• The SymbolTable class should be modified so that if a variable is assigned multiple values, the last assignment applies.

• The Literal class should be modified so that expressions containing floating point literals are properly evaluated.

Posted Date: 3/25/2013 1:46:18 AM | Location : United States







Related Discussions:- Regular expressions, Assignment Help, Ask Question on Regular expressions, Get Answer, Expert's Help, Regular expressions Discussions

Write discussion on Regular expressions
Your posts are moderated
Related Questions
The fact that the Recognition Problem is decidable gives us another algorithm for deciding Emptiness. The pumping lemma tells us that if every string x ∈ L(A) which has length grea

The path function δ : Q × Σ* → P(Q) is the extension of δ to strings: This just says that the path labeled ε from any given state q goes only to q itself (or rather never l

Application of the general suffix substitution closure theorem is slightly more complicated than application of the specific k-local versions. In the specific versions, all we had

This close relationship between the SL2 languages and the recognizable languages lets us use some of what we know about SL 2 to discover properties of the recognizable languages.

Another way of interpreting a strictly local automaton is as a generator: a mechanism for building strings which is restricted to building all and only the automaton as an inexh

c program to convert dfa to re

Computer has a single LIFO stack containing ?xed precision unsigned integers (so each integer is subject to over?ow problems) but which has unbounded depth (so the stack itself nev

Computer has a single unbounded precision counter which you can only increment, decrement and test for zero. (You may assume that it is initially zero or you may include an explici


One might assume that non-closure under concatenation would imply non closure under both Kleene- and positive closure, since the concatenation of a language with itself is included