https://github.com/expertcoderz/fun-with-pseudocode
Python utility for parsing CIE AS & A Level-style pseudocode.
https://github.com/expertcoderz/fun-with-pseudocode
Last synced: 10 months ago
JSON representation
Python utility for parsing CIE AS & A Level-style pseudocode.
- Host: GitHub
- URL: https://github.com/expertcoderz/fun-with-pseudocode
- Owner: Expertcoderz
- License: agpl-3.0
- Created: 2025-04-26T09:51:50.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-05-07T15:49:12.000Z (11 months ago)
- Last Synced: 2025-05-19T01:13:04.309Z (11 months ago)
- Language: Python
- Size: 58.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fun with Pseudocode
Fun with Pseudocode (or `fwp` for short) is a Python utility to parse
"pseudocode" with syntax based on the Cambridge International A & AS Level
Computer Science [Pseudocode Guide for Teachers](https://www.cambridgeinternational.org/Images/697401-2026-pseudocode-guide-for-teachers.pdf).
This project is a fun exercise. It has no intended practical application. It is
also largely unfinished as of now; not all language features have been
implemented or rigorously tested.
## Usage
```sh
$ python -m fwp --help
```
Requires [Lark](https://github.com/lark-parser/lark) to be installed.
Sample pseudocode programs are provided under the `examples` directory.
## The Process
```txt
+--------------+
| EBNF grammar |
+---|----------+
|
+-------------------+ V +------------+ +----+
| Pseudocode source | ---> | Parse tree | --> | IR | ---> ???
+-------------------+ +------------+ +----+
```
1. **Parsing:** the pseudocode source is first run through the parser to
generate a parse tree. [Lark](https://github.com/lark-parser/lark) is used as
the parser generator, and supplied with the EBNF definition of the pseudocode
language (see `fwp/grammar.lark`). The parser performs lexical analysis
(tokenization) and parsing of the pseudocode source, resulting in a parse
tree. Pass the `-P` option to stop at the parsing stage and view the parse
tree.
2. **Intermediate representation (IR) generation:** the IR is implemented as a
hierarchy of Python objects that comprise a tree structure. It is essentially
a parse tree with some semantics added. However, unlike most other IRs there
is no actual text or binary format for which to store such generated IR,
which exists purely as a Python object. To view the IR as a nicely formatted
S-expression, pass the `-S` option.
3. Now all that's left is to do something useful with the IR. This has yet to be
decided upon.
## License
Fun with Pseudocode is licensed under the AGPLv3. See the LICENSE file for more
information.