{"id":13796840,"url":"https://github.com/pseudo-lang/pseudo","last_synced_at":"2025-05-13T00:31:10.621Z","repository":{"id":47730218,"uuid":"53286541","full_name":"pseudo-lang/pseudo","owner":"pseudo-lang","description":"transpile algorithms/libs to idiomatic JS, Go, C#, Ruby ","archived":false,"fork":false,"pushed_at":"2021-03-25T22:50:42.000Z","size":387,"stargazers_count":685,"open_issues_count":8,"forks_count":43,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-09T22:46:40.617Z","etag":null,"topics":["pseudo","python-compiler","translation","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pseudo-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-03-07T01:30:34.000Z","updated_at":"2025-04-22T08:51:00.000Z","dependencies_parsed_at":"2022-08-24T13:37:33.324Z","dependency_job_id":null,"html_url":"https://github.com/pseudo-lang/pseudo","commit_stats":null,"previous_names":["alehander42/pseudo"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudo-lang%2Fpseudo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudo-lang%2Fpseudo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudo-lang%2Fpseudo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudo-lang%2Fpseudo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pseudo-lang","download_url":"https://codeload.github.com/pseudo-lang/pseudo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253336892,"owners_count":21892796,"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":["pseudo","python-compiler","translation","transpiler"],"created_at":"2024-08-03T23:01:16.363Z","updated_at":"2025-05-13T00:31:10.028Z","avatar_url":"https://github.com/pseudo-lang.png","language":"Python","readme":"[![Build Status](https://travis-ci.org/alehander42/pseudo.svg?branch=master)](https://travis-ci.org/alehander42/pseudo)\n[![codecov.io](https://codecov.io/github/alehander42/pseudo/coverage.svg?branch=master)](https://codecov.io/github/alehander42/pseudo?branch=master)\n[![MIT License](http://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n# pseudo\n\n[![Join the chat at https://gitter.im/alehander42/pseudo](https://badges.gitter.im/alehander42/pseudo.svg)](https://gitter.im/alehander42/pseudo?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nPseudo takes an algorithm / a simple program and generates idiomatic code for it in Python, JavaScript, C#, Go and Ruby.\n\nPseudo achieves that with translation on two layers: it uses the target language syntax and it can express standard library methods/api of language X using language Y's native standard library\n\n# git history\n\nSorry: I lied, remaking the git history in a way that it appears most of the work is after 1 march: I was finishing my work in a company in february and I wanted to hide the fact i've worked on pseudo in that time: I actually started more active work somewhere around 20-th february if I remember correctly, somewhere around the second half of february. I am not sure if i have that original git history anymore: sorry to Clevertech(the company)/any observers, this was a really ugly thing to do.\n\n# concept\n\nPseudo consumes \"Pseudo AST\" which corresponds to a very clear, statically typed and somehow limited subset of a language:\n\n  * basic types and collections and standard library methods for them\n  \n  * integer, float, string, boolean\n  * lists\n  * dicts\n  * sets\n  * tuples/structs(fixed length heterogeneous lists)\n  * fixed size arrays\n  * regular expressions\n\n  * functions with normal parameters (no default/keyword/vararg parameters)\n  * classes \n    * single inheritance\n    * polymorphism\n    * no dynamic instance variables\n    * basically a constructor + a collection of instance methods, no fancy metaprogramming etc supported\n\n  * exception-based error handling with support for custom exceptions\n  (target languages support return-based error handling too)\n  \n  * I/O: print/input, file read/write, command arg handling, system and subprocess commands\n\n  * iteration (for-in-range / for-each / iterating over several collections / while)\n  * conditionals (if / else if / else)\n  * standard math/logical operations\n\n  * a lot more in future\n\n[standard library reference](docs/library_reference.md)\n\n\nThose constructs and entities have almost the same behavior and very same-spirited api in a lot of the languages which Pseudo would support.\n\n## examples\n\nEach example contains a detailed README and working translations to Python, JS, Ruby, Go and C#, generated by Pseudo\n\n[fibonacci](examples/fib)\n\n[a football results processing command line tool](examples/football)\n\n[a verbal expressions-like library ported to all the target languages](examples/verbal_expressions)\n\n### architecture\n\n```ruby\nPSEUDO AST:\n   NORMAL CODE     PSEUDO STANDARD LIBRARY INVOCATIONS     \n      ||                    ||\n      ||                    ||\n      ||              API TRANSLATOR\n      ||                    ||\n      ||                    ||\n      ||                    \\/\n      ||              IDIOMATIC TARGET LANGUAGE \n      ||              STANDARD LIBRARY INVOCATIONS        \n      ||                    ||     \n      \\/                    \\/\n  STANDARD OR LANGUAGE-SPECIFIC MIDDLEWARES\n              e.g.\n    name camel_case/snake_case middleware\n    convert-tuples-to-classes middleware\n    convert-exception-based errors handling\n    to return-based error handling middleware\n              etc\n\n              ||\n              ||\n              ||\n              ||\n  TARGET LANGUAGE CODE GENERATOR\n\n      defined with a dsl aware\n      that handles formatting\n         automatically\n              ||\n              ||\n              ||\n              \\/\n\n      Python / C# / Go / JS / Ruby\n```\n\n\n## use cases\n\n  * generate code for the same task/algorithm in different languages (parser generators etc)\n  * port a library/codebase\n  * develop core logic in one language and use it in other language codebases\n  * write a compiler/dsl\n  * bootstrap a codebase in another language / generate equivalent test suites in different languages\n  * translate/support some algorithms in different languages\n  * translate/support some text/data processing/command tool in different languages\n\n## installation\n\n```bash\npip install pseudo #only python 3 supported\n\n# probably you'd like to try the python-to-pseudo-to-js/go/etc compiler\npip install pseudo-python\n```\n\n- [usage](#usage)\n- [why?](#why)\n- [language support](#language-support)\n- [compilers targetting pseudo](#compilers-targetting-pseudo)\n- [implementation](#implementation)\n- [roadmap](#roadmap)\n- [target language specific docs](#target-language-specific-docs)\n- [Pseudo and Haxe?](#pseudo-and-haxe)\n- [the name?](#the-name)\n\n\n## usage\n\nyou can directly generate pseudo ast from Python using Pseudo-Python\n```bash\npseudo-python a.py # generates a.pseudo.yaml\n```\nand then translate the ast\n```bash\npseudo a.pseudo.yaml go # or ruby / js / csharp / py / cpp\n```\nor you can directly translate from python to another language\n\n```bash\npseudo-python a.py b.rb # or c.cs\n```\n\n\n\n```python\npseudo.generate(pseudo_ast, language) # pseudo_ast is a plain dict or a pseudo Node-based tree\n```\n\n```python\npseudo.generate_from_yaml(pseudo_ast, language) # pseudo_ast is yaml-encoded pseudo ast\n```\n\nFor quick experiments it's easier to use `generate_main`\n\n```python\nfrom pseudo import * # ok for a repl\n\nprint(generate_main([\n  assignment(\n    local('a', 'Int'),\n    call(local('g'), [to_node(0), to_node('')], 'Int'))], 'rb'))\n\na = g(0, '')\n```\n\nIn the future Pseudo can add a lisp-like dsl for fast manual creation of ast nodes, but currently it's more useful for its main goal: consuming automatically generated pseudo ast and then transpiling it to the target languages.\n\n\n## why?\n\nSupporting full-blown Ruby to Python/Javascript to C++ auto translation is hard.\n\nHowever often we need to just express an algorithm, a self-contained core of a library, a simple command line tool and the act of manual porting to another languages feels somehow .. primitive. \n\nOften that code is(or can be) expressed in very similar way, with\nsimilar constructs and basic types and data structures. On that level a lot of languages are very similar and the only real difference is syntax and methods api. That's a feasible task for automatic translation and actually the existance of `pseudo` is to fullfill the needs of several other existing projects/ideas.\n\nAnother powerful thing about Pseudo is its standard library.\nIt can accumulate a serious number of methods/idioms and it can act like e.g. a truly cross-platform, target-language-aware equivalent of lodash\n\nPseudo is still young (it's basically less than two weeks old), \nbut it already has a base on which it can improve really quickly\n(adding support for another language is basically just a matter of 3-4 hours currently)\n\n## Language support\n\nUsing pseudo's DSL it's easy to add support for a new language, so it's feasible to expect support for most popular languages and even different versions of them (e.g. EcmaScript 6/7, Perl 5/6 Java 7 / 8)\n\n## Compilers targetting pseudo\n\nCurrently [pseudo-python](https://github.com/alehander42/pseudo-python) is usable, and there are plans for `pseudo-ruby` or `pseudo-js`\n\n## Intermediate AST format\n\nThe AST format uses basic data structures available in most languages. The nodes correspond to \ndictionaries with `type` key corresponding to the node type and `field_name` keys corresponding to\nthe node fields, similar to the widely popular `estree` ecmascript format.\n\nPseudo can consume ast either serialized in `.pseudo.yaml` files or directly as\ndictionary objects through it's `pseudo.generate(ast, output_lang)` API\n\n## Implementation\n\n\n\nThe implementation goal is to make the definitions of new supported languages  really clear and simple. \n\nIf you dive in, you'll find out\na lot of the code/api transformations are defined using a declarative dsl with rare ocassions \nof edge case handling helpers. \n\nThat has a lot of advantages:\n\n* Less bugs: the core transformation code is really generalized, it's reused as a dsl and its results are well tested\n\n* Easy to comprehend: it almost looks like a config file\n\n* Easy to add support for other languages: I was planning to support just python and c# in the initial version but it is so easy to add support for a language similar to the current supported ones, that I\nadded support for 4 more.\n\n* Easy to test: there is a simple test dsl too which helps all \nlanguage tests to share input examples [like that](tests/test_ruby.py)\n\nHowever language translation is related to a lot of details and\na lot of little gotchas, tuning and refining some of them took days. Pseudo uses different abstractions to streamline the process and to reuse logic across languages.\n\n```ruby\nPSEUDO AST:\n   NORMAL CODE     PSEUDO STANDARD LIBRARY INVOCATIONS     \n      ||                    ||\n      ||                    ||\n      ||              API TRANSLATOR\n      ||                    ||\n      ||                    ||\n      ||                    \\/\n      ||              IDIOMATIC TARGET LANGUAGE \n      ||              STANDARD LIBRARY INVOCATIONS        \n      ||                    ||     \n      \\/                    \\/\n  STANDARD OR LANGUAGE-SPECIFIC MIDDLEWARES\n              e.g.\n    name camel_case/snake_case middleware\n    convert-tuples-to-classes middleware\n    convert-exception-based errors handling\n    to return-based error handling middleware\n              etc\n\n              ||\n              ||\n              ||\n              ||\n  TARGET LANGUAGE CODE GENERATOR\n\n      defined with a dsl aware\n      that handles formatting\n         automatically\n              ||\n              ||\n              ||\n              \\/\n\n            OUTPUT\n```\n\n\n\n## Roadmap\n\nPseudo has undergone some changes through the last year in my local repo, the new release somewhere in the next months should contain some of this roadmap.\n\n[Roadmap](roadmap.md)\n\n## Target language specific docs\n\n* [python](docs/python.md)\n* [c#](docs/csharp.md)\n* [go](docs/go.md)\n* [ruby](docs/ruby.md)\n* [javascript](docs/javascript.md)\n* [c++](docs/cpp.md)\n\n## Pseudo and Haxe\n\nThey might seem comparable at a first glance, but they have completely different goals.\n\nPseudo wants to generate readable code, ideally something that looks like a human wrote it/ported it\n\nPseudo doesn't use a target language runtime, it uses the target language standard library for everything (except for JS, but even there is uses `lodash` which is pretty popular and standard)\n\nPseudo's goal is to help with automated translation for cases\nlike algorithm generation, parser generation, refactoring, porting codebases etc. The fact that you can write compilers targetting Pseudo and receiver translation to many languages for free is just a happy accident\n\n## The name?\n\nwell.\n\npseudo(code)\n\n\n## License\n\nCopyright © 2015 2016 [Alexander Ivanov](https://twitter.com/alehander42)\n\nDistributed under the MIT License.\n","funding_links":[],"categories":["Python","Python Hacks"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudo-lang%2Fpseudo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpseudo-lang%2Fpseudo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudo-lang%2Fpseudo/lists"}