Is it possible to produce a small working example of a parser generator, using yacc, without relying on a lexer spec? Most textbook parser specification relies on a lexer, which makes the parser example a bit complex for students to grasp (imho).
If by "without a lexer spec", you mean without generating a lexical scanner from a (f)lex specification, then you will find a number of examples of small working parsers with hand-built lexers in the Bison manual. These are an important (and often neglected) resource for students and novices.
If you mean "without a lexer", then the answer is "No". Yacc (and, as far as I know, all of its commonly-used derivatives) requires that input comes from the yylex
external function. Under normal circumstances, yacc/byacc/bison-generated parsers do not interact with stdio
at all; they rely on yylex
to decompose the input into tokens, and they rely on yyerror
to dispose of error messages.
There are other parser-generators which either have lexical analysis built-in, so that there is only one specification (although it it usually distinguished into two parts), or which produce "scannerless parsers". Both of these approaches seem to have their own idiosyncracies which can be confusing to learners, but I don't believe it is possible to adequately discuss this point without violating StackOverflow's admonition against opinion-based answers.