It is because you didn't write a rule for \n, so the default action is to echo it to the output. You need a rule to ignore all whitespace, something like [ \t\r\n\f]+ ;.
Anything between [ and ] means 'any of these characters'. The characters are space, TAB, CR, LF, FF. The + means 'one or more'. The ; is the C++ code to execute: in this case, an empty statement, meaning 'do nothing'.