Blog

Coursehelp
March 15, 2019
QUESTION : No Comments

(Solved) : Program Read Array String Statements One Statement Time Show Error Statements Array Whenev Q26980402

This program will read an array of string statements, onestatement at a time and will show error statements, from their ownarray, whenever a statement is missing the appropriate parenthesisor bracket. The error messages should be kept simple and should notdisplay two errors at once.

the output should use ^ symbol and will be on a new line belowthe expression pointing at the error

Write java code for expression evaluation and syntax using theSTACK operation and display appropriate error message. I alreadywrote some code, but something wrong.

public class Evaluation1 {
static int statement = 5;
static String[] test = new String[statement]; //array to store thestatement test
static char[] myStack = new char[40];
static int stackTop;
public static void main(String[] args) {
test[0] = “( 1 + 3 ) * { 2 – 1 )”;
test[1] = “( 1 + 3 } * ( 2 – 1 )”;
test[2] = “{ 1 + 3 ) * ( 2 – 1 )”;
test[3] = “{ 1 + 3 } * ( 2 – 1 )}”;
test[4] = “({ 1 + 3 ) * (2 – 1 )”;
for (int i = 0; i < statement; i++) { // loop through how manystatement we need to test
stackTop = -1;
for (int j = 0; j < test[i].length(); j++) {
char c = test[i].charAt(j);
if (c == ‘{‘ || c == ‘(‘) { // if char c = { , ( then use pushmethod
push(c);
}
if (c == ‘}’) {
char poped = pop();
if (poped != ‘{‘)

}
if (c == ‘)’) {
char poped = pop();
if (poped != ‘(‘) // if it doesn’t have complete brackets, printerror message

}
}
}
}
static void printErrorMessage(int position, int errNo) {

for (int i = 0; i < statement; i++ ) {
  

System.out.print(” “);
}

System.out.print(“^ “);
System.out.println(errMsg[errNo]);
}
static void errorMessages() {

errMsg[0] = ” ( expected”;
errMsg[1] = ” ) expected”;
errMsg[2] = ” { expected”;
errMsg[3] = ” } expected”;
}

public static void push(char c) {   
stackTop++;
myStack[stackTop] = c;
}
public static char pop() {
char c;
if (stackTop == -1) {
System.out.println(” “);
System.out.println(“Stack is empty”); // check if the stack isempty
return ‘n’;
}
c = myStack[stackTop];
stackTop–;
return c;
}
}

Expert Answer


Attached . . .

OR
OR

Have a Comment on this Question?

Questions viewed by other students


  • QUESTION : (Solved) : 12 Translate Following Pseudocode Expression Mips Assembly Language Code Include Code Insu Q28562055

    12. Translate the following pseudocode expression to MIPS assembly language code. Include code to insure that there is no array bounds violation when the store word (sw) instruction is executed. Note that the array zap is an array containing 50 words, thus the value in register ?a0 must be in the rang from 0 to 196. Include code to insure that the value in register ?a0 is a word address offset into the array zap. If an array bounds violation is detected or the value in register $a0 is not a word address offset then branch to the label Error. .data zap: .space 200 .text

    12. Translate the following pseudocode expression to MIPS assembly language code. Include code to insure that there is no array bounds violation when the store word (sw) instruction is executed. Note that the array “zap” is an array containing 50 words, thus the value in register ?a0 must be in the rang from 0 to 196. Include code to insure that the value in register ?a0 is a word address offset into the array “zap.” If an array bounds violation is detected or the value in register $a0 is not a word address offset then branch to the label “Error”. .data zap: .space 200 .text Show transcribed image text 12. Translate the following pseudocode expression to MIPS assembly language code. Include code to insure that there is no array bounds violation when the store word (sw) instruction is executed. Note that the array “zap” is an array containing 50 words, thus the value in register ?a0 must be in the rang from 0 to 196. Include code to insure that the value in register ?a0 is a word address offset into the array “zap.” If an array bounds violation is detected or the value in register $a0 is not a word address offset then branch to the label “Error”. .data zap: .space 200 .text

    Expert Answer


    Attached . . .


    view full answer
  • QUESTION : (Solved) : 12 Use Code Answer Questions Follow Assume Proper Libraries Name Spaces Included Code Comp Q31043595

    This is in c++

    12. Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid write in the last digit of your SMC student ID. int foo(int a, int b)f //First intc- a+b; while(c>-3) return C; char foo(string a, int b) t //Second return a[b]; string foo(int b, string &a) 1 //Third string sub-a.substr (3*b,3); a.replace (3*b,3,...); return sub; void main() int last sid - string letters(ggfiorkcboneat !! !ws adtarojot); string output(); int numbers[] {0,8,3,7,4,6,9,1,2,5}; ; //<-Last digit of your SID for(int i-0; i<10; i++) [ int j - numbers[i]; numbers [i]-foo(last_sid,i); string s-foo(j, letters); output -foo(s, numbers[i]); cout << output; a.) For each of the three foo functions briefly describe in plain language what each function is doing. You may refer to the top function as the first function, the one below as the second function, and finally the last as the third function. b.) What is it called when we use the same function identifier for multiple functions? What must we done to allow the compiler to differentiate between functions with the same identifier?

    12. Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid write in the last digit of your SMC student ID. int foo(int a, int b)f //First intc- a+b; while(c>-3) return C; char foo(string a, int b) t //Second return a[b]; string foo(int b, string &a) 1 //Third string sub-a.substr (3*b,3); a.replace (3*b,3,”…”); return sub; void main() int last sid – string letters(“ggfiorkcboneat !! !ws adtarojot”); string output(“”); int numbers[] {0,8,3,7,4,6,9,1,2,5}; ; //Show transcribed image text

    Expert Answer


    Attached . . .


    view full answer
  • QUESTION : (Solved) : 12 Use Direct Proof Show Following Argument Valid Need Add Lines Finish Proof First Box Pr Q28206669

    12.

    Use a direct proof to show that the following argument isvalid.

    Need to add the lines to finish the proof. The first box shouldbe the proof, second two boxes should reference the line numbers,the last box should say which rule we are using. Thank you inadvance!!

    1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgans Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof

    1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgan’s Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof Show transcribed image text 1 (F.K) 2 (B V ~K) 3C (FVB) NC 4 Check Modus Ponens MP Modus Tollens MT Hypothetical Syllogism HS Disjunctive Syllogism DS Constructive Dilemma CD Simplification Simp Conjunction Conj Addition Add DeMorgan’s Rule DM Commutativity Com Associativity Assoc Distribution Dist Double Negation DN Add Line X Delete Line Check Proof

    Expert Answer


    Attached . . .


    view full answer