private void ProcessInnerParenthesis(ISymbol <string, string> readed, ISymbolReader <string, string> reader) { var parenthesisStatus = 1; this.currentReadingValues.Add(readed); do { if (reader.IsAtEOF()) { throw new OdmpProblemException("Matriz set is in a wrong format."); } else { readed = reader.Get(); if (this.elementsDelimiterTypes.ContainsKey(readed.SymbolType)) { this.ProcessDelimiteres(readed, reader); } else if (readed.SymbolType == "left_parenthesis") { ++parenthesisStatus; } else if (readed.SymbolType == "right_parenthesis") { --parenthesisStatus; } this.currentReadingValues.Add(readed); } } while (parenthesisStatus > 0); }
/// <summary> /// A transição inicial - estado 0. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> private IState <string, string> StartState(ISymbolReader <string, string> reader) { this.IgnoreVoids(reader); var readed = reader.Get(); if (reader.IsAtEOF()) { throw new OdmpProblemException("Unexpected end of file."); } if (readed.SymbolType == "left_bracket") { return(this.states[2]); } return(this.states[0]); }
private void ProcessDelimiteres(ISymbol <string, string> readed, ISymbolReader <string, string> reader) { var closeDelimiters = this.elementsDelimiterTypes[readed.SymbolType]; this.currentReadingValues.Add(readed); do { if (reader.IsAtEOF()) { throw new OdmpProblemException("Matriz set is in a wrong format."); } else { readed = reader.Get(); this.currentReadingValues.Add(readed); } } while (!closeDelimiters.Contains(readed.SymbolType)); }
/// <summary> /// A função correspondente à transição de vírgula - estado 6. /// </summary> /// <param name="reader">O leitor.</param> /// <returns>O próximo estado.</returns> private IState <string, ELambdaExpressionWordType> CommaTransition( ISymbolReader <string, ELambdaExpressionWordType> reader) { if (reader.IsAtEOF()) { } else { var readed = reader.Get(); switch (readed.SymbolType) { case ELambdaExpressionWordType.ALPHA: break; case ELambdaExpressionWordType.DELIMITER: break; case ELambdaExpressionWordType.CLOSE_PARENTHESIS: break; case ELambdaExpressionWordType.COMMA: break; case ELambdaExpressionWordType.NUMERIC: break; case ELambdaExpressionWordType.OPEN_PARENTHESIS: break; case ELambdaExpressionWordType.OTHER: break; case ELambdaExpressionWordType.SPACE: break; } } throw new NotImplementedException(); }
/// <summary> /// A funçáo correspondente à transição inicial - estado 0. /// </summary> /// <param name="reader">O leitor.</param> /// <returns>O próximo estado.</returns> private IState <string, ELambdaExpressionWordType> StartTransition( ISymbolReader <string, ELambdaExpressionWordType> reader) { if (reader.IsAtEOF()) { // Termina de forma vazia. return(this.stateList[1]); } else { var readed = reader.Get(); switch (readed.SymbolType) { case ELambdaExpressionWordType.ALPHA: break; case ELambdaExpressionWordType.DELIMITER: break; case ELambdaExpressionWordType.CLOSE_PARENTHESIS: break; case ELambdaExpressionWordType.COMMA: break; case ELambdaExpressionWordType.NUMERIC: break; case ELambdaExpressionWordType.OPEN_PARENTHESIS: break; case ELambdaExpressionWordType.OTHER: break; } return(this.stateList[0]); } }
/// <summary> /// Estado de leitura da colecção de matrizes - estado 2. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> private IState <string, string> InsideBracketsState(ISymbolReader <string, string> reader) { this.IgnoreVoids(reader); var readed = reader.Get(); if (reader.IsAtEOF()) { return(this.states[1]); } if (readed.SymbolType == "left_parenthesis") { return(this.states[3]); } else if (readed.SymbolType == "right_bracket") { return(this.states[1]); } else { throw new OdmpProblemException(string.Format("Unexpected symbol {0}.", readed.SymbolValue)); } }
/// <summary> /// Estado da leitura do valor - estado 4. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> private IState <string, string> ValueState(ISymbolReader <string, string> reader) { this.IgnoreVoids(reader); var readed = reader.Get(); if (reader.IsAtEOF()) { throw new OdmpProblemException("Unexpected end of file."); } this.currentReadingValues.Clear(); if (this.elementsDelimiterTypes.ContainsKey(readed.SymbolType)) { this.ProcessDelimiteres(readed, reader); } else if (readed.SymbolType == "left_parenthesis") { this.ProcessInnerParenthesis(readed, reader); } else { this.currentReadingValues.Add(readed); } var error = new LogStatus <string, EParseErrorLevel>(); var value = this.objectElementsReader.Parse(this.currentReadingValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new OdmpProblemException(string.Format("Can't parse value {0}.", readed.SymbolValue)); } this.SetValueInMatrixSet(this.componentCoord, this.lineCoord, this.columnCoord, value); this.coordState = 0; return(this.states[2]); }
/// <summary> /// Estado de leitura das coordenadas - estado 3. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> private IState <string, string> InsideParenthesisState(ISymbolReader <string, string> reader) { this.IgnoreVoids(reader); var readed = reader.Get(); if (reader.IsAtEOF()) { throw new OdmpProblemException("Unexpected end of file."); } this.currentReadingValues.Clear(); if (readed.SymbolType == "right_parenthesis") { if (this.coordState != 3) { throw new OdmpProblemException(string.Format( "Wrong number, {0}, of coordinates. Expecting 3.", this.coordState)); } this.coordState = 0; return(this.states[4]); } else if (readed.SymbolType == "left_parenthesis") { this.ProcessInnerParenthesis(readed, reader); } else if (this.elementsDelimiterTypes.ContainsKey(readed.SymbolType)) { this.ProcessDelimiteres(readed, reader); } else { this.currentReadingValues.Add(readed); } var error = new LogStatus <string, EParseErrorLevel>(); switch (this.coordState) { case 0: this.componentCoord = this.componentElementsReader.Parse(this.currentReadingValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new OdmpProblemException(string.Format("Can't parse component coordinate: {0}.", readed.SymbolValue)); } break; case 1: this.lineCoord = this.lineElementsReader.Parse(this.currentReadingValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new OdmpProblemException(string.Format("Can't parse line coordinate: {0}.", readed.SymbolValue)); } break; case 2: this.columnCoord = this.columnElementsReader.Parse(this.currentReadingValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new OdmpProblemException(string.Format("Can't parse column coordinate: {0}.", readed.SymbolValue)); } break; default: throw new OdmpProblemException("An internal error has occured."); } ++this.coordState; return(this.states[3]); }