Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
menhir
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
11
Issues
11
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POTTIER Francois
menhir
Commits
428429f0
Commit
428429f0
authored
Nov 04, 2015
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the concrete syntax of the new keyword to [$endpos($0)].
Now supported by the table back-end.
parent
2e8ede8b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
19 deletions
+31
-19
src/action.mli
src/action.mli
+1
-1
src/codePieces.ml
src/codePieces.ml
+5
-0
src/codePieces.mli
src/codePieces.mli
+1
-0
src/invariant.ml
src/invariant.ml
+3
-3
src/keyword.ml
src/keyword.ml
+1
-1
src/keyword.mli
src/keyword.mli
+1
-1
src/lr1.ml
src/lr1.ml
+1
-1
src/nonTerminalDefinitionInlining.ml
src/nonTerminalDefinitionInlining.ml
+10
-10
src/tableBackend.ml
src/tableBackend.ml
+8
-2
No files found.
src/action.mli
View file @
428429f0
...
...
@@ -58,5 +58,5 @@ val has_leftend: t -> bool
(** Check whether the keyword $start or $end is used in the action. *)
val
has_left
:
t
->
bool
(** Check whether the keyword $
beforeend
is used in the action. *)
(** Check whether the keyword $
endpos($0)
is used in the action. *)
val
has_beforeend
:
t
->
bool
src/codePieces.ml
View file @
428429f0
...
...
@@ -48,6 +48,11 @@ let token =
that binding these variables before executing a semantic action is
meaningful. *)
(* These names should agree with the printing function [Keyword.posvar]. *)
let
beforeendp
=
"_endpos__0_"
let
startp
=
"_startpos"
...
...
src/codePieces.mli
View file @
428429f0
...
...
@@ -37,6 +37,7 @@ val token: string
(* Variables used to hold start and end positions. *)
val
beforeendp
:
string
val
startp
:
string
val
endp
:
string
...
...
src/invariant.ml
View file @
428429f0
...
...
@@ -620,7 +620,7 @@ let rewind node : instruction =
[sym] must keep track of its end position. (Furthermore, if some initial
state can reduce an epsilon production, then the sentinel cell at the bottom
of the stack must contain a position. This does not concern us here.)
Similarly, if some state whose incoming symbol is [sym] uses [$
beforeendpos
],
Similarly, if some state whose incoming symbol is [sym] uses [$
endpos($0)
],
then [sym] must keep track of its end position. *)
open
Keyword
...
...
@@ -667,10 +667,10 @@ let () =
|
SyntaxError
->
()
|
Position
(
Before
,
_
,
_
)
->
(* Doing nothing here is OK because the presence of [$
beforepos
]
(* Doing nothing here is OK because the presence of [$
endpos($0)
]
in a semantic action is taken account below when we look at
every state and check whether it can reduce a production whose
semantic action contains [$
beforepos
]. *)
semantic action contains [$
endpos($0)
]. *)
()
|
Position
(
Left
,
where
,
_
)
->
require_aux
where
prod
...
...
src/keyword.ml
View file @
428429f0
...
...
@@ -57,7 +57,7 @@ let where = function
let
subject
=
function
|
Before
->
"
before
"
"
__0_
"
|
Left
->
""
|
RightNamed
id
->
...
...
src/keyword.mli
View file @
428429f0
...
...
@@ -25,7 +25,7 @@ type where =
and desugared as a [subject] during keywords rewriting into actual
OCaml identifiers. (See {!Lexer.transform_keywords}.)
We add a new subject, [Before], which corresponds to [$
beforeendpos
]
We add a new subject, [Before], which corresponds to [$
endpos($0)
]
in concrete syntax. We adopt the (slightly awkward) convention that
when the subject is [Before], the [where] component must be [WhereEnd]. *)
type
parsed_subject
=
...
...
src/lr1.ml
View file @
428429f0
...
...
@@ -844,7 +844,7 @@ let invert reductions : TerminalSet.t ProductionMap.t =
(* This is the case if [s] can reduce an epsilon production whose semantic
action uses [$startpos] or [$endpos]. This is also the case if [s] can
reduce a production whose semantic action uses [$
beforeendpos
]. *)
reduce a production whose semantic action uses [$
endpos($0)
]. *)
let
has_beforeend
node
=
TerminalMap
.
fold
(
fun
_
prods
accu
->
...
...
src/nonTerminalDefinitionInlining.ml
View file @
428429f0
...
...
@@ -26,7 +26,7 @@ let index2id producers i =
respectively. *)
(* It does not modify [$startpos] or [$endpos], of course, nor [$startpos(y)]
and [$endpos(y)] for some other [y]. It does not modify [$
beforeendpos
]. *)
and [$endpos(y)] for some other [y]. It does not modify [$
endpos($0)
]. *)
let
rename_sw_outer
(
x
,
startp
,
endp
)
(
subject
,
where
)
:
(
subject
*
where
)
option
=
match
subject
with
...
...
@@ -42,16 +42,16 @@ let rename_sw_outer (x, startp, endp) (subject, where) : (subject * where) optio
None
(* [rename_sw_inner] transforms the keywords in the inner production (the callee)
during inlining. It looks for [$
beforepos], [$startpos], and [$endpos,]
and
replaces them with [beforep], [startp], and [endp], respectively. *)
during inlining. It looks for [$
endpos($0)], [$startpos], and [$endpos],
and
replaces them with [before
end
p], [startp], and [endp], respectively. *)
(* It does not modify any [$startpos(x)], of course. *)
let
rename_sw_inner
(
beforep
,
startp
,
endp
)
(
subject
,
where
)
:
(
subject
*
where
)
option
=
let
rename_sw_inner
(
before
end
p
,
startp
,
endp
)
(
subject
,
where
)
:
(
subject
*
where
)
option
=
match
subject
,
where
with
|
Before
,
_
->
assert
(
where
=
WhereEnd
);
Some
beforep
Some
before
end
p
|
Left
,
WhereStart
->
Some
startp
|
Left
,
WhereEnd
->
...
...
@@ -191,7 +191,7 @@ let inline grammar =
else
(* If the inner production is epsilon and the prefix is empty, then
we need to look up the end position stored in the top stack cell.
This is the reason why we need the keyword [$
beforeendpos
]. It is
This is the reason why we need the keyword [$
endpos($0)
]. It is
required in this case to preserve the semantics of $startpos and
$endpos. *)
Before
,
WhereEnd
...
...
@@ -215,13 +215,13 @@ let inline grammar =
in
(* We must also transform [$
beforeendpos
] if it used by the inner
(* We must also transform [$
endpos($0)
] if it used by the inner
production. It refers to the end position of the stack cell
that comes before the inner production. So, if the prefix is
non-empty, then it translates to the end position of the last
element of the prefix. Otherwise, it translates to [$
beforeendpos
]. *)
element of the prefix. Otherwise, it translates to [$
endpos($0)
]. *)
let
beforep
=
let
before
end
p
=
if
prefix
>
0
then
RightNamed
(
index2id
(
prefix
-
1
))
,
WhereEnd
else
...
...
@@ -232,7 +232,7 @@ let inline grammar =
let
outer_action
=
Action
.
rename
(
rename_sw_outer
(
c
,
startp
,
endp
))
[]
b
.
action
and
action'
=
Action
.
rename
(
rename_sw_inner
(
beforep
,
startp
,
endp
))
phi
pb
.
action
Action
.
rename
(
rename_sw_inner
(
before
end
p
,
startp
,
endp
))
phi
pb
.
action
in
{
b
with
...
...
src/tableBackend.ml
View file @
428429f0
...
...
@@ -205,10 +205,16 @@ let reducebody prod =
)
(
0
,
PVar
stack
,
[]
)
(
Invariant
.
prodstack
prod
)
in
(* Determine start and end positions for the left-hand side of the
production. *)
(* Determine beforeend/start/end positions for the left-hand side of the
production, and bind them to the conventional variables [beforeendp],
[startp], and [endp]. These variables may be unused by the semantic
action, in which case these bindings are dead code and can be ignored
by the OCaml compiler. *)
let
posbindings
=
(
PVar
beforeendp
,
endpos_of_top_stack_cell
)
::
(
PVar
startp
,
if
length
>
0
then
EVar
(
Printf
.
sprintf
"_startpos_%s_"
ids
.
(
0
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment