I'm having a problem with this jflex file. I derived it from some work I did on another language, itself derived from a lexer from a compilation course.
package Analyse; import java_cup.runtime.*; import Exceptions.AnalyseLexicaleException; %% %class AnalyseurLexical %public %line %column %type Symbol %eofval{ return symbol(CodesLexicaux.EOF) ; %eofval} // %unicode %cup // %debug %{ private StringBuilder chaine ; private Symbol symbol(int type) { return new Symbol(type, yyline, yycolumn) ; } private Symbol symbol(int type, Object value) { return new Symbol(type, yyline, yycolumn, value) ; } %} // Définition générales // -------------------- chiffre = [0-9] lettre = [a-zA-Z] majuscule = [A-Z] minuscule = [a-z] chiffrelettre = {chiffre} | {lettre} csteE = {chiffre}+ booleen = "true" | "false" finDeLigne = \r|\n espace = {finDeLigne} | [ \t\f] idvar = {minuscule}+ idalias = {majuscule}{chiffrelettre}* idf = {lettre}+ %% // Commentaires // ------------ "//".* { /* DO NOTHING */ } // Ponctuation ";" { return symbol(CodesLexicaux.SEMICOLON); } // fin de commande "," { return symbol(CodesLexicaux.COMMA); } // virgule // Entiers {csteE} { return symbol(CodesLexicaux.NUMBER, yytext()); } // entier // Fractions "/" { return symbol(CodesLexicaux.FRAC); } // fraction // Égalité des atomes de LQ "=" { return symbol(CodesLexicaux.EQUALS); } // égalité // Parenthèses // ----------- "(" { return symbol(CodesLexicaux.LPAREN); } ")" { return symbol(CodesLexicaux.RPAREN); } "[" { return symbol(CodesLexicaux.LBRACKET); } "]" { return symbol(CodesLexicaux.RBRACKET); } "{" { return symbol(CodesLexicaux.LBRACE); } "}" { return symbol(CodesLexicaux.RBRACE); } // Connecteurs logique // ------------------- "not" { return symbol(CodesLexicaux.NOT); } // négation logique "and" { return symbol(CodesLexicaux.AND); } // conjonction "or" { return symbol(CodesLexicaux.OR); } // disjonction // "xor" { return symbol(CodesLexicaux.XOR); } // ou exclusif // "->" { return symbol(CodesLexicaux.IMPLIES); } // implication // "<->" { return symbol(CodesLexicaux.IIF); } // équivalence // Symboles de variation "^" { return symbol(CodesLexicaux.TOTHE); } // exposant "." { return symbol(CodesLexicaux.DOT); } // point "+" { return symbol(CodesLexicaux.PLUS); } // plus // Commandes // --------- ":=" { return symbol(CodesLexicaux.ASSIGN); } // affectation "print" { return symbol(CodesLexicaux.PRINT); } // printing a result // Identifiants de variables et d'alias {idvar} { return symbol(CodesLexicaux.IDVAR, yytext()); } // identifiant de variable {idalias} { return symbol(CodesLexicaux.IDALIAS, yytext()); } // identifiant d'alias {idf} { return symbol(CodesLexicaux.IDENTIFIER, yytext()); } // identifiant générique // Divers {espace} { } I only changed a few definitions, and changed a few things in the grammar.cup file. Now, I get this message, trying to parse the file test_parser.txt here :
Alpha := (a=1/1); Reading "../../../Tests/test_parseur.var" Error in file "../../../Tests/test_parseur.var" (line 1): This seems not to be a lexical specification (first %% is missing) Alpha := (a=1/1); 1 error, 0 warnings. So it seems the lexer can't read even the first tokens from this file... And I don't understand why. I think it has to do with only the JFlex file, but if the Grammar.cup is needed, I'll provide it.