fork(2) download
  1. procedure main()
  2. s := "Mon Dec 8"
  3. s ? write(Mdate() | "not a valid date")
  4. end
  5. # Define a matching function that returns
  6. # a string that matches a day month dayofmonth
  7. procedure Mdate()
  8. # Define some initial values
  9. static dates
  10. static days
  11. initial {
  12. days := ["Mon","Tue","Wed","Thr","Fri","Sat","Sun"]
  13. dates := ["Jan","Feb","Mar","Apr","May","Jun",
  14. "Jul","Aug","Sep","Oct","Nov","Dec"]
  15. }
  16. every suspend (retval <- tab(match(!days)) || # Match a day
  17. =" " || # Followed by a blank
  18. tab(match(!dates)) || # Followed by the month
  19. =" " || # Followed by a blank
  20. matchdigits(2) # Followed by at least 2 digits
  21. ) &
  22. (=" " | pos(0) ) & # Either a blank or the end of the string
  23. retval # And finally return the string
  24. end
  25. # Matching function that returns a string of n digits
  26. procedure matchdigits(n)
  27. suspend (v := tab(many(&digits)) & *v <= n) & v
  28. end
  29.  
  30.  
stdin
Standard input is empty
compilation info
Translating:
prog.icn:
  main
  Mdate
  matchdigits
No errors
Linking:
stdout
Mon Dec 8