TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Monospaced Font
Show HTML Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender: "Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Date: Tue, 12 Oct 1999 11:59:15 -0400
Reply-To: Clyde Roby <[log in to unmask]>
Content-Transfer-Encoding: 7bit
From: Clyde Roby <[log in to unmask]>
X-cc: Clyde Roby <[log in to unmask]>
In-Reply-To: <[log in to unmask]> from "David Botton" at Oct 11, 1999 03:31:33 PM
Content-Type: text/plain; charset=us-ascii
MIME-Version: 1.0
Parts/Attachments: text/plain (84 lines)
Someone requested an Ada statement counter on one of these lists.
Here's a very simple-minded semi-colon counter that I wrote in 1991
(please be kind)...Clyde

--- procedure SEMI
--
--  Count all semi-colons in the input file and send this
--  count to the output file.

with TEXT_IO; use TEXT_IO;

procedure SEMI -- Count all semicolons.

is

    package INT_IO is new INTEGER_IO (NATURAL);

    CHAR: CHARACTER;
    LINE: STRING (1 .. 250);

    LAST: NATURAL;

    COUNTER: NATURAL := 0;

    QUOTE, DQUOTE, MINUS : BOOLEAN;

begin

    while not END_OF_FILE loop

        GET_LINE (LINE, LAST);

        if LAST >= LINE'FIRST then

            QUOTE := FALSE;
            DQUOTE := FALSE;
            MINUS := FALSE;

            for I in 1 .. LAST loop
                CHAR := LINE (I);
                case CHAR is
                    when '-' =>
                        if not DQUOTE and not QUOTE then
                            if MINUS then
                                -- double MINUS, i.e., comment; exit loop
                                exit;
                            else
                                -- We've seen a minus.
                                MINUS := TRUE;
                            end if;
                        end if;
                    when '"' =>
                        if not QUOTE then
                            -- not within a quote
                            DQUOTE := not DQUOTE;
                        end if;
                        MINUS := FALSE;
                    when ''' =>
                        if not DQUOTE then
                            -- not within a double quote
                            QUOTE := not QUOTE;
                        end if;
                        MINUS := FALSE;
                    when ';' =>
                        if not DQUOTE and not QUOTE then
                            -- not within quotes of any kind, count it.
                            COUNTER := COUNTER + 1;
                        end if;
                        MINUS := FALSE;
                    when OTHERS =>
                        MINUS := FALSE;
                end case;
            end loop;

        end if;

    end loop;

    PUT ("There are");
    INT_IO.PUT (COUNTER, WIDTH => 10);
    PUT_LINE (" semi-colons in the input stream.");

end SEMI;

ATOM RSS1 RSS2