private void RaiseException(SyntacticExceptionType exc, ForthAtom atom) { switch (exc) { case SyntacticExceptionType._EDeclareOutsideWords: throw new Exception(atom.Name + " should be declared outside words. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EDeclareInsideWords: throw new Exception(atom.Name + " should be declared inside words. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EReservedWord: throw new Exception(atom.Name + " is a reserved identifier. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EInvalidIdentifier: throw new Exception(atom.Name + " is an invalid identifier. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EUnableToDefineConst: throw new Exception("Unable to define constant " + atom.Name + ". Number or string required before CONSTANT. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EUnableToAllocVar: throw new Exception("Unable to alloc variable space " + atom.Name + ". Number needed before ALLOT. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EUnexpectedEndOfFile: throw new Exception("Unexpected end of file " + atom.FileName + "."); case SyntacticExceptionType._EWrongAllotConstType: throw new Exception("Wrong constant type specified for ALLOT. Use an integer. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._ENestedWordsNotAllowed: throw new Exception("Nested words are not allowed. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMalformedBWRStruct: throw new Exception("Malformed BEGIN-WHILE-REPEAT control structure. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMalformedBAStruct: throw new Exception("Malformed BEGIN-AGAIN control structure. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMalformedBUStruct: throw new Exception("Malformed BEGIN-UNTIL control structure. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMalformedIETStruct: throw new Exception("Malformed IF-ELSE-THEN control structure. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMalformedCOEStruct: throw new Exception("Malformed CASE-OF-ENDCASE control structure. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EUnfinishedControlStruct: throw new Exception("Control structures must be terminated before ';'. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EMainNotDefined: throw new Exception("Program starting point is missing. Please define the word MAIN."); case SyntacticExceptionType._EDuplicateConst: throw new Exception("Constant redefines an already defined constant or variable. (" + atom.FileName + ":" + atom.LineNumber + ")"); case SyntacticExceptionType._EDuplicateVar: throw new Exception("Variable redefines an already defined constant or variable. (" + atom.FileName + ":" + atom.LineNumber + ")"); } }
// RaiseException - Throws a specified exception // Input: SyntacticExceptionType - the code of the exception to be thrown // ForthAtom - the atom (with file name and line number) that caused the error // Output: None // Overloads: 1 private void RaiseException(SyntacticExceptionType exc) { ForthAtom atom = new ForthAtom { Name = string.Empty, FileName = string.Empty, LineNumber = 0 }; // Create an "empty" atom RaiseException(exc, atom); }