The lexer is ok with 123foo and will split it into two tokens.
- Integer constant
- and identifier.
But try to find the part in the syntax that allows these two tokens to sit side by side. Thus, I am sure that the lexer generates an error when it sees these two tokens.
Note that the lexer does not care about spaces (unless you explicitly say so, be careful). In this case, it just throws a space:
[ \t\v\n\f] { count(); }
Just to check what I created:
wget http://www.lysator.liu.se/c/ANSI-C-grammar-l.html > ll wget http://www.lysator.liu.se/c/ANSI-C-grammar-y.html > yy
Edited ll file to stop at the compiler complaining about undeclared functions:
#include "y.tab.h"
Create the following file: main.c:
#include <stdio.h> extern int yylex(); int main() { int x; while((x = yylex()) != 0) { fprintf(stdout, "Token(%d)\n", x); } }
Build it:
$ bison -d yy yy: conflicts: 1 shift/reduce $ flex ll $ gcc main.c lex.yy.c $ ./a.out 123foo 123Token(259) fooToken(258)
Yes, he divided it into two tokens.
source share