Regular expressions, Theory of Computation

Assignment Help:

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.


Related Discussions:- Regular expressions

Non - sl languages, Application of the general suffix substitution closure ...

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

Concatenation, We saw earlier that LT is not closed under concatenation. If...

We saw earlier that LT is not closed under concatenation. If we think in terms of the LT graphs, recognizing the concatenation of LT languages would seem to require knowing, while

Kleene closure, One might assume that non-closure under concatenation would...

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

Mapping reducibility, Can you say that B is decidable? If you somehow know...

Can you say that B is decidable? If you somehow know that A is decidable, what can you say about B?

Formal languages and grammar, The universe of strings is a very useful medi...

The universe of strings is a very useful medium for the representation of information as long as there exists a function that provides the interpretation for the information carrie

Bonds, . On July 1, 2010, Harris Co. issued 6,000 bonds at $1,000 each. The...

. On July 1, 2010, Harris Co. issued 6,000 bonds at $1,000 each. The bonds paid interest semiannually at 5%. The bonds had a term of 20 years. At the time of issuance, the market r

Pumping lemma constant, a) Let n be the pumping lemma constant. Then if L i...

a) Let n be the pumping lemma constant. Then if L is regular, PL implies that s can be decomposed into xyz, |y| > 0, |xy| ≤n, such that xy i z is in L for all i ≥0. Since the le

Construct a regular expression, Given any NFA A, we will construct a regula...

Given any NFA A, we will construct a regular expression denoting L(A) by means of an expression graph, a generalization of NFA transition graphs in which the edges are labeled with

Kleene Closure, 1. Does above all''s properties can be used to prove a lang...

1. Does above all''s properties can be used to prove a language regular? 2..which of the properties can be used to prove a language regular and which of these not? 3..Identify one

Can you help me in automata questions, i have some questions in automata, c...

i have some questions in automata, can you please help me in solving in these questions?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd