forked from yurug/menhir-error-recovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.ml
77 lines (74 loc) · 2.15 KB
/
symbol.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
open Parser
open Parser.MenhirInterpreter
let string_of_token = function
| VAR -> "VAR"
| THEN -> "THEN"
| STAR -> "STAR"
| SEMICOLON -> "SEMICOLON"
| RPAREN -> "RPAREN"
| RETURN -> "RETURN"
| RBRACE -> "RBRACE"
| PLUS -> "PLUS"
| LPAREN -> "LPAREN"
| LINT d -> Printf.sprintf "LINT(%d)" d
| LBRACE -> "LBRACE"
| IF -> "IF"
| ID s -> Printf.sprintf "ID(%s)" s
| EQ -> "EQ"
| EOF -> "EOF"
| ELSE -> "ELSE"
| DEF -> "DEF"
| COMMA -> "COMMA"
let string_of_symbol = function
| X (T T_error) -> "error"
| X (T T_VAR) -> "a variable"
| X (T T_THEN) -> "then"
| X (T T_STAR) -> "*"
| X (T T_SEMICOLON) -> ";"
| X (T T_RPAREN) -> ")"
| X (T T_RETURN) -> "return"
| X (T T_RBRACE) -> "}"
| X (T T_PLUS) -> "+"
| X (T T_LPAREN) -> "("
| X (T T_LINT) -> "an integer"
| X (T T_LBRACE) -> "{"
| X (T T_IF) -> "if"
| X (T T_ID) -> "an identifier"
| X (T T_EQ) -> "="
| X (T T_EOF) -> "end-of-file"
| X (T T_ELSE) -> "else"
| X (T T_DEF) -> "def"
| X (T T_COMMA) -> ","
| X (N N_loption_separated_nonempty_list_COMMA_identifier__) ->
"a list of identifiers separated by commas"
| X (N N_separated_nonempty_list_COMMA_identifier_) ->
"a list of identifiers separated by commas"
| X (N N_loption_separated_nonempty_list_COMMA_expression__) ->
"a list of expressions separated by commas"
| X (N N_separated_nonempty_list_COMMA_expression_) ->
"a list of expressions separated by commas"
| X (N N_program) ->
"a program"
| X (N N_list_definition_) ->
"a list of definitions"
| X (N N_list_command_) ->
"a list of commands"
| X (N N_identifier) ->
"an identifier"
| X (N N_function_identifier) ->
"a function identifier"
| X (N N_expression) ->
"an expression"
| X (N N_definition) ->
"a definition"
| X (N N_command) ->
"a command"
| X (N N_block) ->
"a block of commands"
let string_of_item (p, i) =
string_of_symbol (lhs p) ^ " -> "
^ String.concat " " (
List.mapi (fun j s ->
(if j = i then "." else "") ^ string_of_symbol s)
(rhs p))
^ (if i = List.length (rhs p) then "." else "")