Commit d3d469e6 authored by POTTIER Francois's avatar POTTIER Francois

Replace [env.lexer] and [env.lexbuf] with a single field, [env.read].

The ratio table/code seems to be back from 2.1 to 2.0.
parent f9ce16b6
......@@ -86,11 +86,8 @@ module Make (T : TABLE) = struct
previous token. *)
and discard env =
let lexbuf = env.lexbuf in
let token = env.lexer lexbuf in
let startp = lexbuf.Lexing.lex_start_p
and endp = lexbuf.Lexing.lex_curr_p in
let triple = (token, startp, endp) in
let triple = env.read() in
let (token, startp, endp) = triple in
Log.lookahead_token (T.token2terminal token) startp endp;
let env = { env with triple } in
check_for_default_reduction env
......@@ -310,7 +307,14 @@ module Make (T : TABLE) = struct
(lexbuf : Lexing.lexbuf)
: semantic_value =
(* Pre-apply the lexer to the lexbuf. *)
(* Wrap the lexer and lexbuf as a revised lexer. *)
let read () =
let token = lexer lexbuf in
let startp = lexbuf.Lexing.lex_start_p
and endp = lexbuf.Lexing.lex_curr_p in
(token, startp, endp)
in
(* Build an empty stack. This is a dummy cell, which is its own
successor. Its fields other than [next] contain dummy values. *)
......@@ -325,20 +329,17 @@ module Make (T : TABLE) = struct
(* Perform an initial call to the lexer. *)
let token = lexer lexbuf in
let startp = lexbuf.Lexing.lex_start_p
and endp = lexbuf.Lexing.lex_curr_p in
let triple = read() in
(* Log our first lookahead token. *)
let (token, startp, endp) = triple in
Log.lookahead_token (T.token2terminal token) startp endp;
(* Build an initial environment. *)
let triple = (token, startp, endp) in
let env = {
lexer;
lexbuf;
read;
triple;
stack = empty;
current = s;
......
......@@ -51,12 +51,7 @@ type ('state, 'semantic_value, 'token) env = {
(* The lexer. *)
lexer: Lexing.lexbuf -> 'token;
(* The lexing buffer. It is used as an argument to the lexer, and also
accessed directly when extracting positions. *)
lexbuf: Lexing.lexbuf;
read: unit -> 'token * Lexing.position * Lexing.position;
(* The last token that was obtained from the lexer, together with its start
and end positions. In principle, this should be a legit token, but the
......
......@@ -52,11 +52,8 @@ let fstack =
let fcurrent =
field "current"
let flexbuf =
field "lexbuf"
let flex_start_p =
"Lexing.lex_start_p"
let ftriple =
field "triple"
let interpreter =
"MenhirInterpreter"
......@@ -157,7 +154,11 @@ let reducebody prod =
if length > 0 then
EVar (Printf.sprintf "_startpos_%s_" ids.(0))
else
ERecordAccess(ERecordAccess (EVar env, flexbuf), flex_start_p)
(* Use the start position of the current lookahead token,
which is stored in the second component of [env.triple]. *)
ELet ([PTuple [PWildcard; PVar "startpos"; PWildcard],
ERecordAccess (EVar env, ftriple)],
EVar "startpos")
) ::
( PVar endp,
if length > 0 then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment