aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/pre_parser.mly
diff options
context:
space:
mode:
authorFrançois Pottier <francois.pottier@inria.fr>2015-10-08 09:23:41 +0200
committerFrançois Pottier <francois.pottier@inria.fr>2015-10-23 12:51:24 +0200
commit1c6d12874f0737d07acbda6b56e43053ca159c36 (patch)
tree7d592914309cee12091af28a7db6538270911c47 /cparser/pre_parser.mly
parent4972a6a8851dfe823a022fc3b8c7c01332a89c35 (diff)
downloadcompcert-kvx-1c6d12874f0737d07acbda6b56e43053ca159c36.tar.gz
compcert-kvx-1c6d12874f0737d07acbda6b56e43053ca159c36.zip
Reformulated the definitions of [option] and [list] in a slightly more elegant manner.
Diffstat (limited to 'cparser/pre_parser.mly')
-rw-r--r--cparser/pre_parser.mly24
1 files changed, 13 insertions, 11 deletions
diff --git a/cparser/pre_parser.mly b/cparser/pre_parser.mly
index e2ca8439..6627568d 100644
--- a/cparser/pre_parser.mly
+++ b/cparser/pre_parser.mly
@@ -68,12 +68,6 @@
so this definition of [option] is actually used, even though the
word [option] does not appear in the rest of this file. *)
-option(X):
-| /* nothing */
- { None }
-| x = X
- { Some x }
-
(* [ioption(X)] is equivalent to [option(X)], but is marked [%inline],
so its definition is expanded. In the absence of conflicts, the two
are equivalent. Using [ioption] instead of [option] in well-chosen
@@ -81,12 +75,20 @@ option(X):
of [ioption] in well-chosen places can help reduce the number of
states of the automaton. *)
+(* Defining the non-%inline version in terms of the %inline version is
+ a standard idiom. It obviates the need to duplicate the definition.
+ The same idiom is used elsewhere below. *)
+
%inline ioption(X):
| /* nothing */
{ None }
| x = X
{ Some x }
+option(X):
+ o = ioption(X)
+ { o }
+
(* [optional(X, Y)] is equivalent to [X? Y]. However, by inlining
the two possibilies -- either [X Y] or just [Y] -- we are able
to give more meaningful syntax error messages. [optional(X, Y)]
@@ -99,17 +101,17 @@ optional(X, Y):
separators. Note that, by convention, [X*] is syntactic sugar for
[list(X)]. *)
-list(X):
-| (* empty *) {}
-| list(X) X {}
-
(* [ilist(X)] is equivalent to [list(X)], but is marked [%inline],
- so its definition is expanded. *)
+ so its definition is expanded (only one level deep, of course). *)
%inline ilist(X):
| (* empty *) {}
| list(X) X {}
+list(X):
+ xs = ilist(X)
+ { xs }
+
%inline fst(X):
| x = X
{ fst x }