Custopootimus

Prolog Regexp

Mar 8th, 2015
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.84 KB | None | 0 0
  1. % Infix operators for shorthand
  2. :- op(1000,yfx,).
  3. :- op(1200,yfx,).
  4. :- op(1100,yfx,).
  5. :- op( 900, xf,).
  6.  
  7. % Notes on names:
  8. % P     Pattern
  9. % I     Input
  10. % Subscripts ᵢ and ⱼ are used to differentiate two things of the same
  11. %   type, e.g., two patterns, or two inputs.
  12. % The subscript ᵨ denotes that the variable is an array.
  13.  
  14. % Epsilon matches empty
  15. regex(ε,[]).
  16.  
  17. % Concatenation
  18. regex((Pᵢ,Pⱼ),Iᵨ)
  19.  :- append(Iᵢ,Iⱼ,Iᵨ)
  20.   , regex(Pᵢ,Iᵢ)
  21.   , regex(Pⱼ,Iⱼ).
  22.  
  23. % Union
  24. regex((Pᵢ,Pⱼ),Iᵨ)
  25.  :- regex(Pᵢ,Iᵨ)
  26.   ; regex(Pⱼ,Iᵨ).
  27.  
  28. % Intersection
  29. regex((Pᵢ,Pⱼ),Iᵨ)
  30.  :- regex(Pᵢ,Iᵨ)
  31.   , regex(Pⱼ,Iᵨ).
  32.  
  33. % Kleene Star
  34. regex((_),[]).
  35. regex((Pᵢ),Iᵨ)
  36.  :- append(Iᵢ,Iⱼ,Iᵨ)
  37.   , regex(Pᵢ,Iᵢ)
  38.   , regex(*(Pᵢ),Iⱼ).
  39.  
  40. regex(P,[P])
  41.  :- atom(P).
Advertisement
Add Comment
Please, Sign In to add comment