A diary of two contributions to grammars-v4, ANTLR's grammar repository: first the Full BASIC grammar and, nine days later, the Minimal BASIC one.
BASIC was my first contact with programming, back in the 1980s, sitting at the display computers in shops. Much later, with programming languages as a hobby, I came to ANTLR and Terence Parr's books, and wanted to do something real with them by going back to BASIC. The first attempt, AJGBasic, was built on a modified version of jvmBasic and was published in 2013. Then I turned to the standards: Minimal BASIC, the 1978 one, as a hobby for ten years until its first version in 2023, and in parallel Full BASIC, the 1987 one, on an ANTLR grammar I wrote from scratch from the BNF of ANSI X3.113, about 1,600 lines long.
In November 2026 I took that grammar to grammars-v4, ANTLR's community grammar repository, and a few days later did the same with the Minimal BASIC one. This is the diary of those two weeks.
Two days earlier I had published the Full BASIC conformance suite under the MIT licence. The grammar complements it. The suite checks what an interpreter does, and the grammar lets anyone read Full BASIC programs without writing a parser. grammars-v4 had a single BASIC grammar, the very jvmBasic AJGBasic had started from, and none for the standards.
The interpreter is closed source, so the first thing to settle was the licence. The two grammar files are published under MIT, like the suite, and the rest of the repository stays as it was. Comments cite sections of the standard ("§7.2") without copying its text, and the header names the three equivalent standards: ANSI X3.113 by way of FIPS PUB 68-2, which is freely available, ECMA-116 and ISO/IEC 10279.
The technical side weighed more. grammars-v4's continuous integration generates each parser in Java, C#, Python, JavaScript, TypeScript, Go, Dart and C++, and runs it in all of them, so grammars have to be free of code in any particular language. Mine had five rules with fragments of C++, each one because of a Full BASIC quirk:
SIN, LEN and the other functions can be used as variable names. A predicate looked ahead for a parenthesis.DATA isn't a reserved word either, and what follows it is read almost as free text, spaces included. Another rule looked backwards and forwards to recognise it.grammars-v4 accepts predicates if they come with a base class written in each target language. Keeping the same code in eight languages seemed too much to me.
The first plan was a script to produce a clean version of the interpreter's grammar. To check it, I built a harness that ran my 2,537 test programs (the interpreter's test bench and the suite) through both versions and compared what each one accepted and rejected. It found zero differences, and that made the script unnecessary: if the clean grammar accepts exactly the same programs, the interpreter can use it as it is. Keeping two grammars ends with two different grammars.
What the C++ used to do moved to the stage that walks the parser's tree. Upper-casing happens there. SIN and friends appear in the grammar as words that can act as identifiers, and when a parenthesis follows them the function call is tried first. DATA is parsed as a list of items, and the interpreter recovers the exact text of each one from the source file. There were two subtle cases. MAT T = SHIFT(1,2) * V could be read two ways and needed a rule of its own. And some badly written DATA statements would have lost their error message, so the interpreter validates them before calling the parser.
Getting the grammar ready for other readers also turned up accumulated leftovers: a token, EXPONENT, that the lexer never defined; another, DIGIT_CHAR, that was never produced; an ambiguous definition of PRINT; an unused rule, four spare tokens, and six warnings from letter sets like [A-Za-z] in a grammar that already ignored case. ANTLR now generates it without a single warning. By the end of the day the 6,637 core tests, the 440 bench programs and the suite's 2,085 were all passing.
grammars-v4 recommends presenting a new grammar in an issue before sending it. I prepared the package with the grammar's two files, a desc.xml with the target languages, a README with the sources and the deliberate deviations from the standard, and 60 programs from the suite as examples. With trgen, the tool their continuous integration uses, it passed in Java, C#, Python, JavaScript and C++.
I asked two things: where to put it, since jvmBasic took up the whole basic/ folder, and whether I could declare every target language although I had only tested five. One of the maintainers replied in about forty minutes. The suggestion was to turn basic/ into a folder with one subfolder per grammar, move jvmBasic to basic/jvmBasic/ keeping its history, and put mine in basic/fullbasic/. On the languages, declare them all and let continuous integration say which ones failed.
The pull request went out that same afternoon, reorganisation included.
All 34 checks passed first time, including Dart, Go, TypeScript and Antlr4ng, which I hadn't been able to test. It was merged with a "thanks!" and no round of changes.
Full BASIC extends an earlier and much smaller standard, the 1978 Minimal BASIC (ECMA-55, equivalent to ANSI X3.60). Around then I was preparing version 2.0 of Minimal BASIC, with plenty of improvements and a rebuilt core, and I took the chance to bring its grammar in line with the rules learnt the week before: a single grammar for the interpreter and for publishing, MIT licence, the grammars-v4 folder layout, and no code in any particular language. What a grammar expresses badly, such as the order of line numbers, END coming last or every FOR having its NEXT, is checked by the interpreter, and the README explains it.
The tests came almost ready-made. The National Bureau of Standards test programs for Minimal BASIC are in the public domain, and their 134 programs make up the positive test. I added a negative one, which the Full BASIC grammar didn't have: 13 small programs that must be rejected with an exact error, such as 2^-1, A$<B$ or LET A$=B$+C$. A fourteenth, ON X GOSUB 20, was left out because the Java runtime lists more expected tokens than the others and no single message worked for all of them.
This time I went straight to the pull request, since the basic/ folder was already set up for several grammars. On the first continuous integration run, all nine Windows jobs failed. Two of the expected-error files contain a newline, and Git on Windows was turning it into CRLF. One line in .gitattributes fixed it.
A couple of checks timed out on the continuous integration's macOS servers, and one of the maintainers asked for them to be rerun a few hours later, when the load was lighter.
Merged, with the same "thanks!". The basic/ folder now holds three grammars, jvmBasic, fullbasic and minimalbasic, with the two ANSI/ECMA BASIC standards side by side.
The Full BASIC grammar had to be cleaned up before it could be published, and the interpreter came out ahead: no language-specific code, no warnings, and a harness that keeps an eye on what it accepts. The Minimal BASIC grammar was prepared that way from the start of 2.0, and sending it was little more than copying a folder.
Both are in grammars-v4 under the MIT licence:
There's more detail on the Full BASIC open-source page.