Example #1
0
 private void Error(int errorCode)
 {
     ioModule.AddError(errorCode, lexicalAnalyzer.CurrentLineNumber, lexicalAnalyzer.CurrentPositionInLine);
 }
Example #2
0
        private void ScanSymbol()
        {
            if (LexicalUtils.IsDigit(currentCharacter.Value))
            {
                ScanNumber();
            }
            else if (LexicalUtils.IsStringConstantStart(currentCharacter.Value))
            {
                ScanString();
            }
            else if (LexicalUtils.IsIdentifierStart(currentCharacter.Value))
            {
                ScanIdentifier();
            }
            else
            {
                switch (currentCharacter.Value)
                {
                case '<':
                    currentCharacter = ioModule.NextCh();
                    if (currentCharacter.Value == '=')
                    {
                        CurrentSymbol    = SymbolEnum.LessEquals;
                        currentCharacter = ioModule.NextCh();
                    }
                    else
                    {
                        if (currentCharacter.Value == '>')
                        {
                            CurrentSymbol    = SymbolEnum.NotEquals;
                            currentCharacter = ioModule.NextCh();
                        }
                        else
                        {
                            CurrentSymbol = SymbolEnum.Less;
                        }
                    }
                    break;

                case '>':
                    currentCharacter = ioModule.NextCh();
                    if (currentCharacter.Value == '=')
                    {
                        CurrentSymbol    = SymbolEnum.GreaterEquals;
                        currentCharacter = ioModule.NextCh();
                    }
                    else
                    {
                        CurrentSymbol = SymbolEnum.Less;
                    }
                    break;

                case ':':
                    currentCharacter = ioModule.NextCh();
                    if (currentCharacter.Value == '=')
                    {
                        CurrentSymbol    = SymbolEnum.Assign;
                        currentCharacter = ioModule.NextCh();
                    }
                    else
                    {
                        CurrentSymbol = SymbolEnum.Colon;
                    }
                    break;

                case '+':
                    CurrentSymbol    = SymbolEnum.Plus;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '-':
                    CurrentSymbol    = SymbolEnum.Minus;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '*':
                    CurrentSymbol    = SymbolEnum.Star;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '/':
                    CurrentSymbol    = SymbolEnum.Slash;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '=':
                    CurrentSymbol    = SymbolEnum.Equals;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '(':
                    currentCharacter = ioModule.NextCh();
                    if (currentCharacter.Value == '*')
                    {
                        ScanMultilineComment();
                    }
                    else
                    {
                        CurrentSymbol = SymbolEnum.LeftRoundBracket;
                    }
                    break;

                case ')':
                    CurrentSymbol    = SymbolEnum.RightRoundBracket;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '[':
                    CurrentSymbol    = SymbolEnum.LeftSquareBracket;
                    currentCharacter = ioModule.NextCh();
                    break;

                case ']':
                    CurrentSymbol    = SymbolEnum.RightSquareBracket;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '{':
                    CurrentSymbol    = SymbolEnum.LeftCurlyBracket;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '}':
                    CurrentSymbol    = SymbolEnum.RightCurlyBracket;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '.':
                    currentCharacter = ioModule.NextCh();
                    if (currentCharacter.Value == '.')
                    {
                        CurrentSymbol    = SymbolEnum.TwoDots;
                        currentCharacter = ioModule.NextCh();
                    }
                    else
                    {
                        CurrentSymbol = SymbolEnum.Dot;
                    }
                    break;

                case ',':
                    CurrentSymbol    = SymbolEnum.Comma;
                    currentCharacter = ioModule.NextCh();
                    break;

                case '^':
                    CurrentSymbol    = SymbolEnum.Arrow;
                    currentCharacter = ioModule.NextCh();
                    break;

                case ';':
                    CurrentSymbol    = SymbolEnum.Semicolon;
                    currentCharacter = ioModule.NextCh();
                    break;

                default:
                    Error = ioModule.AddError(6, CurrentLineNumber, CurrentPositionInLine);
                    break;
                }
            }
        }