0
votes

I am doing a project with a Pascal subset. My code looks like:

NLINE       [\n]
BRACKET     ['('|')']

%%

{BRACKET} {
  std::cout << "Found BRACKET symbol " << yytext[0] << std::endl;
  return yytext[0];
}

{NLINE} {
  std::cout << "Found NEWLINE symbol " << yytext[0] << std::endl;
  yylineno++;
}

...

. { // anything is exactly before EOF
    std::cout << "Found ANYTHING " << yytext[0] << std::endl;
    yylval = NONE;
    return yytext[0];
}

I tried many ways to deal with that, also just \n instead of [\n] or [ \n] but without the expected results. Below is the output:

...
Found BRACKET symbol )
Found ANYTHING ;
Found ANYTHING  << where in code should be \n

I know that this is \n issue, because when I push the code without that it works like a charm!

Will appreciate every constructive answer.

1
The correct pattern to match ( or ) is [()]. Your pattern will match a parenthesis, an apostrophe, or a vertical bar. - rici
Also, I have no idea what you mean by "when I push the code without that". - rici
I mean when I cut all \n from input file. All just in one line, which is not highly comfortable. Sorry, I didn't express myself clearly enough. - Kris

1 Answers

0
votes

The problem seemed to be the carriage return symbol. In case you will have similar issue, if this won't help, you should check other nonprintable characters.

In my case helped:

DELIM       [ \t\r]

DELIM is "eated" in my solution so no rule is applied.