-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Trying to improve the error messages for conflicts and testing a gramma that has multi character end of line \r\n
I found that actually lalr
is nothing doing it properly (see bellow my fix for it).
@@ -338,10 +357,9 @@ bool GrammarParser::match_whitespace()
{
if ( is_new_line(position) )
{
- ++line_;
- line_position_ = position;
+ position = new_line( position );
}
- ++position;
+ else ++position;
}
position_ = position;
return true;
Grammar with \r\n
:
conflicts {
%whitespace "[ \t]*";
/*
%token <ival> DREG VREG /* indices into dreg, vreg arrays */
%token <dval> CONST /* floating point constant */
%type <dval> dexp /* expression */
%type <vval> vexp /* interval expression */
*/
/* precedence information about the operators */
%left '+' '-' ;
%left '*' '/' ;
%left UMINUS ; /* precedence for unary minus */
/* beginning of rules section */
lines :
/* empty */
| lines line
;
line :
dexp '\n'
| vexp '\n'
| DREG '=' dexp '\n'
| VREG '=' vexp '\n'
| error '\n'
;
dexp :
CONST
| DREG
| dexp '+' dexp
| dexp '-' dexp
| dexp '*' dexp
| dexp '/' dexp
| '-' dexp %prec UMINUS
| '(' dexp ')'
;
vexp :
dexp
| '(' dexp ',' dexp ')'
| VREG
| vexp '+' vexp
| dexp '+' vexp
| vexp '-' vexp
| dexp '-' vexp
| vexp '*' vexp
| dexp '*' vexp
| vexp '/' vexp
| dexp '/' vexp
| '-' vexp %prec UMINUS
| '(' vexp ')'
;
//Lexer
DREG : "[a-z]" ;
VREG : "[A-Z]" ;
CONST : "[0-9]+(\.[0-9]*)" ;
}
Metadata
Metadata
Assignees
Labels
No labels