{"id":24110327,"url":"https://github.com/perceptronv/dudocode","last_synced_at":"2025-05-13T00:35:53.367Z","repository":{"id":57210078,"uuid":"379576991","full_name":"PerceptronV/dudocode","owner":"PerceptronV","description":"A pseudocode-to-Python transpiler based on the format specified in CIE IGCSE (Syllabus 0478)","archived":false,"fork":false,"pushed_at":"2023-10-31T15:50:52.000Z","size":804,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T05:11:14.146Z","etag":null,"topics":["pseudocode","pseudocode-interpreter","transpiler"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/dudocode/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerceptronV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-23T11:16:54.000Z","updated_at":"2024-04-17T09:06:47.000Z","dependencies_parsed_at":"2022-09-01T08:10:36.323Z","dependency_job_id":null,"html_url":"https://github.com/PerceptronV/dudocode","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerceptronV%2Fdudocode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerceptronV%2Fdudocode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerceptronV%2Fdudocode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerceptronV%2Fdudocode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerceptronV","download_url":"https://codeload.github.com/PerceptronV/dudocode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850542,"owners_count":21973662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pseudocode","pseudocode-interpreter","transpiler"],"created_at":"2025-01-11T01:14:47.053Z","updated_at":"2025-05-13T00:35:53.344Z","avatar_url":"https://github.com/PerceptronV.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dudocode\nThis repository contains the source code for Dudocode, a pseudocode-to-Python transpiler based on the format specified in CIE IGCSE (Syllabus 0478). It allows you to run pseudocode source files, as well as executing pseudocode interactively in the console.\n\nThe pseudocode syntax is specified in [this PDF](./pseudocode_specification.pdf) (downloaded from the [official CIE IGCSE website](https://www.cambridgeinternational.org/programmes-and-qualifications/cambridge-igcse-computer-science-0478/)). **Dudocode supports all of these documented features!** Yep, finally filestream operations too, following the v0.6 update.\n\nNote that the arrow assignment operator (`←`) can be replaced with `\u003c-` for easier typing.\n\nDudocode's transpilation workflow is heavily reliant on [trilobyte](https://github.com/PerceptronV/trilobyte). This is a custom text-pattern parsing engine which I built primarily for this project and for processing code. Nevertheless, it has a very general syntax and has a wide range of potential use cases. I decided to build Trilobyte not least because I was bored of Regex (I've seen enough transpiler projects out there that use this), but also because I thought it would be fun (and it was!). Trilobyte ended up using a custom 'keypoints'-based algorithm which I devised. There are still some bugs with Trilobyte, but all of its features used in Dudocode seem to be stable.\n\n**Contents**:\n* [Dudocode](#dudocode)\n    * [Getting started](#getting-started)\n    * [Demos](#demos)\n    * [Documentation](#documentation)\n    * [Pseudocode Quick Reference](#quick-reference)\n\n## Getting started\n\n1. Dudocode is built on top of Python. If you do not have Python, please download and install it [here](https://www.python.org/downloads/).\n\n2. Add your Python installation to PATH.\n\n3. Dudocode is available as a [PyPI package](https://pypi.org/project/dudocode/). To download and install the latest version of Dudocode, run\n    ```shell\n    pip install dudocode\n    ```\n    \n4. Interact with the `dudo` CLI in terminal. See [documentation](#documentation) for help, or try out the examples in [demos](#demos).\n\n### Notepad++ Integration\n\nI have created a User Defined Language file to aid you in coding with pseudocode. Download [`notepadpp_udl_dudocode.xml`](./notepadpp_udl_dudocode.xml), and import it into Notepad via `Language -\u003e Define your language... -\u003e Import`. This language file supports syntax highlighting, code folding, and auto-completion for all of Dudocode's features. Its recognised file endings are `.ddo` and `.notcode`.\n\n## Demos\n\nTry running the following pseudocode programs if you're not sure how to get started!\n\nIn all the examples below, any output line that starts with an `\u003e` denotes where user input is required.\n\n### Hello World\nPseudocode:\n```c++\nOUTPUT \"Hello World!\"\n```\n\nOutput:\n```shell\nHello World!\n```\n\n### Triangular Stars\nPseudocode:\n```c++\nINPUT NumRows\nFOR i ← 0 TO NumRows\n    FOR j ← 0 TO i\n        OUTPUT '*'\n    NEXT j\n    OUTPUT '\\n'\nNEXT i\n```\nOutput:\n```shell\n\u003e 10\n*\n**\n***\n****\n*****\n******\n*******\n********\n*********\n**********\n***********\n```\n\n### Arithmetic\nPseudocode:\n```c++\nOUTPUT \"Enter a number: \"\nINPUT NumA\n\nOUTPUT \"Enter another number: \"\nINPUT NumB\n\nNumA \u003c- REAL(NumA)\nNumB \u003c- REAL(NumB)\n\nOUTPUT \"Enter operator: \"\nINPUT Operator\n\n// Awesome CASE statements are supported by Dudocode!\nCASE OF Operator\n  \"add\": OUTPUT NumA + NumB\n  \"sub\": OUTPUT NumA - NumB\n  \"mul\": OUTPUT NumA * NumB\n  \"div\": OUTPUT NumA / NumB\n  \"mod\": OUTPUT MOD(NumA, NumB)\n  OTHERWISE OUTPUT \"Unknown operator\"\nENDCASE\n```\n\nOutput:\n```shell\n\u003e Enter a number: 14\n\u003e Enter another number: 7\n\u003e Enter operator: mod\n0.0\n```\n\n### Sieve of Eratosthenes\nPseudocode:\n```c++\nINPUT Limit\n\nDECLARE IsPrime : ARRAY[2:Limit] OF BOOLEAN\n\n// Initialise array\nFOR Number ← 2 TO Limit\n    IsPrime[Number] ← TRUE\nNEXT Number\n\nFOR Number ← 2 TO Limit\n    IF IsPrime[Number] = TRUE\n      THEN\n        // Print Number if it is prime\n        OUTPUT Number, \" \"\n        \n        // Then mark all its multiples as not prime\n        FOR Multiple ← 2 TO DIV(Limit, Number)\n            IsPrime[Number * Multiple] ← FALSE\n        NEXT Multiple\n    ENDIF\nNEXT Number\n```\n\nOutput:\n```shell\n\u003e 100\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 \n```\n\n### Recursion\nPseudocode:\n```c++\nFUNCTION Factorial(Num:INTEGER) RETURNS INTEGER\n    IF Num = 0 OR Num = 1\n      THEN\n        RETURN 1\n      ELSE\n        RETURN Num * Factorial(Num - 1)\n    ENDIF\nENDFUNCTION\n\nINPUT Number\n\nOUTPUT Factorial(Number), \"\\n\"\n```\n\nOutput:\n```shell\n\u003e 20\n2432902008176640000\n```\n\n\u003c!--\n### Boilerplate\nPseudocode:\n```c++\n\n```\n\nOutput:\n```shell\n\n```\n--\u003e\n\n### File Reading and Writing\n\nSuppose you have a file called `inp.txt`, and you wanna copy its contents to `out.txt`:\n\nPseudocode:\n```c++\nOPENFILE inp.txt FOR READ\nREADFILE inp.txt, Text\nCLOSEFILE inp.txt\n\nOUTPUT \"Text from file: \", Text, \"\\n\"\n\nOPENFILE out.txt FOR WRITE\nWRITEFILE out.txt, Text\nCLOSEFILE out.txt\n```\n\n----------\n\n## Documentation\n\n### `dudo`\nDudo is Dudocode's versatile CLI, allowing you to convert and run pseudocode source files. It also supports interactive pseudocode execution.\n\nThe following commands may be run on the command line:\n```\nusage: dudo [-h] [-v] {run} ...\n\nDudocode is a Pseudocode interpreter that transpiles pseudocode to Python.\n\npositional arguments:\n  {run}          Dudocode subcommands (use `dudo` without any commands to launch interactive console)\n    run          Run pseudocode source files with Dudocode\n\noptional arguments:\n  -h, --help     show this help message and exit\n  -v, --version  show program's version number and exit\n```\n\nTo launch the interactive console, simply run `dudo`.\n\n### `dudo run`\nThe `dudo run` subcommand deals with transpiling and running pseudocode source files:\n```\nusage: dudo run [-h] [-d] [-p] [-s] [-o OUT] [-q] [-v] path\n\npositional arguments:\n  path               path to Dudocode source code\n\noptional arguments:\n  -h, --help         show this help message and exit\n  -d, --dudo         print the source Dudocode\n  -p, --py           print the transpiled Python program\n  -s, --save         save the transpiled Python program\n  -o OUT, --out OUT  path to saved Python program when flag `--save` is passed (if not specified, this defaults to that of the input file, but with `.py` as file extension)\n  -q, --quiet        does not run the transpiled Python program\n  -v, --verbose      print stupid comments while transpiling\n```\n\n## Quick Reference\n\nThis section contains snippets of common pseudocode patterns, taken from the CIE IGCSE specification.\n\n### Data types\n* `INTEGER`\n* `REAL`\n* `CHAR`\n* `STRING`\n* `BOOLEAN`\n\n### Array Declaration\n1D\n```c++\nDECLARE \u003cidentifier\u003e : ARRAY[\u003cl1\u003e:\u003cu1\u003e, \u003cl2\u003e:\u003cu2\u003e] OF \u003cdata type\u003e\n```\n\n2D\n```c++\nDECLARE \u003cidentifier\u003e : ARRAY[\u003cl1\u003e:\u003cu1\u003e, \u003cl2\u003e:\u003cu2\u003e] OF \u003cdata type\u003e\n```\n\n*n*D\n```c++\nDECLARE \u003cidentifier\u003e : ARRAY[\u003cl1\u003e:\u003cu1\u003e, \u003cl2\u003e:\u003cu2\u003e, ..., \u003cln\u003e:\u003cun\u003e] OF \u003cdata type\u003e\n```\n\n### Control Flow\n\n_Note the use of 2 spaces instead of 4 in some of these indentations._\n\nSimple IF statement\n```c++\nIF \u003ccondition\u003e\n  THEN\n    \u003cstatements\u003e\nENDIF\n```\n\nIF-ELSE statement\n```c++\nIF \u003ccondition\u003e\n  THEN\n    \u003cstatements\u003e\n  ELSE\n    \u003cstatements\u003e\nENDIF\n```\n\nCASE statement (without default)\n```c++\nCASE OF \u003cidentifier\u003e\n    \u003cvalue 1\u003e : \u003cstatement\u003e\n    \u003cvalue 2\u003e : \u003cstatement\u003e\n    ...\nENDCASE\n```\n\nCASE statement (with default)\n```c++\nCASE OF \u003cidentifier\u003e\n  \u003cvalue 1\u003e : \u003cstatement\u003e\n  \u003cvalue 2\u003e : \u003cstatement\u003e\n  ...\n  OTHERWISE \u003cstatement\u003e\nENDCASE\n```\n\n### Loops\nFOR loop\n```c++\nFOR \u003cidentifier\u003e ← \u003cvalue1\u003e TO \u003cvalue2\u003e STEP \u003cincrement\u003e\n    \u003cstatements\u003e\nNEXT \u003cidentifier\u003e\n```\n\nREPEAT-UNTIL loop\n```c++\nREPEAT\n    \u003cStatements\u003e\nUNTIL \u003ccondition\u003e\n```\n\nWHILE loop\n```c++\nWHILE \u003ccondition\u003e DO\n    \u003cstatements\u003e\nENDWHILE\n```\n\n### Procedure Declaration\nWithout arguments\n```c++\nPROCEDURE \u003cidentifier\u003e\n    \u003cstatements\u003e\nENDPROCEDURE\n```\n\nWith arguments\n```c++\nPROCEDURE \u003cidentifier\u003e(\u003cparam1\u003e:\u003cdatatype\u003e, \u003cparam2\u003e:\u003cdatatype\u003e...)\n    \u003cstatements\u003e\nENDPROCEDURE\n```\n\n### Function Declaration\n```c++\nFUNCTION \u003cidentifier\u003e(\u003cparam1\u003e:\u003cdatatype\u003e, \u003cparam2\u003e:\u003cdatatype\u003e...) RETURNS \u003cdata type\u003e\n    \u003cstatements\u003e\nENDFUNCTION\n```\n\n### Filestream Operations\n```c++\nOPENFILE \u003cfilename\u003e FOR READ\nREADFILE \u003cfilename\u003e, \u003cvariable\u003e\n\nOPENFILE \u003cfilename\u003e FOR WRITE\nWRITEFILE \u003cfilename\u003e, \u003cvariable\u003e\n\nCLOSEFILE \u003cfilename\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperceptronv%2Fdudocode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperceptronv%2Fdudocode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperceptronv%2Fdudocode/lists"}