Section: a Compiler's First Pass: Report Unbalanced Symbol Errors. an Application of a Stack
Total Page:16
File Type:pdf, Size:1020Kb
Section: A Compiler's First Pass: Report Unbalanced Symbol errors. An Application of a Stack
Assuming LinkedStack
+ " } \n" System.out.println(Goodbye]; } + "} \n" } + "[{( \n"; [{(
System.out.println(allText); // Apply the algorithm above to detect errors. // Print the most accurate compile time error messages as possible. // Definitely print the number of errors found.
Possible compile time errors:
Missing opener found by line 1 Mismatched closer on line 2 Mismatched closer on line 7 Missing opener found by line 8 Missing opener found by line 9 Found extra opener ( Found extra opener { Found extra opener [
Error count = 8 import java.util.EmptyStackException; public interface OurStack
/** * Check if the stack is empty to help avoid popping an empty stack. * @returns true if there are zero elements in this stack. */ public boolean isEmpty();
/** * Put element on "top" of this Stack object. * @param element The element to be added at the top of this stack. */ public void push(E element);
/** * Return reference to the element at the top of this stack. * @returns A reference to the top element. * @throws EmptyStackException if the stack is empty. */ public E peek() throws EmptyStackException;
/** * Remove element at top of stack and return a reference to it. * @returns A reference to the most recently pushed element. * @throws EmptyStackException if the stack is empty. */ public E pop() throws EmptyStackException; }