diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll
index a9be762984b9afbc3137bdf82bd458dd31f5e5b9..f2b1b7b97072dd3944f18e6687d01891b304bab6 100644
--- a/preprocessor/DynareFlex.ll
+++ b/preprocessor/DynareFlex.ll
@@ -53,7 +53,7 @@ string eofbuff;
 
 %option case-insensitive noyywrap nounput batch debug never-interactive
 
- /* NB: if new start conditions are defined, add them in the line for [\n]+ and <<EOF>>*/
+ /* NB: if new start conditions are defined, add them in the line for <<EOF>> */
 %x COMMENT
 %x DYNARE_STATEMENT
 %x DYNARE_BLOCK
@@ -65,7 +65,7 @@ string eofbuff;
 
 %{
 // Increments location counter for every token read
-#define YY_USER_ACTION yylloc->columns(yyleng);
+#define YY_USER_ACTION location_increment(yylloc, yytext);
 %}
 %%
  /* Code put at the beginning of yylex() */
@@ -88,7 +88,7 @@ string eofbuff;
 
  /* spaces, tabs and carriage returns are ignored */
 <*>[ \t\r\f]+  { yylloc->step(); }
-<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+       { yylloc->lines(yyleng); yylloc->step(); }
+<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+       { yylloc->step(); }
 
  /* Comments */
 <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>["%"].*
@@ -620,6 +620,16 @@ DynareFlex::DynareFlex(istream* in, ostream* out)
 {
 }
 
+void
+DynareFlex::location_increment(Dynare::parser::location_type *yylloc, const char *yytext)
+{
+  while (*yytext != 0)
+    if (*yytext++ == '\n')
+      yylloc->lines(1);
+    else
+      yylloc->columns(1);
+}
+
 /* This implementation of DynareFlexLexer::yylex() is required to fill the
  * vtable of the class DynareFlexLexer. We define the scanner's main yylex
  * function via YY_DECL to reside in the DynareFlex class instead. */
diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh
index 3acb8460c7c275ee0dab37df26c3b258a7437b69..490d2bbafe23b5f94a7a271f9454954759e23475 100644
--- a/preprocessor/ParsingDriver.hh
+++ b/preprocessor/ParsingDriver.hh
@@ -68,6 +68,9 @@ public:
   //! The filename being parsed
   /*! The bison parser locations (begin and end) contain a pointer to that string */
   string filename;
+
+  //! Increment the location counter given a token
+  void location_increment(Dynare::parser::location_type *yylloc, const char *yytext);
 };
 
 //! Drives the scanning and parsing of the .mod file, and constructs its abstract representation