示例#1
0
 public Token AddChar(currentChar c)
 {
     Token tokenToReturn  = null;
     //check if the char is legal in this context
     if (syntaxIllegalCharTypes.Contains(c.currentCharTokenType)) {
         throw new Exception("Illegal char placement");
     }
     //The char is legal. Check we if we should publish the current string
     if (!charsThatAppendToCurrentString.Contains(c.currentCharTokenType) && tokenString.Count() > 0) {
         tokenToReturn = new Token(tokenString, currentStringTokenType);
         tokenString = string.Empty;
     }
     //Append Char
     tokenString += c.val;
     //Depending on the current char type:
     //Set the local string type and other currenttoken state values
     //Set publication types and char legal types
     switch (c.currentCharTokenType) {
         case CharType.arithmeticOp:
             //Set local string type
             if (c.val == '=')
                 currentStringTokenType = TokenType.equalSign;
             else
                 currentStringTokenType = TokenType.arithmeticOp;
             //Set the value of the publication type, etc.
             //Publish on every char type
             charsThatAppendToCurrentString = new HashSet<CharType>() {};
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.arithmeticOp, CharType.syntaxChar };
             break;
         case CharType.brace:
             if(c.val == ')')
                 currentStringTokenType = TokenType.closedBrace;
             if (c.val == '(')
                 currentStringTokenType = TokenType.openBrace;
             charsThatAppendToCurrentString = new HashSet<CharType>() {};
             syntaxIllegalCharTypes = new HashSet<CharType>() { };
             break;
         case CharType.letter:
             currentStringTokenType = TokenType.charString;
             charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.letter, CharType.number };
             syntaxIllegalCharTypes = new HashSet<CharType>() { };
             break;
         case CharType.number:
             //We're not dealing with a word - we're dealing with a number or +/-
             if (currentStringTokenType != TokenType.charString) {
                 currentStringTokenType = TokenType.number;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.number, CharType.letter };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { };
             } else {
                 currentStringTokenType = TokenType.charString;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.letter, CharType.number };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { };
             }
             break;
         case CharType.plusOrMinusSign:
             currentStringTokenType = TokenType.arithmeticOp;
             charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.number };
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.arithmeticOp, CharType.syntaxChar };
             break;
         case CharType.syntaxChar:
             currentStringTokenType = TokenType.syntaxChar;
             charsThatAppendToCurrentString = new HashSet<CharType>() { };
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.arithmeticOp, CharType.syntaxChar };
             break;
         case CharType.whitespace:
             tokenString = string.Empty;
             break;
     }
     return tokenToReturn;
 }
示例#2
0
            public Token AddChar(currentChar c)
            {
                Token tokenToReturn = null;

                //check if the char is legal in this context
                if (syntaxIllegalCharTypes.Contains(c.currentCharTokenType))
                {
                    throw new Exception("Illegal char placement");
                }
                //The char is legal. Check we if we should publish the current string
                if (!charsThatAppendToCurrentString.Contains(c.currentCharTokenType) && tokenString.Count() > 0)
                {
                    tokenToReturn = new Token(tokenString, currentStringTokenType);
                    tokenString   = string.Empty;
                }
                //Append Char
                tokenString += c.val;
                //Depending on the current char type:
                //Set the local string type and other currenttoken state values
                //Set publication types and char legal types
                switch (c.currentCharTokenType)
                {
                case CharType.arithmeticOp:
                    //Set local string type
                    if (c.val == '=')
                    {
                        currentStringTokenType = TokenType.equalSign;
                    }
                    else
                    {
                        currentStringTokenType = TokenType.arithmeticOp;
                    }
                    //Set the value of the publication type, etc.
                    //Publish on every char type
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.arithmeticOp, CharType.syntaxChar
                    };
                    break;

                case CharType.brace:
                    if (c.val == ')')
                    {
                        currentStringTokenType = TokenType.closedBrace;
                    }
                    if (c.val == '(')
                    {
                        currentStringTokenType = TokenType.openBrace;
                    }
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                    };
                    break;

                case CharType.letter:
                    currentStringTokenType         = TokenType.charString;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                        CharType.letter, CharType.number
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                    };
                    break;

                case CharType.number:
                    //We're not dealing with a word - we're dealing with a number or +/-
                    if (currentStringTokenType != TokenType.charString)
                    {
                        currentStringTokenType         = TokenType.number;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.number, CharType.letter, CharType.period
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                        };
                    }
                    else
                    {
                        currentStringTokenType         = TokenType.charString;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.letter, CharType.number
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                        };
                    }
                    break;

                case CharType.plusOrMinusSign:
                    currentStringTokenType         = TokenType.arithmeticOp;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                        CharType.number
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.arithmeticOp, CharType.syntaxChar
                    };
                    break;

                case CharType.syntaxChar:
                    currentStringTokenType         = TokenType.syntaxChar;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.arithmeticOp, CharType.syntaxChar
                    };
                    break;

                case CharType.whitespace:
                    tokenString = string.Empty;
                    break;
                }
                return(tokenToReturn);
            }
示例#3
0
 public IToken AddChar(currentChar c)
 {
     IToken tokenToReturn  = null;
     //check if the char is legal in this context
     if (syntaxIllegalCharTypes.Contains(c.currentCharTokenType)) {
         ErrorLog.Add(new ErrorMessage("Syntax illegal char cannot be added to token"));
         return null;
     }
     //The char is legal. Check we if we should publish the current string
     if (!charsThatAppendToCurrentString.Contains(c.currentCharTokenType) && tokenString.Count() > 0) {
         tokenToReturn = PublishCurrentTokenString();
         tokenString = string.Empty;
     }
     //Append Char
     tokenString += c.val;
     //Depending on the current char type:
     //Set the local string type and other currenttoken state values
     //Set publication types and char legal types
     switch (c.currentCharTokenType) {
         case CharType.infixArithmeticOp:
             currentStringTokenType = TokenType.infixOperator;
             //Set the value of the publication type, etc.
             //Publish on every char type
             charsThatAppendToCurrentString = new HashSet<CharType>() {};
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.infixArithmeticOp, CharType.comma, CharType.suffixOp };
             break;
         case CharType.suffixOp:
             currentStringTokenType = TokenType.suffixOperator;
             charsThatAppendToCurrentString = new HashSet<CharType>() {};
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.number };
             break;
         case CharType.brace:
             if(c.val == ')')
                 currentStringTokenType = TokenType.closedBrace;
             if (c.val == '(')
                 currentStringTokenType = TokenType.openBrace;
             charsThatAppendToCurrentString = new HashSet<CharType>() {};
             syntaxIllegalCharTypes = new HashSet<CharType>() { };
             break;
         case CharType.letter:
             currentStringTokenType = TokenType.charString;
             charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.letter, CharType.number };
             syntaxIllegalCharTypes = new HashSet<CharType>() { };
             break;
         case CharType.number:
             //We're not dealing with a word - we're dealing with a number or +/-
             if (currentStringTokenType != TokenType.charString) {
                 currentStringTokenType = TokenType.number;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.number, CharType.period };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { };
             } else {
                 currentStringTokenType = TokenType.charString;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.letter, CharType.number };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { };
             }
             break;
         case CharType.period:
             if (currentStringTokenType != TokenType.charString && decimalNumber == false) {
                 currentStringTokenType = TokenType.number;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.number };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.period  };
                 decimalNumber = true;
             } else {
                 currentStringTokenType = TokenType.charString;
                 charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.letter, CharType.number };
                 syntaxIllegalCharTypes = new HashSet<CharType>() { };
             }
             break;
         case CharType.plusOrMinusSign:
             currentStringTokenType = TokenType.infixOperator;
             charsThatAppendToCurrentString = new HashSet<CharType>() { CharType.number };
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.infixArithmeticOp, CharType.comma, CharType.suffixOp };
             break;
         case CharType.comma:
             currentStringTokenType = TokenType.argSeperator;
             charsThatAppendToCurrentString = new HashSet<CharType>() { };
             syntaxIllegalCharTypes = new HashSet<CharType>() { CharType.infixArithmeticOp, CharType.comma };
             break;
         case CharType.whitespace:
             tokenString = string.Empty;
             break;
     }
     return tokenToReturn;
 }
示例#4
0
            public IToken AddChar(currentChar c)
            {
                IToken tokenToReturn = null;

                //check if the char is legal in this context
                if (syntaxIllegalCharTypes.Contains(c.currentCharTokenType))
                {
                    ErrorLog.Add(new ErrorMessage("Syntax illegal char cannot be added to token"));
                    return(null);
                }
                //The char is legal. Check we if we should publish the current string
                if (!charsThatAppendToCurrentString.Contains(c.currentCharTokenType) && tokenString.Count() > 0)
                {
                    tokenToReturn = PublishCurrentTokenString();
                    tokenString   = string.Empty;
                }
                //Append Char
                tokenString += c.val;
                //Depending on the current char type:
                //Set the local string type and other currenttoken state values
                //Set publication types and char legal types
                switch (c.currentCharTokenType)
                {
                case CharType.infixArithmeticOp:
                    currentStringTokenType = TokenType.infixOperator;
                    //Set the value of the publication type, etc.
                    //Publish on every char type
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.infixArithmeticOp, CharType.comma, CharType.suffixOp
                    };
                    break;

                case CharType.suffixOp:
                    currentStringTokenType         = TokenType.suffixOperator;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.number
                    };
                    break;

                case CharType.brace:
                    if (c.val == ')')
                    {
                        currentStringTokenType = TokenType.closedBrace;
                    }
                    if (c.val == '(')
                    {
                        currentStringTokenType = TokenType.openBrace;
                    }
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                    };
                    break;

                case CharType.letter:
                    currentStringTokenType         = TokenType.charString;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                        CharType.letter, CharType.number
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                    };
                    break;

                case CharType.number:
                    //We're not dealing with a word - we're dealing with a number or +/-
                    if (currentStringTokenType != TokenType.charString)
                    {
                        currentStringTokenType         = TokenType.number;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.number, CharType.period
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                        };
                    }
                    else
                    {
                        currentStringTokenType         = TokenType.charString;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.letter, CharType.number
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                        };
                    }
                    break;

                case CharType.period:
                    if (currentStringTokenType != TokenType.charString && decimalNumber == false)
                    {
                        currentStringTokenType         = TokenType.number;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.number
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                            CharType.period
                        };
                        decimalNumber = true;
                    }
                    else
                    {
                        currentStringTokenType         = TokenType.charString;
                        charsThatAppendToCurrentString = new HashSet <CharType>()
                        {
                            CharType.letter, CharType.number
                        };
                        syntaxIllegalCharTypes = new HashSet <CharType>()
                        {
                        };
                    }
                    break;

                case CharType.plusOrMinusSign:
                    currentStringTokenType         = TokenType.infixOperator;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                        CharType.number
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.infixArithmeticOp, CharType.comma, CharType.suffixOp
                    };
                    break;

                case CharType.comma:
                    currentStringTokenType         = TokenType.argSeperator;
                    charsThatAppendToCurrentString = new HashSet <CharType>()
                    {
                    };
                    syntaxIllegalCharTypes = new HashSet <CharType>()
                    {
                        CharType.infixArithmeticOp, CharType.comma
                    };
                    break;

                case CharType.whitespace:
                    tokenString = string.Empty;
                    break;
                }
                return(tokenToReturn);
            }