HyperDbg Debugger
Loading...
Searching...
No Matches
lalr_parsing.lr_zero Namespace Reference

Classes

class  Automaton
 

Functions

 get_automaton (gr)
 
 closure (gr, item_set)
 
 goto (gr, item_set, inp)
 
 kernels (item_set)
 

Function Documentation

◆ closure()

lalr_parsing.lr_zero.closure ( gr,
item_set )
43def closure(gr, item_set):
44 result = set(item_set)
45 set_queue = item_set
46
47 while len(set_queue) > 0:
48 new_elements = []
49
50 for itemProdId, dot in set_queue:
51 pname, pbody = gr.productions[itemProdId]
52 if dot == len(pbody) or pbody[dot] not in gr.nonterms:
53 continue
54
55 nt = pbody[dot]
56 nt_offset = gr.nonterm_offset[nt]
57 for idx in range(len(nt.productions)):
58 new_item_set = (nt_offset + idx, 0)
59 if new_item_set not in result:
60 new_elements += [new_item_set]
61 result.add(new_item_set)
62
63 set_queue = new_elements
64
65 return frozenset(result)
66
67
set(SourceFiles "hyperdbg-cli.cpp" "../include/platform/user/header/Environment.h") include_directories("../include" "../dependencies") add_executable(hyperdbg-cli $
Definition CMakeLists.txt:1

◆ get_automaton()

lalr_parsing.lr_zero.get_automaton ( gr)
8def get_automaton(gr):
9 dfa = Automaton()
10 dfa.states = [closure(gr, [(0, 0)])]
11 next_id = 0
12
13 dfa.id_from_state[dfa.states[-1]] = next_id
14 next_id += 1
15
16 seen = set(dfa.states)
17 set_queue = dfa.states
18 while len(set_queue) > 0:
19 new_elements = []
20 for item_set in set_queue:
21 item_set_id = dfa.id_from_state[item_set]
22
23 for symbol in gr.symbols:
24 next_item_set = goto(gr, item_set, symbol)
25 if len(next_item_set) == 0:
26 continue
27
28 if next_item_set not in seen:
29 new_elements += [next_item_set]
30 seen.add(next_item_set)
31
32 dfa.states += [next_item_set]
33 dfa.id_from_state[dfa.states[-1]] = next_id
34 next_id += 1
35
36 dfa.goto[(item_set_id, symbol)] = dfa.id_from_state[next_item_set]
37
38 set_queue = new_elements
39
40 return dfa
41
42

◆ goto()

lalr_parsing.lr_zero.goto ( gr,
item_set,
inp )
68def goto(gr, item_set, inp):
69 result_set = set()
70
71 for prod_index, dot in item_set:
72 pname, pbody = gr.productions[prod_index]
73 if dot < len(pbody) and pbody[dot] == inp:
74 result_set.add((prod_index, dot + 1))
75
76 result_set = closure(gr, result_set)
77 return result_set
78
79

◆ kernels()

lalr_parsing.lr_zero.kernels ( item_set)
80def kernels(item_set):
81 return frozenset((x, y) for x, y in item_set if y > 0 or x == 0)