Program Real Line Counter. Anyone want to jump in?
#11
Okay, added Steve's suggestions and Mark's REM option.

Code: (Select All)
PRINT "Line count analysis...": PRINT

DO
    LINE INPUT "Count statements beginning with REM or ' as a line? [Y] / [N]: "; rem_ans$: PRINT
    rem_ans$ = UCASE$(rem_ans$)
    IF INSTR("YN", rem_ans$) THEN EXIT DO
LOOP

PRINT "Press [1] to parse all colons or [2] the exclude colons after an IF statement.": PRINT

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        SELECT CASE b$
            CASE CHR$(27): SYSTEM
            CASE "1": myopt = 3: PRINT "Parsing all significant colons...": PRINT
            CASE "2": myopt = 4: PRINT "Parsing all significant colons not used in IF/THEN one line statements.": PRINT
        END SELECT
        IF myopt THEN EXIT DO
    END IF
LOOP
_KEYCLEAR

x$ = _CLIPBOARD$
IF RIGHT$(x$, 2) <> CHR$(13) + CHR$(10) THEN x$ = x$ + CHR$(13) + CHR$(10) ' Compensates for 1-line no return Notepad copy.

DO
    ' parse clipboard
    statement$ = _TRIM$(UCASE$(MID$(x$, 1, INSTR(x$, CHR$(13)) - 1)))
    x$ = MID$(x$, INSTR(x$, CHR$(10)) + 1)

    DO
        IF RIGHT$(RTRIM$(statement$), 1) = "_" THEN ' Combined statement.
            statement$ = statement$ + UCASE$(MID$(x$, 1, INSTR(x$, CHR$(13)) - 1))
            x$ = MID$(x$, INSTR(x$, CHR$(10)) + 1)
            program_ide_lines = program_ide_lines + 1
        ELSE
            EXIT DO
        END IF
    LOOP

    IF LEN(_TRIM$(statement$)) THEN
        program_ide_lines = program_ide_lines + 1
        FOR i = 1 TO myopt
            SELECT CASE i
                CASE 1: mychr$ = CHR$(34)
                CASE 2: mychr$ = "'"
                CASE 3: mychr$ = "REM "
                CASE 4: mychr$ = " THEN "
            END SELECT

            SELECT CASE i
                CASE 1 '  Double polling for enclosed quotes.
                    DO UNTIL INSTR(statement$, mychr$) = 0
                        IF INSTR(statement$, mychr$) THEN
                            statement$ = MID$(statement$, 1, INSTR(statement$, mychr$) - 1) + MID$(statement$, INSTR(INSTR(statement$, mychr$) + 1, statement$, mychr$) + 1)
                        END IF
                    LOOP
                CASE ELSE
                    DO UNTIL INSTR(statement$, mychr$) = 0
                        IF INSTR(statement$, mychr$) THEN
                            IF myopt = 3 THEN IF rem_ans$ = "N" THEN IF MID$(statement$, 1, 4) = "REM " OR LEFT$(statement$, 1) = "'" THEN linecnt = linecnt - 1: real_line_cnt = real_line_cnt - 1
                            statement$ = MID$(statement$, 1, INSTR(statement$, mychr$) - 1)
                        END IF
                    LOOP
            END SELECT
        NEXT
        IF RIGHT$(RTRIM$(statement$), 1) = ":" THEN statement$ = MID$(RTRIM$(statement$), 1, LEN(RTRIM$(statement$)) - 1)
        ' Parse significant single colons.
        DO UNTIL INSTR(statement$, " ") = 0
            statement$ = MID$(statement$, 1, INSTR(statement$, " ") - 1) + MID$(statement$, INSTR(statement$, " ") + 1)
        LOOP
        ' Now look for double or multiple colons and remove them
        DO UNTIL INSTR(statement$, "::") = 0
            statement$ = MID$(statement$, 1, INSTR(statement$, ":") - 1) + MID$(statement$, INSTR(statement$, ":") + 1)
        LOOP
        ' count colons.
        seed% = 0: linecnt = linecnt + 1: real_line_cnt = real_line_cnt + 1

        DO UNTIL INSTR(seed%, statement$, ":") = 0
            seed% = INSTR(seed%, statement$, ":") + 1
            real_line_cnt = real_line_cnt + 1
        LOOP
    ELSE
        program_ide_lines = program_ide_lines + 1
    END IF
LOOP UNTIL x$ = ""
IF rem_ans$ = "Y" THEN
    PRINT "Program IDE lines ="; program_ide_lines; "  Line count ="; linecnt; "  Real line count ="; real_line_cnt
ELSE
    PRINT "Program IDE lines ="; program_ide_lines; "  Line count without remark lines ="; linecnt; "  Real line count ="; real_line_cnt
END IF


Pete
If eggs are brain food, Biden takes his scrambled.
Reply
#12
For fun, I also started something more compact using a slightly different approach...

Code: (Select All)
DIM i AS _INTEGER64

x$ = UCASE$(_CLIPBOARD$)
IF RIGHT$(x$, 2) <> CHR$(13) + CHR$(10) THEN x$ = x$ + CHR$(13) + CHR$(10) ' Compensates for 1-line no return Notepad copy.

PRINT "Line count analysis...": PRINT

DO
    LINE INPUT "Count statements beginning with REM or ' as a line? [Y] / [N]: "; rem_ans$: PRINT
    rem_ans$ = UCASE$(rem_ans$)
    IF INSTR("YN", rem_ans$) THEN EXIT DO
LOOP

PRINT "Press [1] to parse all colons or [2] the exclude colons after an IF statement.": PRINT

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        SELECT CASE b$
            CASE CHR$(27): SYSTEM
            CASE "1": PRINT "Parsing all significant colons...": EXIT DO
            CASE "2": myopt = -1: PRINT "Parsing all significant colons not used in IF/THEN one line statements.": EXIT DO
        END SELECT
    END IF
LOOP
PRINT
_KEYCLEAR

FOR i = 1 TO LEN(x$)
    a$ = MID$(x$, i, 1)
    'PRINT i; ASC(MID$(x$, i, 1)); MID$(x$, i, 1); "  p1$ = "; parse1$; "  p2$ = "; parse2$; "  p3$ = "; parse3$: SLEEP
    IF a$ = CHR$(13) OR a$ = CHR$(10) THEN
        IF a$ = CHR$(10) THEN
            c$ = "": parse1$ = "": parse2$ = "": parse3$ = "": ide_line_cnt = ide_line_cnt + 1
            'PRINT s$, LEN(s$): SLEEP
            IF LEN(s$) = 0 THEN blank_line_cnt = blank_line_cnt + 1
            s$ = ""
        END IF
    ELSE
        s$ = s$ + a$
        c$ = c$ + a$
        IF myopt THEN
            IF c$ = "THEN " THEN IF parse1$ = "" AND parse2$ = "" THEN parse3$ = "off"
        END IF
        IF a$ = "'" OR c$ = "REM " THEN
            IF parse1$ = "" AND parse2$ = "" THEN parse1$ = "off"
            IF _TRIM$(s$) = _TRIM$(c$) THEN rem_lines = rem_lines + 1
        END IF
        IF a$ = " " THEN c$ = ""
        IF parse1$ <> "off" THEN
            IF a$ = CHR$(34) THEN IF parse1$ = "" AND parse3$ = "" THEN IF parse2$ = "off" THEN parse2$ = "" ELSE parse2$ = "off"
            IF parse2$ <> "off" THEN
                IF parse3$ <> "off" THEN
                    IF col$ = "on" THEN IF a$ <> " " AND a$ <> ":" THEN col$ = ""
                    IF a$ = ":" AND col$ = "" THEN col$ = "on": c_cnt = c_cnt + 1
                END IF
            END IF
        END IF
    END IF
    IF a$ = "_" THEN IF MID$(x$, i + 1, 1) = CHR$(13) THEN IF parse1$ = "" AND parse2$ = "" AND parse3$ = "" THEN cont_lines = cont_lines + 1
NEXT
IF rem_ans$ = "Y" THEN
    PRINT "IDE Lines ="; ide_line_cnt; "  Statement Lines ="; ide_line_cnt - blank_line_cnt - cont_lines; "  Real Lines ="; ide_line_cnt - blank_line_cnt - cont_lines + c_cnt
ELSE
    PRINT "IDE Lines ="; ide_line_cnt; "  Statement Lines Without Remark Lines ="; ide_line_cnt - blank_line_cnt - cont_lines - rem_lines; "  Real Lines ="; ide_line_cnt - blank_line_cnt - cont_lines - rem_lines + c_cnt
END IF

Pete
Reply
#13
Hey guys, here's one...

Code: (Select All)
$IF A THEN
        foo1
        foo2
        foo3
$END IF

Any reason this block REM hack shouldn't be ignored?
Reply
#14
(10-23-2022, 04:31 AM)Pete Wrote: Hey guys, here's one...

Code: (Select All)
$IF A THEN
        foo1
        foo2
        foo3
$END IF

Any reason this block REM hack shouldn't be ignored?

Just the common sense idea that you're getting silly at this point.

$LET A = TRUE
$IF A THEN
    '.....insert 100,000,000 line program
$END IF

If you ignore that $IF statement, then I just wrote a 1 line program!

If you're going to start testing the $IF condition, then...  good luck with that!  You'll be writing your own mini-language of definitions and comparisons and all that jazz!

After all, which lines do you count?

$IF A THEN
   PRINT "foo"
   X = 2
$ELSE
   PRINT "mootoo"
   Y = s
   S = x
   x = Y
$END IF

The $IF lines?  The $ELSE lines?  Neither?  Both?

You're opening up a crazy can of worms trying to decide to count/not count $IF lines.
Reply
#15
Yeah, I would rather punt on this bastard.

Code: (Select All)
APPLE = 1
$IF APPLE = 1 THEN
        PRINT "Pete"
        add
        add
$END IF

Does nothing, other than act as a block remark statement, but...

Code: (Select All)
$LET APPLE = 1
$IF APPLE = 1 THEN
        PRINT "Pete"
        ' add
        ' add
$END IF

Add in the $LET and now you have to rem out the "add" statements, because now the compiler will process it. So what a PITA to track down all $LET statements and marry them $IF/THENs.

Pete
Reply
#16
Well unless anyone else has anything missed to add, I think this cake is backed. I like method #2 best, but I haven't speed tested them. Too me, QB64 handles these types a text functions so fast, it really doesn't make much of a difference.

Now, if nothing more gets added, we just need some beta tests to see if anything can be broke or simply doesn't function as expected.

Pete
Reply
#17
I'm a bit bemused by all of this... why is it important to know how many lines it can be broken down into? Does this have a bearing on a programmes's speed, or usefulness, or memory-useage? Surely the file size and design can tell you what you need to know?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#18
1) It's parsing, which makes it fun.

2) Practical use: Contests.

Once in a blue moon someone will put together a contest. Maybe write a pong game in 100 lines or less. Maybe even fewest lines wins. Anyway, colons make it possible to place many statements on a single line. Parsing out the colons, which serve that purpose, makes judging the actual lines used to code the program quantifiable.

Pete

Like I always say, "Don't take it parsenally!"
Reply
#19
Now what you need to work on is a QB64PE-Merge program which recursively loads all $INCLUDE files and then saves the whole program as a singular BAS file for total line count, quick reference, formatting, and debugging purposes. Wink
Reply
#20
(10-23-2022, 06:10 AM)Pete Wrote: 1) It's parsing, which makes it fun.

2) Practical use: Contests.

Once in a blue moon someone will put together a contest. Maybe write a pong game in 100 lines or less. Maybe even fewest lines wins. Anyway, colons make it possible to place many statements on a single line. Parsing out the colons, which serve that purpose, makes judging the actual lines used to code the program quantifiable.

Pete

Like I always say, "Don't take it parsenally!"
Yep, now I get it.
I'll watch from the kiosk. Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply




Users browsing this thread: 24 Guest(s)