-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_day_3_2024.yrl
More file actions
47 lines (37 loc) · 1.46 KB
/
parser_day_3_2024.yrl
File metadata and controls
47 lines (37 loc) · 1.46 KB
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
Nonterminals instruction memory else.
Terminals mul int open_paren close_paren comma skip do dont.
Rootsymbol memory.
instruction -> mul open_paren int comma int close_paren : {ok, operands, {extract_integer('$3'), extract_integer('$5')}}.
instruction -> mul open_paren int comma int : incomplete.
instruction -> mul open_paren int comma : incomplete.
instruction -> mul open_paren int : incomplete.
instruction -> mul open_paren : incomplete.
instruction -> do : {ok, enable}.
instruction -> dont : {ok, disable}.
instruction -> else : incomplete.
memory -> instruction : remove_incomplete('$1').
memory -> instruction memory : remove_incomplete_rec('$1', '$2').
else -> mul.
else -> int.
else -> open_paren.
else -> close_paren.
else -> comma.
else -> skip.
Erlang code.
extract_integer({_Token, _Line, Value}) -> Value.
remove_incomplete({ok, operands, {A, B}}) ->
[{operands, {A, B}}];
remove_incomplete({ok, enable}) ->
[enable];
remove_incomplete({ok, disable}) ->
[disable];
remove_incomplete(incomplete) ->
[].
remove_incomplete_rec({ok, operands, {A, B}}, Rest) ->
[{operands, {A, B}} | Rest];
remove_incomplete_rec({ok, enable}, Rest) ->
[enable | Rest];
remove_incomplete_rec({ok, disable}, Rest) ->
[disable | Rest];
remove_incomplete_rec(incomplete, X) ->
X.