Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
menhir
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POTTIER Francois
menhir
Commits
b7fac4ab
Commit
b7fac4ab
authored
Aug 29, 2015
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup in calc-inspection. Isolated two more files.
parent
e12cc76d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
99 deletions
+123
-99
demos/calc-inspection/CalcErrorReporting.ml
demos/calc-inspection/CalcErrorReporting.ml
+29
-0
demos/calc-inspection/CalcErrorReporting.mli
demos/calc-inspection/CalcErrorReporting.mli
+7
-0
demos/calc-inspection/CalcPrinters.ml
demos/calc-inspection/CalcPrinters.ml
+67
-0
demos/calc-inspection/CalcPrinters.mli
demos/calc-inspection/CalcPrinters.mli
+9
-0
demos/calc-inspection/calc.ml
demos/calc-inspection/calc.ml
+11
-99
No files found.
demos/calc-inspection/CalcErrorReporting.ml
0 → 100644
View file @
b7fac4ab
open
Parser
open
Parser
.
MenhirInterpreter
(* In order to submit artificial tokens to the parser, we need a function that
converts a terminal symbol to a (dummy) token. Unfortunately, we cannot (in
general) auto-generate this code, because it requires making up semantic
values of arbitrary OCaml types. *)
let
terminal2token
(
type
a
)
(
symbol
:
a
terminal
)
:
token
=
match
symbol
with
|
T_TIMES
->
TIMES
|
T_RPAREN
->
RPAREN
|
T_PLUS
->
PLUS
|
T_MINUS
->
MINUS
|
T_LPAREN
->
LPAREN
|
T_INT
->
INT
0
|
T_EOL
->
EOL
|
T_DIV
->
DIV
|
T_error
->
assert
false
demos/calc-inspection/CalcErrorReporting.mli
0 → 100644
View file @
b7fac4ab
open
Parser
.
MenhirInterpreter
(* This module offers the functionality required by the functor
[ErrorReporting.Printers.Make]. *)
val
terminal2token
:
_
terminal
->
token
demos/calc-inspection/CalcPrinters.ml
0 → 100644
View file @
b7fac4ab
open
Parser
.
MenhirInterpreter
(* In order to print syntax error messages and/or debugging information, we
need a symbol printer. *)
let
print_symbol
symbol
:
string
=
match
symbol
with
|
X
(
T
T_TIMES
)
->
"*"
|
X
(
T
T_RPAREN
)
->
")"
|
X
(
T
T_PLUS
)
->
"+"
|
X
(
T
T_MINUS
)
->
"-"
|
X
(
T
T_LPAREN
)
->
"("
|
X
(
T
T_INT
)
->
"INT"
|
X
(
N
N_expr
)
->
"expr"
|
X
(
N
N_main
)
->
"main"
|
X
(
T
T_EOL
)
->
"EOL"
|
X
(
T
T_DIV
)
->
"/"
|
X
(
T
T_error
)
->
"error"
(* In order to print a view of the stack that includes semantic values,
we need an element printer. (If we don't need this feature, then
[print_symbol] above suffices.) *)
let
print_element
e
:
string
=
match
e
with
|
Element
(
s
,
v
,
_
,
_
)
->
match
incoming_symbol
s
with
|
T
T_TIMES
->
"*"
|
T
T_RPAREN
->
")"
|
T
T_PLUS
->
"+"
|
T
T_MINUS
->
"-"
|
T
T_LPAREN
->
"("
|
T
T_INT
->
string_of_int
v
|
N
N_expr
->
string_of_int
v
|
N
N_main
->
string_of_int
v
|
T
T_EOL
->
""
|
T
T_DIV
->
"/"
|
T
T_error
->
"error"
(* The public functions. *)
let
print
=
prerr_string
let
print_symbol
s
=
print
(
print_symbol
s
)
let
print_element
=
Some
(
fun
s
->
print
(
print_element
s
))
demos/calc-inspection/CalcPrinters.mli
0 → 100644
View file @
b7fac4ab
open
Parser
.
MenhirInterpreter
(* This module offers the functionality required by the functor
[MenhirLib.Printers.Make]. *)
val
print
:
string
->
unit
val
print_symbol
:
xsymbol
->
unit
val
print_element
:
(
element
->
unit
)
option
demos/calc-inspection/calc.ml
View file @
b7fac4ab
open
MenhirLib
.
General
open
Parser
.
MenhirInterpreter
(* --------------------------------------------------------------------------- *)
(* In order to submit artificial tokens to the parser, we need a function that
converts a terminal symbol to a (dummy) token. Unfortunately, we cannot (in
general) auto-generate this code, because it requires making up semantic
values of arbitrary OCaml types. *)
let
terminal2token
(
type
a
)
(
symbol
:
a
terminal
)
:
token
=
let
open
Parser
in
match
symbol
with
|
T_TIMES
->
TIMES
|
T_RPAREN
->
RPAREN
|
T_PLUS
->
PLUS
|
T_MINUS
->
MINUS
|
T_LPAREN
->
LPAREN
|
T_INT
->
INT
0
|
T_EOL
->
EOL
|
T_DIV
->
DIV
|
T_error
->
assert
false
(* In order to print syntax error messages and/or debugging information, we
need a symbol printer. *)
let
print_symbol
symbol
=
match
symbol
with
|
X
(
T
T_TIMES
)
->
"*"
|
X
(
T
T_RPAREN
)
->
")"
|
X
(
T
T_PLUS
)
->
"+"
|
X
(
T
T_MINUS
)
->
"-"
|
X
(
T
T_LPAREN
)
->
"("
|
X
(
T
T_INT
)
->
"INT"
|
X
(
N
N_expr
)
->
"expr"
|
X
(
N
N_main
)
->
"main"
|
X
(
T
T_EOL
)
->
"EOL"
|
X
(
T
T_DIV
)
->
"/"
|
X
(
T
T_error
)
->
"error"
(* In order to print a view of the stack that includes semantic values,
we need an element printer. (If we don't need this feature, then
[print_symbol] above suffices.) *)
let
print_element
e
:
string
=
match
e
with
|
Element
(
s
,
v
,
_
,
_
)
->
match
incoming_symbol
s
with
|
T
T_TIMES
->
"*"
|
T
T_RPAREN
->
")"
|
T
T_PLUS
->
"+"
|
T
T_MINUS
->
"-"
|
T
T_LPAREN
->
"("
|
T
T_INT
->
string_of_int
v
|
N
N_expr
->
string_of_int
v
|
N
N_main
->
string_of_int
v
|
T
T_EOL
->
""
|
T
T_DIV
->
"/"
|
T
T_error
->
"error"
(* --------------------------------------------------------------------------- *)
(* TEMPORARY comment *)
(* Instantiate [MenhirLib.Printers] for our parser. This requires providing a
few printing functions -- see [CalcPrinters]. *)
module
P
=
MenhirLib
.
Printers
.
Make
(
Parser
.
MenhirInterpreter
)
(
struct
let
print
s
=
Printf
.
fprintf
stderr
"%s"
s
let
print_symbol
s
=
print
(
print_symbol
s
)
let
print_element
=
Some
(
fun
s
->
print
(
print_element
s
))
end
)
MenhirLib
.
Printers
.
Make
(
Parser
.
MenhirInterpreter
)
(
CalcPrinters
)
(* Instantiate [MenhirLib.ErrorReporting] for our parser. This requires
providing a few functions -- see [CalcErrorReporting]. *)
module
E
=
MenhirLib
.
ErrorReporting
.
Make
(
Parser
.
MenhirInterpreter
)
(
struct
let
terminal2token
=
terminal2token
end
)
MenhirLib
.
ErrorReporting
.
Make
(
Parser
.
MenhirInterpreter
)
(
CalcErrorReporting
)
let
print_explanation
explanation
=
(* TEMPORARY not satisfactory at all *)
...
...
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