0

I'm using CUP for a project but I'm not really sure how to save the value of the token TEXT into a String

here´s my production:

error_content ::= LEXEMA_START TEXT LEXEMA_END {:   System.out.println("´text value" ); :}
                | LINE_START numero LINE_END {: System.out.println("numero value"); :}
                | COLUMN_START numero COLUMN_END {: System.out.println("numero value"); :}
                | TIPO_START TEXT TIPO_END {: System.out.println("text value"); :}
                | DESCRIPCION_START TEXT DESCRIPCION_END {: 
                      String textToken = "TEXT VALUE"
                      System.out.println("p description: " + textoToken); 
                   :};

here's the complete code

parser code
{:
    public String resultado="";
    public static LinkedList<TError> TablaES = new LinkedList<TError>(); 
    public static Flexcup f = new Flexcup();


    //Metodo al que se llama en el momento en que ya no es posible una recuperacion de errores
    public void unrecovered_syntax_error(Symbol s) throws java.lang.Exception
    {        
        String lexema = s.value.toString();
        int fila = s.right;
        int columna = s.left;
        
        System.out.println("!!!!!!! Error Sintactico, Panic Mode !!!!!!! ");
        System.out.println("\t\tLexema: "+lexema);
        System.out.println("\t\tFila: "+fila);
        System.out.println("\t\tColumna: "+columna);

        TError datos = new TError(lexema,fila,columna,"Error Sintactico","Caracter no esperado");
        TablaES.add(datos);
     
    }
:}

//------> Codigo para las acciones gramaticales
action code
{:
:}

/* Clases y variables de los símbolos terminales */
terminal TEXT,
         ERROR_START, ERROR_END, ERRORS_START, ERRORS_END,
         LEXEMA_START, LEXEMA_END, TIPO_START, TIPO_END,
         LINE_START, LINE_END, COLUMN_START, COLUMN_END,
         DESCRIPCION_START, DESCRIPCION_END, numero;
non terminal document, errors, element, error_tag, error_content, error_content_list;
/* Producciones */
start with document;

document ::= errors;

errors ::= ERRORS_START element ERRORS_END;

element ::= error_tag
            | element error_tag;

error_tag ::= ERROR_START error_content_list ERROR_END;

error_content_list ::= error_content
                        | error_content_list  error_content;

error_content ::= LEXEMA_START TEXT LEXEMA_END {:   System.out.println("´text value" ); :}
                | LINE_START numero LINE_END {: System.out.println("numero value"); :}
                | COLUMN_START numero COLUMN_END {: System.out.println("numero value"); :}
                | TIPO_START TEXT TIPO_END {: System.out.println("text value"); :}
                | DESCRIPCION_START TEXT DESCRIPCION_END {: 
                      String textToken = "TEXT VALUE"
                      System.out.println("p description: " + textoToken); 
                   :};
Ale
  • 3
  • 2
  • if you want to define TEXT as a string, rather than java.lang.Object you should declare it as 'terminal String TEXT;' – A-_-S Mar 13 '23 at 15:24

0 Answers0