Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.5%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: Moderocky
- License: mit
- Language: Java
- Default Branch: main
- Size: 95.7 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Whilezie
A compiler for the basic WHILE language to VM bytecode.
Preface: Notes on Implementation
I built this in my 'model' language style: a source code document is turned into a string of tokens, parsed into a complete 'model' of the document, then compiled. This is not the most efficient way to write a compiler -- especially for something like WHILE, which needs to know very little about its surrounding code.
The 'model' stage is a rigorous in-memory structure of the code. This is a fantastic way to verify and test the program, resolve forward references, collect insights, or build new adaptations (e.g. 'transpilation' to another language). If I were writing an optimal compiler, the parsing should be done at the same time as the tokenising and the model step could be skipped entirely. (In fact, WHILE is so basic it could be done in a single stream without a backtracking buffer.)
The bytecode assembler is my Foundation 3. Aside from being a lot more fun to use, it allowed me to do a lot of the resolution of values at compile-time.
Grammar
There seemed to be some disagreement over what is considered the 'essential' WHILE grammar. I chose to eliminate everything other than the bare essentials.
```antlr identifier: [A-Za-z][A-Za-z0-9]*
program:
|
statements:
|
statement:
|
expression:
| nil
| cons
Grammar Extensions
I also included the following as optional extensions in the parser. Most extensions resolve to their real code.
Macros
antlr
expression:
| < <identifier> > <expression>
Macros
antlr
statement:
| if <expression> <statement> else <statement>
| if <expression> <statement>
Literals
antlr
expressions:
| <expression>
| <expressions> , <expression>
expression:
| < <expression> . <expression >
| [ <expressions> ]
| (true|false)
| [0-9]+
There seem to be some discrepancies about what is considered 'core' to the WHILE language.
Text & Print-out
Some WHILE implementations include text literals and a print keyword.4
I chose not to include these.
However, my tokeniser has quoted text support, so an extender would only need to handle the text to binary tree
conversion.
Numbers & Maths
Some grammars and implementations include number literals.1 4 I also chose not to include these. My reasoning was that part of the excitement of WHILE is assembling everything from binary trees. My tokeniser has support for number literals, and the built-in Java operation methods have tree to number conversion.
If, Else & Switch
Some grammars include language-level if and switch statements.
I found this to be a little antithetical to the original purpose of WHILE:
I think the idea of being able to construct every other flow control statement from while-loops is betrayed slightly by
also including every other flow control statement.
I included if and if-else as optional content in the model parser.
Skip
A no-operation code skip is included in some BNF grammars for WHILE, due to its presence in Hoare logic.
Since I already had the block {} as an empty statement, I did not include this.
Example Macros
Several programs (macros) are included as examples:
- Logic (not, and, or, xor, implication)
- (Positive) addition, subtraction, multiplication, division
- Deep-tree equality, number-kind test
While-in-While
I wanted to create WHILE-evaluation in WHILE.
Instruction Set
I stuck to the simplest possible program representation.
- A program is a list of instructions.
- Each instruction is a three-address list.
- The first element in an instruction is a numerical operation code corresponding to the instruction.
- The interpretation of the following elements depends on the instruction.
Theoretically, it is not very difficult to represent any WHILE program as three-address code. This is essentially what the model stage of my compiler does, and doing it in WHILE itself is no different. The only minor difference between Java bytecode and three-address code is that bytecodes take up a variable number of slots, whereas the three-address code is a fixed number. I have cheated slightly in that, rather than jumping to subroutines within the instruction set, I simply call the evaluator with a sub-instruction.
The operation codes are displayed below.
1. while
Evaluation
- Variables are indexed numerically in a register list
- A two-element stack is used to hold values.
References
- Jonathan Aldrich, "The WHILE Language and WHILE3ADDR Representation", cs.cmu.edu.
- Giulio Guerrieri, "Limits of Computation (4): WHILE-Semantics", Lecture, University of Sussex, Feb. 2025.
- Aho, Sethi, Ullman, "Compilers: Principles, Techniques, and Tools", Addison-Wesley, 1986.
- Leonardo Lucena, "While language", whilelang, Federal Institute of Education, Science & Technology, Brazil.
Owner
- Name: Moderocky
- Login: Moderocky
- Kind: user
- Location: United Kingdom
- Company: @SkriptLang
- Website: www.byteskript.org
- Repositories: 14
- Profile: https://github.com/Moderocky
Specialist in metaprogramming tools, compilers and interpreters. Lead @ ByteSkript Lead @ SkriptLang
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Scott" given-names: "Mackenzie" title: "Whilezie" version: 1.0.0 date-released: 2025-02-05 url: "https://github.com/Moderocky/Whilezie"
GitHub Events
Total
- Push event: 10
- Create event: 2
Last Year
- Push event: 10
- Create event: 2
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- org.valross:constantine 1.0.0 compile
- org.valross:foundation-assembler 3.0.0 compile
- junit:junit 4.13.2 test