Higuys, I want to parsing a text using Byacc. The text is made clearly by spaces and new line. What do you think about these rules to parse one text?
text: /* empty string */ {$$ = "";}
|TEXT {$$ = $1;}
|TEXT whitespace text {$$ = $1 + $2 + $3;}
|TEXT line whitespace text {$$ = $1 + $2 + $4;}
The token TEXT is in the Jflex file, and it represents one single word. The other two rules, whitespace and line are down:
line : NL { $$ = System.lineSeparator(); }
| line NL { $$ = $1 + System.lineSeparator(); }
whitespace: WHITESPACE {$$ = " ";}
|whitespace WHITESPACE {$$ = $1 + " ";}
Is my "text"'s rule wrong? Thaks