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

Create a general algorithm from a checking algorithm, Claim Under the assum...

Claim Under the assumptions above, if there is an algorithm for checking a problem then there is an algorithm for solving the problem. Before going on, you should think a bit about

Chomsky-schutzenberger, The upper string r ∈ Q+ is the sequence of states v...

The upper string r ∈ Q+ is the sequence of states visited by the automaton as it scans the lower string w ∈ Σ*. We will refer to this string over Q as the run of A on w. The automa

Discrete math, Find the Regular Grammar for the following Regular Expressio...

Find the Regular Grammar for the following Regular Expression: a(a+b)*(ab*+ba*)b.

Regular languages, LTO was the closure of LT under concatenation and Boolea...

LTO was the closure of LT under concatenation and Boolean operations which turned out to be identical to SF, the closure of the ?nite languages under union, concatenation and compl

Abstract model of computation, When we say "solved algorithmically" we are ...

When we say "solved algorithmically" we are not asking about a speci?c programming language, in fact one of the theorems in computability is that essentially all reasonable program

Fsa as generators, The SL 2 languages are speci?ed with a set of 2-factors...

The SL 2 languages are speci?ed with a set of 2-factors in Σ 2 (plus some factors in {?}Σ and some factors in Σ{?} distinguishing symbols that may occur at the beginning and en

Ogdens lemma, proof ogdens lemma .with example i am not able to undestand ...

proof ogdens lemma .with example i am not able to undestand the meaning of distinguished position .

A composable-reset DFA (CR-DFA) is a five-tuple, Question 2 (10 pt): In thi...

Question 2 (10 pt): In this question we look at an extension to DFAs. A composable-reset DFA (CR-DFA) is a five-tuple, (Q,S,d,q0,F) where: – Q is the set of states, – S is the alph

Myhill graph of the automaton, Exercise:  Give a construction that converts...

Exercise:  Give a construction that converts a strictly 2-local automaton for a language L into one that recognizes the language L r . Justify the correctness of your construction.

Push down automata, Construct a PDA that accepts { x#y | x, y in {a, b}* su...

Construct a PDA that accepts { x#y | x, y in {a, b}* such that x ? y and xi = yi for some i, 1 = i = min(|x|, |y|) }. For your PDA to work correctly it will need to be non-determin

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