[Flex/Bison] Handling newlines
I'm not sure if a C programming forum is the right place to ask something regarding Flex and Bison, but people around here have been very helpful in the past so I decided to give it a try.
So, we're required to create a lexical & semantics parser as part of the Compilers course, using Flex and Bison. My issue is that I don't have a proper way to handle newlines. We're required to ignore all whitespace and newlines except if specifically asked, so I did the simple thing and had my Flex file return nothing in case of whitespace. But there is a certain rule in the language we're asked to parse that requires a newline character at the end of the line.
Rule goes something like this:
That's the only rule that specifically requires a newline. Everywhere else we're asked to ignore it. So what's a proper way of requiring the newline there, but having it ignored everywhere else so that I don't have to add optional "newline" rules in every rule that I have in my syntax?
program: PROGRAM variable_name newline