Package: dudocode
DudocodeThis 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.The pseudocode syntax is specified inthis PDF(downloaded from theofficial CIE IGCSE website).Dudocode supports all of these documented features!Yep, finally filestream operations too following the v0.6 update.Note that the arrow assignment operator (←) can be replaced with<-for easier typing.Dudocode's transpilation workflow is heavily reliant ontrilobyte. 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'll 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.Contents:DudocodeGetting startedDemosDocumentationPseudocode Quick ReferenceGetting startedDudocode is built on top of Python. If you do not have Python, please download and install ithere.Add your Python installation to PATH.Dudocode is available as aPyPI package. To download and install the latest version of Dudocode, runpipinstalldudocodeInteract with thedudoCLI in terminal. Seedocumentationfor help, or try out the examples indemos.Notepad++ IntegrationI have created a User Defined Language file to aid you in coding with pseudocode. Downloadnotepadpp_udl_dudocode.xml, and import it into Notepad viaLanguage -> Define your language... -> Import. This language file supports syntax highlighting, code folding, and auto-completion for all of Dudocode's features. It's recognised file endings are.ddoand.notcode.DemosTry running the following pseudocode programs if you're not sure how to get started!In all the examples below, any output line that starts with an>denotes where user input is required.Hello WorldPseudocode:OUTPUT"Hello World!"Output:HelloWorld!Triangular StarsPseudocode:INPUTNumRowsFORi←0TONumRowsFORj←0TOiOUTPUT'*'NEXTjOUTPUT'\n'NEXTiOutput:>10*
**
***
****
*****
******
*******
********
*********
**********
***********ArithmeticPseudocode:OUTPUT"Enter a number: "INPUTNumAOUTPUT"Enter another number: "INPUTNumBNumA<-REAL(NumA)NumB<-REAL(NumB)OUTPUT"Enter operator: "INPUTOperator// Awesome CASE statements are supported by Dudocode!CASEOFOperator"add":OUTPUTNumA+NumB"sub":OUTPUTNumA-NumB"mul":OUTPUTNumA*NumB"div":OUTPUTNumA/NumB"mod":OUTPUTMOD(NumA,NumB)OTHERWISEOUTPUT"Unknown operator"ENDCASEOutput:>Enteranumber:14>Enteranothernumber:7>Enteroperator:mod0.0Sieve of EratosthenesPseudocode:INPUTLimitDECLAREIsPrime:ARRAY[2:Limit]OFBOOLEAN// Initialise arrayFORNumber←2TOLimitIsPrime[Number]←TRUENEXTNumberFORNumber←2TOLimitIFIsPrime[Number]=TRUETHEN// Print Number if it is primeOUTPUTNumber," "// Then mark all its multiples as not primeFORMultiple←2TODIV(Limit,Number)IsPrime[Number*Multiple]←FALSENEXTMultipleENDIFNEXTNumberOutput:>1002357111317192329313741434753596167717379838997RecursionPseudocode:FUNCTIONFactorial(Num:INTEGER)RETURNSINTEGERIFNum=0ORNum=1THENRETURN1ELSERETURNNum*Factorial(Num-1)ENDIFENDFUNCTIONINPUTNumberOUTPUTFactorial(Number),"\n"Output:>202432902008176640000File Reading and WritingSuppose you have a file calledinp.txt, and you wanna copy its contents toout.txt:Pseudocode:OPENFILEinp.txtFORREADREADFILEinp.txt,TextCLOSEFILEinp.txtOUTPUT"Text from file: ",Text,"\n"OPENFILEout.txtFORWRITEWRITEFILEout.txt,TextCLOSEFILEout.txtDocumentationdudoDudo is Dudocode's versatile CLI, allowing you to convert and run pseudocode source files. It also supports interactive pseudocode execution.The following commands may be run on the command line:usage: dudo [-h] [-v] {run} ...

Dudocode is a Pseudocode interpreter that transpiles pseudocode to Python.

positional arguments:
  {run}          Dudocode subcommands (use `dudo` without any commands to launch interactive console)
    run          Run pseudocode source files with Dudocode

optional arguments:
  -h, --help     show this help message and exit
  -v, --version  show program's version number and exitTo launch the interactive console, simply rundudo.dudo runThedudo runsubcommand deals with transpiling and running pseudocode source files:usage: dudo run [-h] [-d] [-p] [-s] [-o OUT] [-q] [-v] path

positional arguments:
  path               path to Dudocode source code

optional arguments:
  -h, --help         show this help message and exit
  -d, --dudo         print the source Dudocode
  -p, --py           print the transpiled Python program
  -s, --save         save the transpiled Python program
  -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)
  -q, --quiet        does not run the transpiled Python program
  -v, --verbose      print stupid comments while transpilingQuick ReferenceThis section contains snippets of common pseudocode patterns, taken from the CIE IGCSE specification.Data typesINTEGERREALCHARSTRINGBOOLEANArray Declaration1DDECLARE<identifier>:ARRAY[<l1>:<u1>,<l2>:<u2>]OF<datatype>2DDECLARE<identifier>:ARRAY[<l1>:<u1>,<l2>:<u2>]OF<datatype>nDDECLARE<identifier>:ARRAY[<l1>:<u1>,<l2>:<u2>,...,<ln>:<un>]OF<datatype>Control FlowNote the use of 2 spaces instead of 4 in some of these indentations.Simple IF statementIF<condition>THEN<statements>ENDIFIF-ELSE statementIF<condition>THEN<statements>ELSE<statements>ENDIFCASE statement (without default)CASEOF<identifier><value1>:<statement><value2>:<statement>...ENDCASECASE statement (with default)CASEOF<identifier><value1>:<statement><value2>:<statement>...OTHERWISE<statement>ENDCASELoopsFOR loopFOR<identifier>←<value1>TO<value2>STEP<increment><statements>NEXT<identifier>REPEAT-UNTIL loopREPEAT<Statements>UNTIL<condition>WHILE loopWHILE<condition>DO<statements>ENDWHILEProcedure DeclarationWithout argumentsPROCEDURE<identifier><statements>ENDPROCEDUREWith argumentsPROCEDURE<identifier>(<param1>:<datatype>,<param2>:<datatype>...)<statements>ENDPROCEDUREFunction DeclarationFUNCTION<identifier>(<param1>:<datatype>,<param2>:<datatype>...)RETURNS<datatype><statements>ENDFUNCTIONFilestream OperationsOPENFILE<filename>FORREADREADFILE<filename>,<variable>OPENFILE<filename>FORWRITEWRITEFILE<filename>,<variable>CLOSEFILE<filename>