SlideShare a Scribd company logo
1 of 39
Download to read offline
Efficient Regular Expressions that produce Parse Trees
Aaron Karper Niko Schwarz
University of Bern

January 7, 2014

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

1 / 38
Regular expressions so far

Regular expressions

https? : // (([a − z] + .) + ([a − z]+)) ((/[a − z0 − 9]+)/?)
domain

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

path segments

January 7, 2014

2 / 38
Regular expressions so far

Regular expressions

https? : // (([a − z] + .) + ([a − z]+)) ((/[a − z0 − 9]+)/?)
domain

path segments

http : // www . reddit . com / r / computerscience / comments / 1sg 69d /
domain domain domain

Aaron Karper, Niko Schwarz (UniBe)

path

path

Regex Parse Trees

path

path

January 7, 2014

2 / 38
Regular expressions so far

Regular expressions are greedy by default:
(a+)(a?) on "aaa" → "aaa" in group 0 and "" in group 1.

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

3 / 38
Regular expressions so far

Regular expressions so far

Posix gives only one match.
Regular languages are recognized, but parsing with combinatorical parsers
takes O(n3 ).
Backtracking implementations (Java, python, perl, . . . ) are exponentially
slow in the worst case.

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

4 / 38
Benchmarks

Parsing with https?://(([a-z]+.)+([a-z]+))((/[a-z0-9]+)/?)
0

3
2
4
http:// www. reddit. com /r /computerscience /comments /1sg69d
1

Figure : Posix
0

1
3
4 4
4
4
2
2
2
http:// www. reddit. com /r /computerscience /comments /1sg69d

Figure : Our approach

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

5 / 38
Benchmarks

Benchmarks

Matching ((a+b)+c)+ against
(a200 bc)2000 .
Tool

Time

JParsec
java.util.regex
Ours

Extract all class names from our project
with complex regular expression1 .

4,498
1,992
5,332

Tool

Time

java.util.regex
Ours

11,319
8,047

1 (.*?([a-z]+.)*([A-Z][a-zA-Z]*))*.*?
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

6 / 38
Benchmarks

Optimizations of the algorithm

Benchmarks – Optimizations of the algorithm

Typically most time is spent in long repetitions, we optimize for that case by:
Lazily compile deterministic FA.
Avoiding to recreate state if seen similar state.
Use compressed representation if in static repetition.

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

7 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+

Parse
(a?(a)b)+
over
”aabab”
01234

1

2

1
2

a a b a b
0 1 2 3 4
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

8 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

[[], [], [], []]

q5

q3

q4

q7

q8

-

q6

q9

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

9 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

[[], [], [], []]

[[0], [], [], []]

q5

q6

q4

q7

q8

-

q9

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

10 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

[[], [], [], []]

[[0], [], [], []]

[[0], [], [], []]

q5

q6

-

q4

q7

q8

q9

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

11 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

q4

[[], [], [], []]

[[0], [], [], []]

[[0], [], [], []]

[[0], [], [0], []]

q5

q6

q7

q8

-

q9

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

12 / 38
Benchmarks

NFA interpretation

Threads

State:

q

Copy of thread is modified.
Copy of array of histories makes
reading a character O(m2 )

Histories:
h1 h2 h3 h4 h5 h6

Aaron Karper, Niko Schwarz (UniBe)

Need faster persistent data
structure to get O(m log m).

Regex Parse Trees

January 7, 2014

13 / 38
Benchmarks

NFA interpretation

Optimized thread forking
Set entry 2 to 20:
1

2

9

3

4

6

5

Aaron Karper, Niko Schwarz (UniBe)

7

10

8

Regex Parse Trees

11

13

12

January 7, 2014

14 / 38
Benchmarks

NFA interpretation

Optimized thread forking
Set entry 2 to 20:
1

2

20

3

4

1

9

6

5

Aaron Karper, Niko Schwarz (UniBe)

7

10

8

Regex Parse Trees

11

13

12

January 7, 2014

15 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

q4

[[], [], [], []]

[[0], [], [], []]

[[0], [], [], []]

[[0], [], [0], []]

q5

q6

q7

q8

-

q9

For each character read, threads start hungry and must eat immediately.
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

16 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

[[], [], [], []]

[[0], [], [], []]

[[0], [], [], []]

q5

q6

-

q4

q7

q8

[[0], [], [0], []]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

17 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

[[], [], [], []]

[[0], [], [], []]

[[0], [], [], []]

q5

q6

[[0], [], [0], []]

-

q4

[[0], [], [0], [0]]

q7

q8

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

18 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

[[], [], [], []]

[[0], [], [], []]

q7

q5

q8

-

q6

[[0], [], [0], []]

q4

[[0], [], [0], [0]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

19 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q5

q8

q6

[[0], [], [0], []]

[[0], [], [1], []]

q7

-

q4

[[0], [], [], []]

[[0], [], [0], [0]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

20 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q4

-

q5

q6

[[0], [], [1], []]

q7

q8

[[0], [], [0], [0]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

21 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q4

-

q5

q6

[[0], [], [1], []]

q7

q8

[[0], [], [0], [0]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

22 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q4

q7

q8

-

q5

q6

[[0], [], [1], []]

[[0], [], [1], [1]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

23 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q4

q7

q8

-

q5

q6
[[0], [], [1], [1]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

24 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

q4

[[0], [2], [1], [1]]

[[0,2], [2], [1], [1]]

[[0,2], [2], [1], [1]]

[[0,2], [2], [1,3], [1]]

q5

q6

q7

q8

[[0], [], [1], [1]]

[[0], [2], [1], [1]]

-

q9
[[0], [2], [1], [1]]

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

25 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

q3

q4

[[0], [2], [1], [1]]

[[0,2], [2], [1], [1]]

[[0,2], [2], [1], [1]]

[[0,2], [2], [1,3], [1]]

q5

q6

q7

q8

[[0], [], [1], [1]]

[[0], [2], [1], [1]]

-

q9
[[0], [2], [1], [1]]

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

26 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q5

q8

q6

[[0,2], [2], [1,3], [1]]

[[0,2], [2], [1,4], [1]]

q7

-

q4

[[0,2], [2], [1], [1]]

[[0,2], [2], [1,3], [1,3]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

27 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q2

q1

q3

q5

q8

q6

[[0,2], [2], [1,3], [1]]

[[0,2], [2], [1,4], [1]]

q7

-

q4

[[0,2], [2], [1], [1]]

[[0,2], [2], [1,3], [1,3]]

q9

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

28 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q1

q2

[[0,2], [2,4], [1,3], [1,3]]

[[0,2,5], [2,4], [1,3], [1,3]]

q3

q5

q6

-

q4

[[0,2,5], [2,4], [1,3], [1,3]]

[[0,2,5], [2,4,5], [1,3], [1,3]]

q7

q8

[[0,2], [2], [1,3], [1,3]]

[[0,2], [2,4], [1,3], [1,3]]

q9
[[0,2], [2,4], [1,3], [1,3]]

For each character read, threads start hungry and must eat immediately.
Only a hungry thread can eat
Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

29 / 38
Benchmarks

NFA interpretation

Example: (a?(a)b)+
Reading "aabab"
01234

q9
[[0,2], [2,4], [1,3], [1,3]]

1

2

1
2

a a b a b
0 1 2 3 4

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

30 / 38
Download

https://github.com/nes1983/tree-regex

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

31 / 38
NFA construction
S1

S

-

Optional
S?

S2
Alternation
S1|S2

S

S

-

Capture group
(S)

Star operation
S*?

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

32 / 38
Backtracking’s nightmare

(a + a+) + b
against
”an b”
will backtrack Θ(2n ) times.

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

33 / 38
Backtracking’s nightmare

Extract the first cell in a CSV that starts with "P"1 :
∧(.∗?, ) + (P.∗?),
failing against
”1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13”
is exponential.

1 From

http://www.regular-expressions.info/catastrophic.html

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

34 / 38
Thread execution order matters

.*(a?)
start

q1

τ1 ↑

q3

a

q4

τ1 ↓

q5

any

q2

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

35 / 38
Priority matters

(a)|(a)
q2

a

q4
τ1 ↓

τ1 ↑

start

q1

q6
τ2 ↑

τ2 ↓
q3

Aaron Karper, Niko Schwarz (UniBe)

a

q5

Regex Parse Trees

January 7, 2014

36 / 38
Optimization Pipeline

1

Convert to nondeterministic FA

2

Interpret nondeterministic FA, building deterministic FA lazily.

3

Find similar/mappable states to avoid creating infinite DFA.

4

Run on DFA if possible

5

Compactify DFA if creation of new states wasn’t necessary for a while.

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

37 / 38
NFA interpretation

Aaron Karper, Niko Schwarz (UniBe)

Regex Parse Trees

January 7, 2014

38 / 38

More Related Content

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Regular expression that produce parse trees

  • 1. Efficient Regular Expressions that produce Parse Trees Aaron Karper Niko Schwarz University of Bern January 7, 2014 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 1 / 38
  • 2. Regular expressions so far Regular expressions https? : // (([a − z] + .) + ([a − z]+)) ((/[a − z0 − 9]+)/?) domain Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees path segments January 7, 2014 2 / 38
  • 3. Regular expressions so far Regular expressions https? : // (([a − z] + .) + ([a − z]+)) ((/[a − z0 − 9]+)/?) domain path segments http : // www . reddit . com / r / computerscience / comments / 1sg 69d / domain domain domain Aaron Karper, Niko Schwarz (UniBe) path path Regex Parse Trees path path January 7, 2014 2 / 38
  • 4. Regular expressions so far Regular expressions are greedy by default: (a+)(a?) on "aaa" → "aaa" in group 0 and "" in group 1. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 3 / 38
  • 5. Regular expressions so far Regular expressions so far Posix gives only one match. Regular languages are recognized, but parsing with combinatorical parsers takes O(n3 ). Backtracking implementations (Java, python, perl, . . . ) are exponentially slow in the worst case. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 4 / 38
  • 6. Benchmarks Parsing with https?://(([a-z]+.)+([a-z]+))((/[a-z0-9]+)/?) 0 3 2 4 http:// www. reddit. com /r /computerscience /comments /1sg69d 1 Figure : Posix 0 1 3 4 4 4 4 2 2 2 http:// www. reddit. com /r /computerscience /comments /1sg69d Figure : Our approach Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 5 / 38
  • 7. Benchmarks Benchmarks Matching ((a+b)+c)+ against (a200 bc)2000 . Tool Time JParsec java.util.regex Ours Extract all class names from our project with complex regular expression1 . 4,498 1,992 5,332 Tool Time java.util.regex Ours 11,319 8,047 1 (.*?([a-z]+.)*([A-Z][a-zA-Z]*))*.*? Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 6 / 38
  • 8. Benchmarks Optimizations of the algorithm Benchmarks – Optimizations of the algorithm Typically most time is spent in long repetitions, we optimize for that case by: Lazily compile deterministic FA. Avoiding to recreate state if seen similar state. Use compressed representation if in static repetition. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 7 / 38
  • 9. Benchmarks NFA interpretation Example: (a?(a)b)+ Parse (a?(a)b)+ over ”aabab” 01234 1 2 1 2 a a b a b 0 1 2 3 4 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 8 / 38
  • 10. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 [[], [], [], []] q5 q3 q4 q7 q8 - q6 q9 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 9 / 38
  • 11. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 [[], [], [], []] [[0], [], [], []] q5 q6 q4 q7 q8 - q9 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 10 / 38
  • 12. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 [[], [], [], []] [[0], [], [], []] [[0], [], [], []] q5 q6 - q4 q7 q8 q9 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 11 / 38
  • 13. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 q4 [[], [], [], []] [[0], [], [], []] [[0], [], [], []] [[0], [], [0], []] q5 q6 q7 q8 - q9 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 12 / 38
  • 14. Benchmarks NFA interpretation Threads State: q Copy of thread is modified. Copy of array of histories makes reading a character O(m2 ) Histories: h1 h2 h3 h4 h5 h6 Aaron Karper, Niko Schwarz (UniBe) Need faster persistent data structure to get O(m log m). Regex Parse Trees January 7, 2014 13 / 38
  • 15. Benchmarks NFA interpretation Optimized thread forking Set entry 2 to 20: 1 2 9 3 4 6 5 Aaron Karper, Niko Schwarz (UniBe) 7 10 8 Regex Parse Trees 11 13 12 January 7, 2014 14 / 38
  • 16. Benchmarks NFA interpretation Optimized thread forking Set entry 2 to 20: 1 2 20 3 4 1 9 6 5 Aaron Karper, Niko Schwarz (UniBe) 7 10 8 Regex Parse Trees 11 13 12 January 7, 2014 15 / 38
  • 17. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 q4 [[], [], [], []] [[0], [], [], []] [[0], [], [], []] [[0], [], [0], []] q5 q6 q7 q8 - q9 For each character read, threads start hungry and must eat immediately. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 16 / 38
  • 18. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 [[], [], [], []] [[0], [], [], []] [[0], [], [], []] q5 q6 - q4 q7 q8 [[0], [], [0], []] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 17 / 38
  • 19. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 [[], [], [], []] [[0], [], [], []] [[0], [], [], []] q5 q6 [[0], [], [0], []] - q4 [[0], [], [0], [0]] q7 q8 q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 18 / 38
  • 20. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 [[], [], [], []] [[0], [], [], []] q7 q5 q8 - q6 [[0], [], [0], []] q4 [[0], [], [0], [0]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 19 / 38
  • 21. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q5 q8 q6 [[0], [], [0], []] [[0], [], [1], []] q7 - q4 [[0], [], [], []] [[0], [], [0], [0]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 20 / 38
  • 22. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q4 - q5 q6 [[0], [], [1], []] q7 q8 [[0], [], [0], [0]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 21 / 38
  • 23. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q4 - q5 q6 [[0], [], [1], []] q7 q8 [[0], [], [0], [0]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 22 / 38
  • 24. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q4 q7 q8 - q5 q6 [[0], [], [1], []] [[0], [], [1], [1]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 23 / 38
  • 25. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q4 q7 q8 - q5 q6 [[0], [], [1], [1]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 24 / 38
  • 26. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 q4 [[0], [2], [1], [1]] [[0,2], [2], [1], [1]] [[0,2], [2], [1], [1]] [[0,2], [2], [1,3], [1]] q5 q6 q7 q8 [[0], [], [1], [1]] [[0], [2], [1], [1]] - q9 [[0], [2], [1], [1]] For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 25 / 38
  • 27. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 q3 q4 [[0], [2], [1], [1]] [[0,2], [2], [1], [1]] [[0,2], [2], [1], [1]] [[0,2], [2], [1,3], [1]] q5 q6 q7 q8 [[0], [], [1], [1]] [[0], [2], [1], [1]] - q9 [[0], [2], [1], [1]] For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 26 / 38
  • 28. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q5 q8 q6 [[0,2], [2], [1,3], [1]] [[0,2], [2], [1,4], [1]] q7 - q4 [[0,2], [2], [1], [1]] [[0,2], [2], [1,3], [1,3]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 27 / 38
  • 29. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q2 q1 q3 q5 q8 q6 [[0,2], [2], [1,3], [1]] [[0,2], [2], [1,4], [1]] q7 - q4 [[0,2], [2], [1], [1]] [[0,2], [2], [1,3], [1,3]] q9 For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 28 / 38
  • 30. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q1 q2 [[0,2], [2,4], [1,3], [1,3]] [[0,2,5], [2,4], [1,3], [1,3]] q3 q5 q6 - q4 [[0,2,5], [2,4], [1,3], [1,3]] [[0,2,5], [2,4,5], [1,3], [1,3]] q7 q8 [[0,2], [2], [1,3], [1,3]] [[0,2], [2,4], [1,3], [1,3]] q9 [[0,2], [2,4], [1,3], [1,3]] For each character read, threads start hungry and must eat immediately. Only a hungry thread can eat Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 29 / 38
  • 31. Benchmarks NFA interpretation Example: (a?(a)b)+ Reading "aabab" 01234 q9 [[0,2], [2,4], [1,3], [1,3]] 1 2 1 2 a a b a b 0 1 2 3 4 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 30 / 38
  • 32. Download https://github.com/nes1983/tree-regex Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 31 / 38
  • 33. NFA construction S1 S - Optional S? S2 Alternation S1|S2 S S - Capture group (S) Star operation S*? Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 32 / 38
  • 34. Backtracking’s nightmare (a + a+) + b against ”an b” will backtrack Θ(2n ) times. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 33 / 38
  • 35. Backtracking’s nightmare Extract the first cell in a CSV that starts with "P"1 : ∧(.∗?, ) + (P.∗?), failing against ”1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13” is exponential. 1 From http://www.regular-expressions.info/catastrophic.html Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 34 / 38
  • 36. Thread execution order matters .*(a?) start q1 τ1 ↑ q3 a q4 τ1 ↓ q5 any q2 Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 35 / 38
  • 37. Priority matters (a)|(a) q2 a q4 τ1 ↓ τ1 ↑ start q1 q6 τ2 ↑ τ2 ↓ q3 Aaron Karper, Niko Schwarz (UniBe) a q5 Regex Parse Trees January 7, 2014 36 / 38
  • 38. Optimization Pipeline 1 Convert to nondeterministic FA 2 Interpret nondeterministic FA, building deterministic FA lazily. 3 Find similar/mappable states to avoid creating infinite DFA. 4 Run on DFA if possible 5 Compactify DFA if creation of new states wasn’t necessary for a while. Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 37 / 38
  • 39. NFA interpretation Aaron Karper, Niko Schwarz (UniBe) Regex Parse Trees January 7, 2014 38 / 38