Flex: trying to generate a C++ lexer using Flex; "unrecognized rule" error

Viewed 342

I am trying to generate a lexer using flex. This is my definition file lexer.l:

%{
#include <iostream>

using namespace std;

//#define YY_DECL extern "C" int yylex()
%}

staffType "grand" | "treble" | "bass" | "alto" | "tenor"
upperRomans "I" | "II" | "III" | "IV" | "V" | "VI" | "VII"
lowerRomans "i" | "ii" | "iii" | "iv" | "v" | "vi" | "vii"
quality "dim" | "halfdim" | "aug" | "maj" | "min"

%%

[ \t\n]+ { ; // Ignore arbitrary whitespace. }
{staffType} { cout << "Staff" << endl; }
{upperRomans} { cout << "Upper roman" << endl; }
{lowerRomans} { cout << "Lower roman" << endl; }
"doublebar" { cout << "End of line" << endl; }
. { cout << "Parse error" << endl; }

%%

int main(int, char**) {
    // lex through the input
    yylex();
}

However, after invoking:

flex lexer.l

I get:

lexer.l:18: unrecognized rule
lexer.l:19: unrecognized rule
lexer.l:20: unrecognized rule

My flex version is flex 2.5.35 Apple(flex-31).

What have I done wrong?

1 Answers
Related