private tokenObject ProcessWord() { _currentLexeme = _currentCharacterRead.ToString(); while (char.IsLetterOrDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead; } var newToken = new tokenObject(_dictionary.identifyString(_currentLexeme), _currentLexeme, _lastLocation); ClearContent(); return(newToken); }
private tokenObject ProcessCharacter() { _currentLexeme = _currentCharacterRead.ToString(); AdvanceCursors(); if (_currentCharacterRead == '\\') { _currentLexeme += _currentCharacterRead.ToString(); AdvanceCursors(); } _currentLexeme += _currentCharacterRead.ToString(); AdvanceCursors(); if (_currentCharacterRead != '\'') { throw new Exception("Character Too Long or Not Closed At: " + _lastLocation); } _currentLexeme += _currentCharacterRead.ToString(); var returnToken = new tokenObject(tokenType.literal_CHARACTER, _currentLexeme, _lastLocation); ClearContent(); return(returnToken); }
private tokenObject ProcessFileName() { _currentLexeme = _currentCharacterRead.ToString(); while (_nextCharacterRead != '>') { AdvanceCursors(); if (_currentCharacterRead == '\r' || _currentCharacterRead == '\n') { throw new Exception("No Spaces or New Lines Permitted between File Names. AT:" + _lastLocation); } else { _currentLexeme += _currentCharacterRead.ToString(); } } AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); var newToken = new tokenObject(tokenType.literal_FILENAME, _currentLexeme, _lastLocation); ClearContent(); return(newToken); }
private tokenObject ProcessString() { _currentLexeme = _currentCharacterRead.ToString(); while (_nextCharacterRead != '"') { AdvanceCursors(); if (_currentCharacterRead == '\r' || _currentCharacterRead == '\n') { } else { _currentLexeme += _currentCharacterRead.ToString(); } } AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); var newToken = new tokenObject(tokenType.literal_STRING, _currentLexeme, _lastLocation); ClearContent(); return(newToken); }
private tokenObject ProcessNumber() { _currentLexeme = _currentCharacterRead.ToString(); var whatKindOfNumberIsIt = "NUMBER"; if (_currentCharacterRead == '0') { switch (_nextCharacterRead.ToString()) { case "ADVANCE": AdvanceCursors(); _currentLexeme += _currentCharacterRead; break; case ".": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": whatKindOfNumberIsIt = "OCTAL"; goto case "ADVANCE"; case "x": whatKindOfNumberIsIt = "HEXADECIMAL"; goto case "ADVANCE"; default: break; } if (_nextCharacterRead == '.') { switch (whatKindOfNumberIsIt) { case "ADVANCE": AdvanceCursors(); _currentLexeme += _currentCharacterRead; break; case "NUMBER": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "OCTAL": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "HEXADECIMAL": throw new Exception("HEXADECIMALS CAN NOT CONTAIN PERIODS. " + _lastLocation); break; case "FLOAT": throw new Exception("FLOATS DO NOT HAVE MULTIPLE DOTS. " + _lastLocation); break; } } if (char.IsDigit(_nextCharacterRead)) { while (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead; if (_nextCharacterRead == '.') { switch (whatKindOfNumberIsIt) { case "ADVANCE": AdvanceCursors(); _currentLexeme += _currentCharacterRead; break; case "NUMBER": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "OCTAL": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "HEXADECIMAL": throw new Exception("HEXADECIMALS CAN NOT CONTAIN PERIODS. " + _lastLocation); break; case "FLOAT": throw new Exception("FLOATS DO NOT HAVE MULTIPLE DOTS. " + _lastLocation); break; } } } } else { if (whatKindOfNumberIsIt == "NUMBER" || whatKindOfNumberIsIt == "OCTAL") { } else if (whatKindOfNumberIsIt == "HEXADECIMAL" || whatKindOfNumberIsIt == "FLOAT") { throw new Exception("WRONG NUMBER DEFINITION AT: " + _lastLocation); } } } else { while (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead; if (_nextCharacterRead == '.') { switch (whatKindOfNumberIsIt) { case "ADVANCE": AdvanceCursors(); _currentLexeme += _currentCharacterRead; break; case "NUMBER": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "OCTAL": whatKindOfNumberIsIt = "FLOAT"; goto case "ADVANCE"; case "HEXADECIMAL": throw new Exception("HEXADECIMALS CAN NOT CONTAIN PERIODS. " + _lastLocation); break; case "FLOAT": throw new Exception("FLOATS DO NOT HAVE MULTIPLE DOTS. " + _lastLocation); break; } } } } var whatKindOfTokenIsIt = tokenType.NaN; switch (whatKindOfNumberIsIt) { case "NUMBER": whatKindOfTokenIsIt = tokenType.literal_NUMBER; break; case "OCTAL": whatKindOfTokenIsIt = tokenType.literal_OCTAL; break; case "HEXADECIMAL": whatKindOfTokenIsIt = tokenType.literal_HEXADECIMAL; break; case "FLOAT": whatKindOfTokenIsIt = tokenType.literal_FLOAT; break; } var newToken = new tokenObject(whatKindOfTokenIsIt, _currentLexeme, _lastLocation); ClearContent(); return(newToken); }
private tokenObject ProcessDate() { _currentLexeme = _currentCharacterRead.ToString(); if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (_nextCharacterRead == '-') { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (_nextCharacterRead == '-') { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (char.IsDigit(_nextCharacterRead)) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } if (_nextCharacterRead == '#') { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); } else { throw new Exception("Wrong Date Format. Correct format is #DD-MM-YYYY#"); } var newToken = new tokenObject(tokenType.literal_DATE, _currentLexeme, _lastLocation); ClearContent(); return(newToken); }
private tokenObject ProcessSymbolsAndPunctuations() { if (_currentCharacterRead == '_' && char.IsLetterOrDigit(_nextCharacterRead)) { return(ProcessWord()); } _currentLexeme = _currentCharacterRead.ToString(); tokenType probableTokenType = tokenType.NaN; if (_dictionary.identifySymbolAndPunctuation(_currentLexeme) != tokenType.ErrorToken) { probableTokenType = _dictionary.identifySymbolAndPunctuation(_currentLexeme); switch (_currentLexeme) { case "<": if (char.IsLetter(_nextCharacterRead)) { return(ProcessFileName()); } break; case "\'": return(ProcessCharacter()); break; case "\"": return(ProcessString()); break; case "#": if (char.IsDigit(_nextCharacterRead)) { return(ProcessDate()); } break; } while (_dictionary.identifySymbolAndPunctuation(_currentLexeme + _nextCharacterRead) != tokenType.ErrorToken) { AdvanceCursors(); _currentLexeme += _currentCharacterRead.ToString(); probableTokenType = _dictionary.identifySymbolAndPunctuation(_currentLexeme); if (probableTokenType == tokenType.symbol_COMMENTLINE) { while (_nextCharacterRead != '\n') { AdvanceCursors(); } ////var returnToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation); var returnToken = GenerateToken(); ClearContent(); return(returnToken); } if (probableTokenType == tokenType.symbol_commentOpen) { AddLayer("COMMENTBLOCK"); // var returnToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation); var returnToken = GenerateToken(); ClearContent(); return(returnToken); } } } else { throw new Exception("This Symbol Does not Exist. " + _currentLexeme + " At: " + _lastLocation); } var newToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation); ClearContent(); return(newToken); }