/// <summary> /// Mete los operadores al diccionario de tokens /// </summary> /// <param name="buffer"></param> private void AddOperator(string buffer, int columnStart, int columnEnd, int lineNumber) { ElToken token = new ElToken(); //code to add operator if (!esMultilinea) { if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_OPERADOR"); } MakeWriter(buffer, columnStart, columnEnd, "T_OPERADOR", lineNumber); token.Elemento = buffer; token.Tipo = "T_OPERADOR"; ListaTokens.Add(token); } }
/// <summary> /// Mete los tokens al diccionario de tokens /// </summary> /// <param name="buffer"></param> public void AddTokens(string buffer, int columnStart, int columnEnd, int lineNumber) { ElToken token = new ElToken(); if (!esMultilinea) { buffer = buffer.Trim(); var bufferIs = Segmentation(buffer, lineNumber); //call segmentacion to return into the switch para ver si es reservada o id switch (bufferIs) { case 0: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_ERROR"); } MakeWriter(buffer, columnStart, columnEnd, "T_ERROR", lineNumber); errores += "*** ERROR: No se reconoció " + buffer + " en linea: " + lineNumber + " \n"; token.Elemento = buffer; token.Tipo = "T_ERROR"; ListaTokens.Add(token); break; case 1: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, $"T_{buffer}"); } MakeWriter(buffer, columnStart, columnEnd, $"T_{buffer}", lineNumber); token.Elemento = buffer; token.Tipo = $"T_{buffer}"; ListaTokens.Add(token); break; case 2: if (buffer.Length < 32) { if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_ID"); } MakeWriter(buffer, columnStart, columnEnd, "T_ID", lineNumber); token.Elemento = buffer; token.Tipo = "T_ID"; ListaTokens.Add(token); break; } else { buffer = buffer.Substring(0, 31); if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_ID"); } errores += "*** Error: id muy largo, se trunco a 31 caracteres, ID: " + buffer + " *** en linea: " + lineNumber; MakeWriter(buffer, columnStart, columnEnd, "T_ID", lineNumber); token.Elemento = buffer; token.Tipo = "T_ID"; ListaTokens.Add(token); break; } case 3: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_BOOLEAN"); } token.Elemento = buffer; token.Tipo = "T_BOOLEAN"; MakeWriter(buffer, columnStart, columnEnd, "T_BOOLEAN", lineNumber); ListaTokens.Add(token); break; case 4: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_ENTERO"); } MakeWriter(buffer, columnStart, columnEnd, "T_ENTERO", lineNumber); token.Elemento = buffer; token.Tipo = "T_ENTERO"; ListaTokens.Add(token); break; case 5: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_DOUBLE"); } MakeWriter(buffer, columnStart, columnEnd, "T_DOUBLE", lineNumber); token.Elemento = buffer; token.Tipo = "T_DOUBLE"; ListaTokens.Add(token); break; case 6: if (!tokens.ContainsKey(buffer)) { tokens.Add(buffer, "T_CADENA"); } MakeWriter(buffer, columnStart, columnEnd, "T_CADENA", lineNumber); token.Elemento = buffer; token.Tipo = "T_CADENA"; ListaTokens.Add(token); break; } } }