Pete's "Double Parked Colon Enforcer" has an ominous sound to it, but still a useful tool.
I think I'll bugger a few of my programs with it. I tend to use a lot of comments and whitespace and always wondered how many actual code lines the big ones contain.
10-23-2022, 12:08 PM (This post was last modified: 10-23-2022, 12:15 PM by bplus.)
(10-23-2022, 05:28 AM)Pete Wrote: 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
(10-23-2022, 06:03 AM)PhilOfPerth Wrote: 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?
(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!"
(10-23-2022, 08:35 AM)SMcNeill Wrote: 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.
Ha! I am jumping in today because what I would like to do is rewrite MasterGY's 89 IDE lines with 20 blank lines but 85 colons to 174 IDE lines without all the dang colons, so I might begin to study the thing.
So that would be the use of this little excursion.
Steve makes a good point about counting lines in includes. Using include for my GUI experiment was not really helpful but then I was still working on the Include code.
So the cake may be baked but I haven't gazed upon it frosted.
Oh I missed Old Moses post, yes it is interesting how many actual LOC it took to do something or what some function costs in LOC.
Isn't it a sign of a smart coder to get something done with less LOC and not taking off points for blank lines and comments.
Those Q-B-64 IF THENs add some more
Type um up, execute, optimize and sell it to the app store
But I gotta keep coding
Ohh, I'm parsing my life away
Lookin' for a better way... for me...
- I thought I saw an Eddie Rabbit. I did , I did!
Seriously, if this app can help with a contest, great, or if someone just wants to compare how many lines of code it took them to make a project, without changing their coding style well that's nice, too; but if it never gets used it was still fun to think through and code.
As for the $INCLUDE, I thought about that but it isn't practical letting anyone use it in a contest, so no worries about INCLUDING $INCLUDE in this app and I won't be going down that Eddie Rabbit hole anytime soon. Decades ago I wrote a program that rewrote itself on the fly, similar to how $INCLUDE works. Just another Eddie Rabbit, I mean Cheap Trick way of coding to break the rules. Kind of like the snow job I made for the Winter forum banner!
Now I need to figure out a way to exclude a colon used as a label
Myline:
This gets a lilte wonkie because labels can have other statements on them..
Myline: a = 2
I would write that as:
Myline:
a = 2
...but coding styles differ.
Remarks are already in the code so no problem with...
Myline: ' Hey, that's my line!
Wait, I think I have it. In the case of a label the IDE pins the colon to the last character. No space. Of course if someone is writing in Notepad, it's not always going to be that way.
This one might not fit all possible conditions outside the IDE. I'm sure not going to add keyword parsing to this little app.
After the program finishes the real lines are placed on your clipboard. You could try and copy the forum code for MG's shadow effects to your clipboard, run this app, open an IDE, and paste 155 un-colonized lines that should run the same as the original.
Now in DEBUG stage. Found one bug with failure to close IF/THEN tags in complex nested statement blocks.
Code: (Select All)
WIDTH 100, 25
_SCREENMOVE _MIDDLE
DIM i AS _INTEGER64
z$ = _CLIPBOARD$
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. [2] to exclude colons in one-line IF/THEN statements.": 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)
IF a$ = CHR$(13) OR a$ = CHR$(10) THEN
IF a$ = CHR$(10) THEN
IF label_check THEN
tmp$ = _TRIM$(MID$(s$, INSTR(s$, ":") + 1))
IF MID$(tmp$, 1, 3) = "REM" OR LEFT$(tmp$, 1) = "'" OR tmp$ = CHR$(10) + CHR$(13) OR tmp$ = "" THEN ELSE MID$(z$, label_check, 1) = CHR$(0): c_cnt = c_cnt + 1
END IF
if_block$ = "": then_marker = 0
c$ = "": parse1$ = "": parse2$ = "": parse3$ = "": label_check = 0: ide_line_cnt = ide_line_cnt + 1
IF parse4$ = "off" THEN rem_lines = rem_lines + 1
IF LEN(s$) = 0 THEN blank_line_cnt = blank_line_cnt + 1
s$ = ""
ELSE
IF if_block$ = "on" THEN
MID$(z$, i, 1) = CHR$(255): MID$(z$, then_marker, 1) = CHR$(0): c_cnt = c_cnt + 1 ' Add one line for the END IF
if_block$ = "": then_marker = 0
END IF
END IF
ELSE
s$ = s$ + a$
c$ = c$ + a$
IF myopt THEN IF c$ = "THEN " THEN IF parse1$ = "" AND parse2$ = "" AND parse4$ = "" THEN parse3$ = "off"
IF myopt = 0 THEN IF c$ = "THEN " THEN then_marker = i
IF s$ = "$IF THEN" THEN parse4$ = "off": parse1$ = "": parse2$ = "": parse3$ = ""
IF a$ = "'" OR c$ = "REM " THEN
IF parse1$ = "" AND parse2$ = "" AND parse3$ = "" AND parse4$ = "" THEN parse1$ = "off"
IF _TRIM$(s$) = _TRIM$(c$) THEN rem_lines = rem_lines + 1
END IF
IF parse4$ = "off" THEN IF s$ = "$END IF " THEN parse4$ = ""
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 parse4$ <> "off" THEN
IF myopt = 0 AND then_marker THEN IF a$ = ":" THEN IF if_block$ = "" THEN if_block$ = "on"
IF col$ = "on" THEN IF a$ <> " " AND a$ <> ":" THEN col$ = ""
IF a$ = ":" THEN ' Test for label.
IF INSTR(MID$(LTRIM$(s$), 1, INSTR(LTRIM$(s$), ":")), " ") = 0 THEN
label_check = i + 1
ELSE
IF col$ = "" THEN col$ = "on": c_cnt = c_cnt + 1: MID$(z$, i, 1) = CHR$(0)
END IF
END IF
END IF
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
_CLIPBOARD$ = ""
FOR i = 1 TO LEN(z$)
a$ = MID$(z$, i, 1)
IF a$ = CHR$(0) THEN
concat$ = concat$ + CHR$(13) + CHR$(10)
ELSEIF a$ = CHR$(255) THEN
concat$ = concat$ + CHR$(13) + "END IF"
ELSE
concat$ = concat$ + a$
END IF
NEXT
_CLIPBOARD$ = concat$
PRINT: PRINT "Program line rewrite was added to your clipboard."
This one does keep the blank lines, it just ignores them in the count. It could be easily modified to strip the blank lines out. I'm considering that for a proof of real line numbers. For instance, if you run MG's app through the program with "Y" and "1" options, you get a paste of 175 IDE lines, so 20 of those are blank lines for spacing.
10-23-2022, 07:43 PM (This post was last modified: 10-23-2022, 07:45 PM by bplus.)
(10-23-2022, 07:39 PM)Pete Wrote: This one does keep the blank lines, it just ignores them in the count. It could be easily modified to strip the blank lines out. I'm considering that for a proof of real line numbers. For instance, if you run MG's app through the program with "Y" and "1" options, you get a paste of 175 IDE lines, so 20 of those are blank lines for spacing.
Pete
That's just about it! I see only one missed colon after Do but all the colons enclosed in Print " : " preserved.
I ran the revised program and according to screen shot is working fine.
Rewrite MasterGy's Shadowing:
Code: (Select All)
picture$ = "" '<-------- enter an image or leave the field blank
'texture
If _FileExists(picture$) Then
text = _LoadImage(picture$, 33)
Else
temp = _NewImage(1, 1, 32)
_Dest temp
Cls , _RGB32(255, 255, 255)
text = _CopyImage(temp, 33)
_FreeImage temp
End If
'draw cubes
px1 = cube_res / 2
px2 = cube_res - 2
dl = cube_deep - 3
c_dis = Interpolate(50, 2500, light)
temp = cube_deep / c_dis
For a_obj = 0 To obj_c - 1
For t = 0 To 7
For t2 = 0 To 2
pc(t, t2) = (obj(a_obj, 3 + t2) * (Sgn(t And 2 ^ t2) * 2 - 1) + (obj(a_obj, t2) - me(t2)))
Next t2
rotate pc(t, 0), pc(t, 1), pc(t, 2)
pc(t, 3) = Sqr(pc(t, 0) * pc(t, 0) + pc(t, 1) * pc(t, 1) + pc(t, 2) * pc(t, 2))
sm = shdw_m(Abs(Int(pc(t, 2))))
For t2 = 0 To 2
pc(t, 4 + t2) = pc(t, t2) * sm
Next t2
Next t
For t = 0 To 5
For t2 = 0 To 3
side(t2) = Val(Mid$("024623673175105445670123", 1 + t * 4 + t2, 1))
For t3 = 0 To 2
p(t2, t3) = pc(side(t2), t3)
p2(t2, t3) = pc(side(t2), t3 + 4)
Next t3, t2