Beispiel #1
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '-')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = TokenType.OpDec, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = TokenType.OpAssigSub, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else
     {
         return(new Token {
             Type = TokenType.OpSub, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
 }
Beispiel #2
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '>')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateRightShift2().ProcessState(pInput, pLexeme));
         //return new Token { Type = TokenType.OpRightShiftZeroFill, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column };
     }
     else if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token
         {
             Type = TokenType.OpAssigRightShift,
             LexemeVal = pLexeme.Value,
             Row = pInput.Row,
             Column = pInput.Column
         });
     }
     else
     {
         return(new Token {
             Type = TokenType.OpRightShift, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
 }
Beispiel #3
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '/')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateCommentLine().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '*')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateCommentBlock1().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = TokenType.OpAssigDiv, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else
     {
         return(new Token {
             Type = TokenType.OpDiv, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
 }
Beispiel #4
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (char.IsLetter(pInput.CurrentSymbol) || pInput.CurrentSymbol == '_' || char.IsDigit(pInput.CurrentSymbol))
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateId().ProcessState(pInput, pLexeme));
     }
     else
     {
         if (!KeyWords.Contains(pLexeme.Value))
         {
             return(new Token {
                 Type = TokenType.Id, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
             });
         }
         else
         {
             return(new Token {
                 Type = KeyWords.GetTokenType(pLexeme.Value), LexemeVal = pLexeme.Value,
                 Row = pInput.Row, Column = pInput.Column
             });
         }
     }
 }
Beispiel #5
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '/' || pInput.CurrentSymbol == '\r')
     {
         //pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         //return new Token { Type = TokenType.COMMENT_BLOCK, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column };
         return(new InitialState().ProcessState(pInput, pLexeme = new Lexeme()));
     }
     else
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateCommentBlock1().ProcessState(pInput, pLexeme));
     }
 }
Beispiel #6
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '*')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateCommentBlock2().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == (char)0)
     {
         throw new LexerException("Lexical Error: Was expected */', Row: " + pInput.Column + ", Column: " + pInput.CurrentColumn);
     }
     else
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateCommentBlock1().ProcessState(pInput, pLexeme));
     }
 }
Beispiel #7
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (char.IsDigit(pInput.CurrentSymbol))
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateFloat2().ProcessState(pInput, pLexeme));
     }
     else
     {
         throw new LexerException("Symbol: " + pInput.CurrentSymbol + " is not a number, a number was expected, Row: " + pInput.Row + ", Column: " + pInput.CurrentColumn);
     }
 }
Beispiel #8
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (char.IsDigit(pInput.CurrentSymbol))
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateDigit().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '.')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateFloat1().ProcessState(pInput, pLexeme));
     }
     else
     {
         return(new Token {
             Type = TokenType.LitInteger, LexemeVal = pLexeme.Value,
             Column = pInput.Column, Row = pInput.Row
         });
     }
 }
Beispiel #9
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = TokenType.OpLessEqualThan, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else if (pInput.CurrentSymbol == '<')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateLeftShift().ProcessState(pInput, pLexeme));
     }
     else
     {
         return(new Token {
             Type = TokenType.OpLessThan, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
 }
Beispiel #10
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateEquiv().ProcessState(pInput, pLexeme));
     }
     else
     {
         return(new Token {
             Type = TokenType.OpAssig, LexemeVal = pLexeme.Value, Column = pInput.Column, Row = pInput.Row
         });
     }
 }
Beispiel #11
0
 public Token ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     if (pInput.CurrentSymbol == '\\')
     {
         //pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         if (pInput.CurrentSymbol == '\'')
         {
             pLexeme.addSymbol('\'');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == '\"')
         {
             pLexeme.addSymbol('\"');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == '\\')
         {
             pLexeme.addSymbol('\\');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == 'n')
         {
             pLexeme.addSymbol('\n');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == 'r')
         {
             pLexeme.addSymbol('\r');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == 't')
         {
             pLexeme.addSymbol('\t');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == 'b')
         {
             pLexeme.addSymbol('\b');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else if (pInput.CurrentSymbol == 'f')
         {
             pLexeme.addSymbol('\f');
             pInput.ConsumeSymbol();
             return(new StateString1().ProcessState(pInput, pLexeme));
         }
         else
         {
             throw new LexerException("Symbol: " + pInput.CurrentSymbol + " not recognized");
         }
     }
     else if (pInput.CurrentSymbol == (char)0)
     {
         throw new LexerException("Lexical Error: Was expected \', Row: " + pInput.Column + ", Column: " + pInput.CurrentColumn);
     }
     else if (pInput.CurrentSymbol == '\'')
     {
         //pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = TokenType.LitString, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateString1().ProcessState(pInput, pLexeme));
     }
 }
Beispiel #12
0
 public Token    ProcessState(InputStream pInput, Lexeme pLexeme)
 {
     pInput.CtrlNewToken = true;
     if (char.IsLetter(pInput.CurrentSymbol) || pInput.CurrentSymbol == '_')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateId().ProcessState(pInput, pLexeme));
     }
     else if (PunctuationMarks.Contains(pInput.CurrentSymbol))
     {
         var _token = PunctuationMarks.GetTokenType(pInput.CurrentSymbol);
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token {
             Type = _token, LexemeVal = pLexeme.Value, Row = pInput.Row, Column = pInput.Column
         });
     }
     else if (pInput.CurrentSymbol == '~')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token
         {
             Type = TokenType.OpNotBit,
             LexemeVal = pLexeme.Value,
             Row = pInput.Row,
             Column = pInput.Column
         });
     }
     else if (pInput.CurrentSymbol == '?')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new Token
         {
             Type = TokenType.OpTernary,
             LexemeVal = pLexeme.Value,
             Row = pInput.Row,
             Column = pInput.Column
         });
     }
     else if (pInput.CurrentSymbol == '^')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateBitwiseXOr().ProcessState(pInput, pLexeme));
     }
     else if (char.IsDigit(pInput.CurrentSymbol))
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateDigit().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '=')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateAssig().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '+')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateSum().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '-')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateSub().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '*')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateMul().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '%')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateMod().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '!')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateNot().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '<')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateLessThan().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '>')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateGreaterThan().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '&')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateAnd().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '|')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateOr().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '/')
     {
         pLexeme.addSymbol(pInput.CurrentSymbol);
         pInput.ConsumeSymbol();
         return(new StateDiv().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '\'')
     {
         pInput.ConsumeSymbol();
         return(new StateString1().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == '\"')
     {
         pInput.ConsumeSymbol();
         return(new StateString2().ProcessState(pInput, pLexeme));
     }
     else if (char.IsWhiteSpace(pInput.CurrentSymbol) || pInput.CurrentSymbol == '\n' ||
              pInput.CurrentSymbol == '\r' || pInput.CurrentSymbol == '\t')
     {
         pInput.ConsumeSymbol();
         return(new InitialState().ProcessState(pInput, pLexeme));
     }
     else if (pInput.CurrentSymbol == (char)0)
     {
         return(new Token {
             Type = TokenType.Eof, LexemeVal = "", Row = pInput.Row, Column = pInput.Column
         });
     }
     else
     {
         throw new LexerException("Symbol: " + pInput.CurrentSymbol + " not recognized");
     }
 }