示例#1
0
        private void RaiseException(ExceptionType exc, ForthAtom atom)
        {
            switch (exc)
            {
            case ExceptionType._EDeclareOutsideWords:
                throw new Exception(atom.Name + " should be declared outside words. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EDeclareInsideWords:
                throw new Exception(atom.Name + " should be declared inside words. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EReservedWord:
                throw new Exception(atom.Name + " is a reserved identifier. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EInvalidIdentifier:
                throw new Exception(atom.Name + " is an invalid identifier. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EUnableToDefineConst:
                throw new Exception("Unable to define constant " + atom.Name + ". Number or string required before CONSTANT. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EUnableToAllocVar:
                throw new Exception("Unable to alloc variable space " + atom.Name + ". Number needed before ALLOT. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EUnexpectedEndOfFile:
                throw new Exception("Unexpected end of file " + atom.FileName + ".");

            case ExceptionType._EWrongAllotConstType:
                throw new Exception("Wrong constant type specified for ALLOT. Use an integer. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._ENestedWordsNotAllowed:
                throw new Exception("Nested words are not allowed. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMalformedBWRStruct:
                throw new Exception("Malformed BEGIN-WHILE-REPEAT control structure. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMalformedBAStruct:
                throw new Exception("Malformed BEGIN-AGAIN control structure. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMalformedBUStruct:
                throw new Exception("Malformed BEGIN-UNTIL control structure. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMalformedIETStruct:
                throw new Exception("Malformed IF-ELSE-THEN control structure. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMalformedCOEStruct:
                throw new Exception("Malformed CASE-OF-ENDCASE control structure. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EUnfinishedControlStruct:
                throw new Exception("Control structures must be terminated before ';'. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EMainNotDefined:
                throw new Exception("Program starting point is missing. Please define the word MAIN.");

            case ExceptionType._EDuplicateConst:
                throw new Exception("Constant redefines an already defined constant or variable. (" + atom.FileName + ":" + atom.LineNumber + ")");

            case ExceptionType._EDuplicateVar:
                throw new Exception("Variable redefines an already defined constant or variable. (" + atom.FileName + ":" + atom.LineNumber + ")");
            }
        }
示例#2
0
        // ProcessLoadDirectives - Parses the atom list and recursively processes the LOAD directives
        // Input:  None
        // Output: Modifies the 'SourceAtoms' global variable
        private void ProcessLoadDirectives()
        {
            string IncludeFile;                         // Name of the file to parse
            int    LoadPosition;                        // Position of the "LOAD" directive in the array

            while (true)
            {
                LoadPosition = -1;                      // Initially not found
                // Get the position of the 'LOAD' directive in the atom list
                for (int i = 0; i < SourceAtoms.Count; i++)
                {
                    ForthAtom atom = (ForthAtom)SourceAtoms[i];
                    if (atom.Name.ToLower() == "load")
                    {
                        LoadPosition = i;
                        break;
                    }
                }
                if (LoadPosition == -1)
                {
                    break;                                      // No need to continue (not found)
                }
                try
                {
                    IncludeFile = ((ForthAtom)SourceAtoms[LoadPosition + 1]).Name;                                      // Get the name of the file to include
                }
                catch (Exception)
                {
                    ForthAtom atom = (ForthAtom)SourceAtoms[LoadPosition];
                    throw new Exception("Missing name of the include file. (" + atom.FileName + "," + atom.LineNumber + ")");                           // Signal error if no file name is supplied
                }

                // Merge the atoms for the two files
                SourceAtoms.RemoveRange(LoadPosition, 2);
                ArrayList NewAtoms = ProcessSourceFile(IncludeFile);
                SourceAtoms.InsertRange(LoadPosition, NewAtoms);
            }
        }
示例#3
0
        // RaiseException - Throws a specified exception
        // Input:  ExceptionType - 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(ExceptionType exc)
        {
            ForthAtom atom = new ForthAtom("", "", 0);                  // Create an "empty" atom

            RaiseException(exc, atom);
        }