Skip to content

Commit c3af864

Browse files
committed
Add support to use an existing DFA stored in external memory
The DFA states are now accessed via a static array pointer, which now allows an existing DFA stored in external memory to be used directly by the RegEx engine. For example, a DFA can now be stored in a `DataSection` block and the RegEx engine uses the DFA directly from there. - New function: `FreeDfa()` - New function: `UseDfaFromMemory()` - Added example code which uses a DFA stored in a `DataSection` block
1 parent e5ca180 commit c3af864

File tree

5 files changed

+190
-18
lines changed

5 files changed

+190
-18
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@ Structure DfaStateStruc
7070
EndStructure
7171
```
7272

73+
```purebasic
74+
Structure DfaStatesArrayStruc
75+
states.DfaStateStruc[0]
76+
EndStructure
77+
```
78+
7379
```purebasic
7480
Structure RegExEngineStruc
75-
List nfaStatesPool.NfaStateStruc() ; Holds all NFA states
76-
*initialNfaState ; Pointer to the NFA initial state
77-
Array dfaStatesPool.DfaStateStruc(0) ; Holds all DFA states
81+
List nfaStatesPool.NfaStateStruc() ; Holds all NFA states
82+
*initialNfaState ; Pointer to the NFA initial state
83+
*dfaStatesPool.DfaStatesArrayStruc ; Holds all DFA states
7884
EndStructure
7985
```
8086

@@ -84,11 +90,17 @@ EndStructure
8490
Creates a new RegEx engine and returns the pointer to the `RegExEngineStruc` structure. If an error occurred (RegEx syntax error or memory could not be allocated) null is returned.
8591

8692
- `CreateDfa(*regExEngine, clearNfa = #True)`<br>
87-
Creates a DFA in the RegEx engine from the NFA created by `Create()`. `Match()` then always uses the DFA and is much faster. Because the NFA is no longer used after this, it is cleared by default. The clearing can be turned off by setting `clearNfa` to `#False`.
93+
Creates a DFA in the RegEx engine from the NFA created by `Create()`. `Match()` then always uses the DFA and is much faster. Because the NFA is no longer used after this, it is cleared by default. The clearing can be turned off by setting `clearNfa` to `#False`. On success `#True` is returned, otherwise `#False`.
8894

8995
- `Free(*regExEngine)`<br>
9096
Frees the memory of the RegEx engine created by the function `Create()`.
9197

98+
- `FreeDfa(*regExEngine)`<br>
99+
Frees the memory of the DFA created by the function `CreateDfa()`.
100+
101+
- `UseDfaFromMemory(*dfaMemory)`<br>
102+
Assigns an existing DFA stored in external memory to the RegEx engine. After that the RegEx engine is directly ready to use; no call of `Create()` and `CreateDfa()` is necessary. But the call of `Free()` is still necessary. On success the pointer to `RegExEngineStruc` is returned, otherwise null.
103+
92104
- `Match(*regExEngine, *string)`<br>
93105
Runs the Regex engine against the string. The function requires the pointer to the string, which can be determined with `@variable$` or `@"text"`. The match search will start from the beginning of the string. If you want to start from a different position, you have to move the pointer of the string, e.g. `*string + SizeOf(Character)` to search from the second character in the string. If a match is found, the character length of the match is returned, otherwise zero.
94106

RegExEngine.pbi

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ DeclareModule RegEx
2222
isFinalState.i ; `#True` if the DFA state is a final state, otherwise `#False`
2323
EndStructure
2424

25+
Structure DfaStatesArrayStruc
26+
states.DfaStateStruc[0]
27+
EndStructure
28+
2529
Structure RegExEngineStruc
26-
List nfaStatesPool.NfaStateStruc() ; Holds all NFA states
27-
*initialNfaState ; Pointer to the NFA initial state
28-
Array dfaStatesPool.DfaStateStruc(0) ; Holds all DFA states
30+
List nfaStatesPool.NfaStateStruc() ; Holds all NFA states
31+
*initialNfaState ; Pointer to the NFA initial state
32+
*dfaStatesPool.DfaStatesArrayStruc ; Holds all DFA states
2933
EndStructure
3034

3135
; Creates a new RegEx engine and returns the pointer to the
@@ -37,11 +41,21 @@ DeclareModule RegEx
3741
; `Match()` then always uses the DFA and is much faster.
3842
; Because the NFA is no longer used after this, it is cleared by default.
3943
; The clearing can be turned off by setting `clearNfa` to `#False`.
44+
; On success `#True` is returned, otherwise `#False`.
4045
Declare CreateDfa(*regExEngine, clearNfa = #True)
4146

4247
; Frees the memory of the RegEx engine created by the function `Create()`.
4348
Declare Free(*regExEngine)
4449

50+
; Frees the memory of the DFA created by the function `CreateDfa()`.
51+
Declare FreeDfa(*regExEngine)
52+
53+
; Assigns an existing DFA stored in external memory to the RegEx engine.
54+
; After that the RegEx engine is directly ready to use; no call of `Create()`
55+
; and `CreateDfa()` is necessary. But the call of `Free()` is still necessary.
56+
; On success the pointer to `RegExEngineStruc` is returned, otherwise null.
57+
Declare UseDfaFromMemory(*dfaMemory)
58+
4559
; Runs the RegEx engine against the string. The function requires the pointer
4660
; to the string, which can be determined with `@variable$` or `@"text"`.
4761
; The match search will start from the beginning of the string. If you want
@@ -475,6 +489,12 @@ Module RegEx
475489
Protected.EClosureStruc Dim eClosures(1), NewMap symbols()
476490
Protected.NfaStateStruc *state
477491
Protected sizeOfArray, dfaState, result
492+
Protected *newMemory
493+
494+
*regExEngine\dfaStatesPool = AllocateMemory(SizeOf(DfaStateStruc) << 1)
495+
If *regExEngine\dfaStatesPool = 0
496+
ProcedureReturn #False
497+
EndIf
478498

479499
dfaState = 1
480500

@@ -491,7 +511,7 @@ Module RegEx
491511
*state = eClosures(dfaState)\nfaStates()
492512
Select *state\symbol
493513
Case #Symbol_Final
494-
*regExEngine\dfaStatesPool(dfaState)\isFinalState = #True
514+
*regExEngine\dfaStatesPool\states[dfaState]\isFinalState = #True
495515
Default
496516
AddState(*state\nextState1, symbols(Chr(*state\symbol))\nfaStates())
497517
EndSelect
@@ -500,13 +520,22 @@ Module RegEx
500520
ForEach symbols()
501521
result = FindStatesSet(eClosures(), symbols()\nfaStates())
502522
If result
503-
*regExEngine\dfaStatesPool(dfaState)\symbols[Asc(MapKey(symbols()))] = result
523+
*regExEngine\dfaStatesPool\states[dfaState]\symbols[Asc(MapKey(symbols()))] = result
504524
Else
505525
sizeOfArray = ArraySize(eClosures())
506526
ReDim eClosures(sizeOfArray + 1)
507-
ReDim *regExEngine\dfaStatesPool(sizeOfArray + 1)
527+
*newMemory = ReAllocateMemory(*regExEngine\dfaStatesPool,
528+
MemorySize(*regExEngine\dfaStatesPool) +
529+
SizeOf(DfaStateStruc))
530+
If *newMemory
531+
*regExEngine\dfaStatesPool = *newMemory
532+
Else
533+
FreeMemory(*regExEngine\dfaStatesPool)
534+
*regExEngine\dfaStatesPool = 0
535+
ProcedureReturn #False
536+
EndIf
508537
CopyList(symbols()\nfaStates(), eClosures(sizeOfArray + 1)\nfaStates())
509-
*regExEngine\dfaStatesPool(dfaState)\symbols[Asc(MapKey(symbols()))] = sizeOfArray + 1
538+
*regExEngine\dfaStatesPool\states[dfaState]\symbols[Asc(MapKey(symbols()))] = sizeOfArray + 1
510539
EndIf
511540
Next
512541

@@ -516,12 +545,29 @@ Module RegEx
516545
*regExEngine\initialNfaState = 0
517546
ClearList(*regExEngine\nfaStatesPool())
518547
EndIf
548+
549+
ProcedureReturn #True
519550
EndProcedure
520551

521552
Procedure Free(*regExEngine.RegExEngineStruc)
522553
FreeStructure(*regExEngine)
523554
EndProcedure
524555

556+
Procedure FreeDfa(*regExEngine.RegExEngineStruc)
557+
FreeMemory(*regExEngine\dfaStatesPool)
558+
EndProcedure
559+
560+
Procedure UseDfaFromMemory(*dfaMemory)
561+
Protected.RegExEngineStruc *regExEngine
562+
563+
*regExEngine = AllocateStructure(RegExEngineStruc)
564+
If *regExEngine
565+
*regExEngine\dfaStatesPool = *dfaMemory
566+
EndIf
567+
568+
ProcedureReturn *regExEngine
569+
EndProcedure
570+
525571
Procedure NfaMatch(*regExEngine.RegExEngineStruc, *string.Ascii)
526572
Protected.NfaStateStruc *state
527573
Protected matchLength, lastFinalStateMatchLength
@@ -561,15 +607,15 @@ Module RegEx
561607
; dfaState '0' is the dead state, so it will be skipped.
562608

563609
Repeat
564-
dfaState = *regExEngine\dfaStatesPool(dfaState)\symbols[*string\a]
610+
dfaState = *regExEngine\dfaStatesPool\states[dfaState]\symbols[*string\a]
565611
If dfaState = #State_DfaDeadState
566612
Break
567613
EndIf
568614

569615
matchLength + 1
570616
*string + SizeOf(Ascii)
571617

572-
If *regExEngine\dfaStatesPool(dfaState)\isFinalState
618+
If *regExEngine\dfaStatesPool\states[dfaState]\isFinalState
573619
lastFinalStateMatchLength = matchLength
574620
EndIf
575621
ForEver
@@ -578,7 +624,7 @@ Module RegEx
578624
EndProcedure
579625

580626
Procedure Match(*regExEngine.RegExEngineStruc, *string.Character)
581-
If ArraySize(*regExEngine\dfaStatesPool())
627+
If *regExEngine\dfaStatesPool <> 0
582628
ProcedureReturn DfaMatch(*regExEngine, *string)
583629
Else
584630
ProcedureReturn NfaMatch(*regExEngine, *string)

examples/DFA_in_DataSection.pb

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+

2+
IncludePath ".."
3+
IncludeFile "RegExEngine.pbi"
4+
5+
Define *regEx = RegEx::UseDfaFromMemory(?dfa)
6+
7+
If *regEx
8+
If RegEx::Match(*regEx, @"Test")
9+
Debug "Match!"
10+
Else
11+
Debug "No match!"
12+
EndIf
13+
RegEx::Free(*regEx)
14+
Else
15+
Debug "Error!"
16+
EndIf
17+
18+
DataSection
19+
dfa:
20+
21+
; Dead state
22+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
23+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
24+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
25+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
26+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
27+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
28+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
109+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
110+
Data.i 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
111+
Data.i 0,0,0,0,0,0,0,0,0,0,0,#True
112+
EndDataSection

examples/Debug_DFA_table.pb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ RegEx::CreateDfa(*regEx)
1616

1717
Debug "| State | Symbol | Next state |"
1818
Debug "| =================== | ====== | =================== |"
19-
sizeOfArray = ArraySize(*regEx\dfaStatesPool())
19+
sizeOfArray = MemorySize(*regEx\dfaStatesPool) / SizeOf(RegEx::DfaStateStruc) - 1
2020
For i = 1 To sizeOfArray
21-
If *regEx\dfaStatesPool(i)\isFinalState
21+
If *regEx\dfaStatesPool\states[i]\isFinalState
2222
Debug "| " + LSet(Str(i) + " (final)", 19) + " | " + Space(6) + " | " +
2323
Space(19) + " |"
2424
Else
2525
Debug "| " + LSet(Str(i), 19) + " | " + Space(6) + " | " + Space(19) + " |"
2626
EndIf
2727

2828
For i2 = 0 To 255
29-
If *regEx\dfaStatesPool(i)\symbols[i2] <> RegEx::#State_DfaDeadState
29+
If *regEx\dfaStatesPool\states[i]\symbols[i2] <> RegEx::#State_DfaDeadState
3030
hex$ = RSet(Hex(i2), 2, "0")
3131
Debug "| " + Space(19) +
3232
" | " + LSet(hex$, 6) +
33-
" | " + LSet(Str(*regEx\dfaStatesPool(i)\symbols[i2]), 19) + " |"
33+
" | " + LSet(Str(*regEx\dfaStatesPool\states[i]\symbols[i2]), 19) + " |"
3434
EndIf
3535
Next
3636
Debug "| ------------------- | ------ | ------------------- |"
3737
Next
3838

39+
RegEx::FreeDfa(*regEx)
3940
RegEx::Free(*regEx)

examples/Find_all_matches.pb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ While *string\c
4141
*string + SizeOf(Character)
4242
Wend
4343

44+
RegEx::FreeDfa(*regEx)
4445
RegEx::Free(*regEx)

0 commit comments

Comments
 (0)