From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb6ebeb41bf44573 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 MSIE X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: character matching References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 13 Aug 2004 18:41:19 GMT NNTP-Posting-Host: 63.184.9.102 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1092422479 63.184.9.102 (Fri, 13 Aug 2004 11:41:19 PDT) NNTP-Posting-Date: Fri, 13 Aug 2004 11:41:19 PDT Xref: g2news1.google.com comp.lang.ada:2722 Date: 2004-08-13T18:41:19+00:00 List-Id: John J wrote: > To develop a program that counts words and sentences I'm trying to > write some code that will recognise a word due to it being a series > of alphanumeric characters terminated by one or more of a space, > comma, fullstop, colon, exclamation mark or question mark. I'm going > to use a case to match the condition then perform an advance on a > wordcounter. > > I also need to include a case match that will recognise sentences by > being a sequence of words terminated by one or more of full stop, > exclamation mark, question mark or colon. The code also needs to be > able to accept that there maybe spaces between the last word of the > sentence and the terminating stop ie. "hope this works !". I'm not > sure on how to match these conditions and would greatly appreciate > some assistance. My skeletion code is as follows: This certainly sounds like a homework assignment. A good approach to this is to consider it a state machine with 2 states: you're either in a word or not in a word; initially you're not in a word. When you're not in a word, characters that terminate a word are junk and leave you in the same state; characters that can be a word put you into the in-a-word state. When you're in a word, characters that can be a word leave you in the same state; characters that terminate a word put you into the not-in-a-word state and terminators that terminate a sentence can also increment the sentence count. This kind of approach can help you consider "Help me!!!" as one sentence rather than 3. -- Jeff Carter "Ada has made you lazy and careless. You can write programs in C that are just as safe by the simple application of super-human diligence." E. Robert Tisdale 72