Your lexer lacks rules to match and return tokens such as '+'
and '*'
, so if there are any in your input, it will just echo them and discard them. This is what happens when you enter fd (10 + 10)
-- the lexer returns the tokens FD
NUMBER
NUMBER
while +
and (
get echoed to stdout. The parser then gives a syntax error.
You want to add a rule to return these single character tokens. The easiest is to just add a single rule to your .l file at the end:
. { return *yytext; }
which matches any single character.
Note that this does NOT match a \n
(newline), so newlines in your input will still be echoed and ignored. You might want to add them (and tabs and carriage returns) to your skip blanks rule:
[ \t\r\n] { /* skip blanks */ }