| Paste number 24849: | Regular expression engine in 14 lines of Python |
| Pasted by: | psykotic |
| 1 years, 8 months ago | |
| None | |
| Paste contents: |
| def iconcat(xs, ys): for x in xs: yield x for y in ys: yield y def nil(s): yield s def seq(l, r): return lambda s: (sr for sl in l(s) for sr in r(sl)) def alt(l, r): return lambda s: iconcat(l(s), r(s)) def star(e): return lambda s: iconcat(nil(s), seq(e, star(e))(s)) def plus(e): return seq(e, star(e)) def char(c): def match(s): if s and s[0] == c: yield s[1:] return match # c(a|d)+r e = seq(char('c'), seq(plus(alt(char('a'), char('d'))), char('r'))) import sys s = sys.stdin.readline()[:-1] for r in e(s): print "Match with remainder:", r |
Annotations for this paste:
| Annotation number 1: | 22222 |
| Pasted by: | 11111 |
| 1 years, 8 months ago | |
| Paste contents: |
| 33333 |
| Annotation number 2: | 22222 |
| Pasted by: | 11111 |
| 1 years, 8 months ago | |
| Paste contents: |
| 33333 |
| Annotation number 3: | Sir |
| Pasted by: | Martin |
| 1 years, 8 months ago | |
| Paste contents: |
| sdkao |
| Annotation number 4: | multiple |
| Pasted by: | Deepak |
| 1 years, 8 months ago | |
| Paste contents: |
| 23233 |
| Annotation number 5: | test |
| Pasted by: | jens |
| 1 years, 8 months ago | |
| Paste contents: |
| testtext |
| Annotation number 6: | 24849 |
| Pasted by: | 24849 |
| 1 years, 4 months ago | |
| Paste contents: |
| 24849 |
| Annotation number 7: | oppo |
| Pasted by: | dyrtrt |
| 1 years, 4 months ago | |
| Paste contents: |
| ertret |