Exemplo n.º 1
0
        } // ScInChar : void

        /// <summary>
        /// Replace the escape char
        /// </summary>
        private void ScReplaceEscapeChar()
        {
            char temp = '\0';

            if (ScOriginalCode[ScPositionNow] == 'a')
            {
                temp = '\a';
            }
            else if (ScOriginalCode[ScPositionNow] == 'b')
            {
                temp = '\b';
            }
            else if (ScOriginalCode[ScPositionNow] == 'f')
            {
                temp = '\f';
            }
            else if (ScOriginalCode[ScPositionNow] == 'n')
            {
                temp = '\n';
            }
            else if (ScOriginalCode[ScPositionNow] == 'r')
            {
                temp = '\r';
            }
            else if (ScOriginalCode[ScPositionNow] == 't')
            {
                temp = '\t';
            }
            else if (ScOriginalCode[ScPositionNow] == 'v')
            {
                temp = '\v';
            }
            else if (ScOriginalCode[ScPositionNow] == '0')
            {
                temp = '\0';
            }
            else if (ScOriginalCode[ScPositionNow] == '\\')
            {
                temp = '\\';
            }
            else if (ScOriginalCode[ScPositionNow] == '\'')
            {
                temp = '\'';
            }
            else if (ScOriginalCode[ScPositionNow] == '\"')
            {
                temp = '\"';
            }
            // change the escape char!
            ScOriginalCode = ScOriginalCode.Substring(0, ScPositionNow - 1) + temp.ToString() + ScOriginalCode.Substring(ScPositionNow + 1, ScOriginalCode.Length - ScPositionNow - 1);
            ScPositionNow -= 1;
        } // ScReplaceEscapeChar : void
Exemplo n.º 2
0
        /// <summary>
        /// Return the last lexemem before the symbol
        /// </summary>
        private Lexeme ScGetLast()
        {
            //if (ScOriginalCode.Substring(ScPositionLast, ScPositionNow - ScPositionLast) != "")
            // now it can't be
            //// nope, it can be empty for some reason = =
            ////// It can't be empty! Determined in the code above! =_=
            {
                Lexeme TempLexeme      = new Lexeme();
                string TempLexemeValue = ScOriginalCode.Substring(ScPositionLast, ScPositionNow - ScPositionLast);
                //////////////////////////////////////////////////
                //
                //  Why not ScPositionNow - ScPositionLast + 1?
                //
                //  aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa
                //    ^                          ^
                //    ScPositionLast             ScPositionNow
                //    if +1, the space will be added to the value.
                //
                //////////////////////////////////////////////////
                TempLexeme.Value      = TempLexemeValue;
                TempLexeme.LineNumber = ScLineCount;

                // Keywords
                //// Type
                if (TempLexemeValue == "new")
                {
                    TempLexeme.Type             = LexemeType.LV2_OPERATOR;
                    TempLexeme.OperatorPriority = 2;
                    TempLexeme.Value            = Operators.NEW;
                }
                else if (TempLexemeValue == "bool")
                {
                    TempLexeme.Type = LexemeType.BOOL;
                }
                ////// NUMBER
                else if (TempLexemeValue == "int")
                {
                    TempLexeme.Type = LexemeType.INT;
                }
                else if (TempLexemeValue == "float")
                {
                    TempLexeme.Type = LexemeType.FLOAT;
                }
                else if (TempLexemeValue == "double")
                {
                    TempLexeme.Type = LexemeType.DOUBLE;
                }

                else if (TempLexemeValue == "char")
                {
                    TempLexeme.Type = LexemeType.CHAR;
                }
                else if (TempLexemeValue == "string")
                {
                    TempLexeme.Type = LexemeType.STRING;
                }
                else if (TempLexemeValue == "void")
                {
                    TempLexeme.Type = LexemeType.VOID;
                }
                else if (TempLexemeValue == "class")
                {
                    TempLexeme.Type = LexemeType.CLASS;
                }
                else if (TempLexemeValue == "enum")
                {
                    TempLexeme.Type = LexemeType.ENUM;
                }
                //// Logic
                else if (TempLexemeValue == "if")
                {
                    TempLexeme.Type = LexemeType.IF;
                }
                else if (TempLexemeValue == "else")
                {
                    TempLexeme.Type = LexemeType.ELSE;
                }
                else if (TempLexemeValue == "do")
                {
                    TempLexeme.Type = LexemeType.DO;
                }
                else if (TempLexemeValue == "while")
                {
                    TempLexeme.Type = LexemeType.WHILE;
                }
                else if (TempLexemeValue == "for")
                {
                    TempLexeme.Type = LexemeType.FOR;
                }
                else if (TempLexemeValue == "break")
                {
                    TempLexeme.Type = LexemeType.BREAK;
                }
                else if (TempLexemeValue == "continue")
                {
                    TempLexeme.Type = LexemeType.CONTINUE;
                }
                else if (TempLexemeValue == "goto")
                {
                    TempLexeme.Type = LexemeType.GOTO;
                }


                else if (TempLexemeValue == "this")
                {
                    TempLexeme.Type = LexemeType.THIS;
                }

                //// Modifier
                else if (TempLexemeValue == "public")
                {
                    TempLexeme.Type = LexemeType.PUBLIC;
                }
                else if (TempLexemeValue == "private")
                {
                    TempLexeme.Type = LexemeType.PRIVATE;
                }
                else if (TempLexemeValue == "protected")
                {
                    TempLexeme.Type = LexemeType.PROTECTED;
                }
                else if (TempLexemeValue == "virtual")
                {
                    TempLexeme.Type = LexemeType.VIRTUAL;
                }
                else if (TempLexemeValue == "override")
                {
                    TempLexeme.Type = LexemeType.OVERRIDE;
                }
                else if (TempLexemeValue == "static")
                {
                    TempLexeme.Type = LexemeType.STATIC;
                }
                else if (TempLexemeValue == "const")
                {
                    TempLexeme.Type = LexemeType.CONST;
                }
                else if (TempLexemeValue == "final")
                {
                    TempLexeme.Type = LexemeType.FINAL;
                }
                //// Values
                else if (TempLexemeValue == "true")
                {
                    TempLexeme.Type = LexemeType.TRUE;
                }
                else if (TempLexemeValue == "false")
                {
                    TempLexeme.Type = LexemeType.FALSE;
                }
                else if (TempLexemeValue == "null")
                {
                    TempLexeme.Type = LexemeType.NULL;
                }

                else if (TempLexemeValue == "try")
                {
                    TempLexeme.Type = LexemeType.TRY;
                }
                else if (TempLexemeValue == "catch")
                {
                    TempLexeme.Type = LexemeType.CATCH;
                }
                else if (TempLexemeValue == "finally")
                {
                    TempLexeme.Type = LexemeType.FINALLY;
                }
                else if (TempLexemeValue == "throw")
                {
                    TempLexeme.Type = LexemeType.THROW;
                }

                else if (TempLexemeValue == "return")
                {
                    TempLexeme.Type = LexemeType.RETURN;
                }


                else if (Regex.Match(TempLexemeValue, @"^[A-Za-z_]([A-Za-z0-9_]*)$").Success)
                {
                    TempLexeme.Type = LexemeType.ID;
                }
                else if (Regex.Match(TempLexemeValue, "^([0-9]*)$").Success || Regex.Match(TempLexemeValue, @"^([0-9]*)(\.([0-9])*)?(E[+-]?([0-9]*))$").Success)
                {
                    TempLexeme.Type = LexemeType.INT_VALUE;
                    int Temp = 0;
                    int.TryParse(TempLexemeValue, out Temp);
                    TempLexeme.Value = Temp;
                }
                else if (Regex.Match(TempLexemeValue, @"^([0-9]*)\.([0-9]*)$").Success)
                {
                    TempLexeme.Type = LexemeType.FLOAT_VALUE;
                    double Temp = 0;
                    double.TryParse(TempLexemeValue, out Temp);
                    TempLexeme.Value = Temp;
                }
                else
                {
                    Error Error = new Error();
                    Error.ID          = ErrorID.C0009;
                    Error.ErrorDetail = "The scanner failed to recogonize the type of the lexeme \"" + TempLexemeValue + "\". Check your spelling.";
                    Error.LineNo      = ScLineCount;
                    ErrorHandler.ErrorHandler.EhErrorOutput(Error);
                    ScStopScanning = true;
                }

                return(TempLexeme);
            } // //if Bolck
        }     // ScGetLast : Lexeme