home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / tests / recogn.icn < prev    next >
Text File  |  1992-02-09  |  600b  |  29 lines

  1. #
  2. #          C F L   R E C O G N I T I O N
  3. #
  4.  
  5. #  This program takes strings from standard input and determines
  6. #  whether or not they are sentences in the language defined by <s>.
  7.  
  8. procedure main()
  9.    local line
  10.    while line := read() do
  11.       if recogn(s,line) then write("accepted") else write("rejected")
  12. end
  13.  
  14. procedure recogn(goal,text)
  15.    return text ? (goal() & pos(0))
  16. end
  17.  
  18. #  <s> ::= a <s> | <t> b | c
  19.  
  20. procedure s()
  21.    suspend (="a" || s()) | (t() || ="b") | ="c"
  22. end
  23.  
  24. #  <t> ::= d <s> d | e | f
  25.  
  26. procedure t()
  27.    suspend (="d" || s() || ="d") | ="e" | ="f"
  28. end
  29.