CS112_45_Assignment7A - CS112 Assignment 7A Problem 1:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112 Assignment 7A Problem 1: Substitution in Trees In mathematics, there are several common procedures that require you to replace all instances of a variable in a formula with some other variable. Working entirely at the client level of exp.h , write a function expressionADT ChangeVariable(expressionADT exp, string oldName, string newName); that returns a new expression which is the same as exp except that every occurrence of the identifier oldName is replaced with newName . For example, if exp is the expression calling newExp = ChangeVariable(exp, "x", "y"); will assign the following expression tree to newExp : Problem 2: Recognizing a Language Write a program capable of recognizing whether an expression typed in by the user is a valid sentence, where the following rules define the grammar. S -> <name>P P -> T P -> TP T -> [<int>] These rules are actually the rules for statically declaring arrays in C. The following are examples of valid sentences:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
x[1] abc[42] y[1][2][3][4][5] The program will be easiest to write if you make use of the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

CS112_45_Assignment7A - CS112 Assignment 7A Problem 1:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online