help me create a yacc grammar for parsing a simple expression, specifically this expression:
1;1;1;1;1;
It's important to consider some specifics:
- Semicolon may be optional after the last '1'
- The expression can be separated by a newline character, and the newline character can be placed either before or after the semicolon.
No matter what I try, I lack the skills; it's just becoming a puzzle. Here's my grammar:
%{
package main
%}
%union {
token Token
}
%token<token> Number
%%
start: expressions
expressions: Number
| expressions NEWLINE
| expressions SEMICOLON opt_Number
;
opt_Number: | Number
NEWLINE: '\n';
SEMICOLON: ';' ;
%%
It covers cases like 1;1;1;1, 1;1;1;1;, and 1;1;1\n;1, but it doesn't cover 1;1;\n1;1.
What am I missing?