Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong line count when it's multi character like '\r\n' #50

Open
mingodad opened this issue Jul 19, 2023 · 0 comments
Open

Wrong line count when it's multi character like '\r\n' #50

mingodad opened this issue Jul 19, 2023 · 0 comments

Comments

@mingodad
Copy link
Contributor

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]*)" ;

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant