FWIW: I'm new to flex/bison (lex/yacc) but I understand the basic concepts. win_flex 2.6.4 bison (GNU Bison) 3.7.1
I am hoping someone can point me in the right direction. I hope I have a setting wrong or missed something simple. I want to use ordinary symbols in rules for my .y file such as ';' and '>'. I'm making a pascal-like language Currently there are no s/r or r/r conflicts in the compiled grammar. Having said that, everything compiles but it seems like the parser can't pick up the single characters. For example, the parser rule: single_const_decl: IDENTIFIER '=' expression ; The parser returns an error after it gets the IDENTIFIER and fetches an error token instead of the '='. I have figured out how to get the trace output and can confirm this: Trace says it goes into state 6: State 6 5 stmts: CONST_ . const_decl 10 | CONST_ . const_decl ';' stmts 46 const_decl: . single_const_decl 47 | . const_decl ';' single_const_decl 48 single_const_decl: . IDENTIFIER '=' expr IDENTIFIER shift, and go to state 14 <<<<< Trace says it goes to state 14 const_decl go to state 15 single_const_decl go to state 16 State 14 48 single_const_decl: IDENTIFIER . '=' expr '=' shift, and go to state 31 <<=== Does not happen. Returns an error token instead. I must be doing something wrong - I'm wondering if I'm missing something simple. Here's what I think what could be relevant lines of code: FLEX: %option nodefault %option c++ %option yyclass="Scanner" %option prefix="gen" %option noyywrap %option yylineno %option case-insensitive %option nounistd %option stack inum [0-9]+ alpha [A-Za-z_]+ ident {alpha}({alpha}|{inum})* /* *snip* */ %% /* *snip* */ {ident} { return gen::Parser::make_IDENTIFIER(result.makeIdentifier(yytext), loc); } /* everything else */ [ \t\r\n]+ ; /* whitespace */ . { return gen::Parser::make_YYerror(loc); } // { yyerror("Unknown character '%c'", *yytext); } NOTE: In case this matters, I would have assumed the whitespace rule and the '.' would have taken care of all possible input conditions but I still get this: 1>Target FlexTarget: 1> Process "scanner.l" flex file 1> scanner.l:154: warning, -s option given but default rule can be matched There are no other errors/warnings for the file. BISON: /* C++ parser interface */ %skeleton "lalr1.cc" %require "3.2" %language "c++" %locations %defines %define api.parser.class { Parser } %define api.token.constructor %define api.value.type variant %define api.namespace { gen } %define parse.error verbose %define parse.lac full The parser rule in question is: single_const_decl: IDENTIFIER '=' expression { $$ = result.makeConstant($1, $3); } ; Thanks for any help :)