Repository navigation
Allows abbreviating ENDPROC as "EN.", in both compilers. - #124
Open
kimslawson wants to merge 2 commits into
Open
kimslawson wants to merge 2 commits into
kimslawson wants to merge 2 commits into
Conversation
"EN." is also an abbreviation of ENDIF, which is tried first: if there is an IF open it closes the IF, as before, and if not, the parser now tries ENDPROC. The cross compiler already did this, as a loop error from ENDIF only fails the current alternative. The native E_POP_IF now does the same: when there is no IF or ELSE to close it fails, so the parser continues with the next statements, and sets the error to report if none matches to "bad loop". As errors are now reported after trying all the alternatives, the column of these errors is the same in both compilers. Costs 23 bytes in the native compilers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
The Windows fallback was a static "strndup", which conflicts with the declaration in newer MinGW <string.h>, failing the Windows CI. Use another name for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Daniel,
This brings back @EricCarrGH's enhancement request from December 2023, #77 "Shorten EndProc abbrev from "ENDP." to "EN."". Eric pointed out that
ENDP.is long for an abbreviation, and thatEN.would save 2 characters perPROC, which adds up in size-coded programs and ten-liners.You closed it because
EN.is already an abbreviation ofENDIF. Inside aPROC,EN.first matchesENDIF, finds noIFto close, and the two compilers then differ. The cross compiler backtracks and triesENDPROC. The native compiler stops with a loop error. You said "Changing this will require a big rewrite of the loop error handling", and you and Eric agreed both compilers must accept exactly the same language.This PR keeps Eric's one-line grammar change and makes the native compiler behave like the cross compiler, without that rewrite. (I did this work with Claude Code, an AI assistant.)
How it works
basic.syn: Eric's change,"ENDProc"becomes"ENdproc"."Endif"still comes first inSTATEMENT.E_POP_IF(actions.asm): before popping, it checks for anIForELSEon top of the loop stack. If there isn't one, it doesn't jump toloop_error. Instead it storesERR_LOOPin a new zero-page byteparse_errand returns with C=1, so the parser goes on to the next statement,ENDPROC. All the other loop actions are unchanged.parse.asm:parse_erris set toERR_PARSEat the start of each statement, andset_parse_errorreportsparse_err. So when nothing else matches, the error is still "bad loop".loop_error()saves the message and only fails the current alternative.fb.xex,fbc.xex,fbi.xex,fbci.xex).What changes for programs
IFopen,EN.(andEND.) still close theIF. They close thePROConly where they used to be a loop error.ENDPROC,ENDP.,ENDIF,E.andENDI.work as before.-lsnow writesEN.forENDPROC, 2 characters shorter each time.-ls:120output of all the samples,cmdline.basandeditor.bas(45EN.) compiles to the same code as the sources. That needs the block order fix from my other PR (branchparser-fixes), because several PROCs now share a line.-lsoutput ofpi.bas,joyas.basand the new test compiles.nc/mastodon(FujiNet) andcmdline.bas(@asm symbols) don't compile natively from the sources either.Native compiler and cross compiler now agree, errors included
I compiled 22 small programs with both compilers, before and after the change: valid and stray
ENDIF/E./EN./END., inside and outsidePROC, withIF/ELSE/ELIF,DO/EXITandFOR, alone and after:.EN.closing aPROCfailed in both compilers. Also, native and cross reported loop errors at different columns. For example, a strayENDIFgave native "bad loop at line 2 column 1" but cross2:5.Tests
make test: 86/86, which is the 83 existing tests plus 3 new ones. The existing loop error tests (err-loop-*,err-endif, ...) pass unchanged.proc-abbrev: runs every form ofENDPROC/ENDIF, includingEN.closing anIFinside aPROC, afterELIF/ELSE, afterDO/EXIT, and in one-linePROCs.err-endif-procanderr-endproc: strayE.andEN.. They check the native message and the cross position, so both compilers must agree.ENDPROC / EN., with a note on theIFcase.Thanks to Eric for the original idea, and to you for giving context (and for writing Fastbasic)!
🤖 Generated with Claude Code
https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM