{"id":29048704,"url":"https://github.com/pkopel/pig","last_synced_at":"2025-10-17T14:37:08.729Z","repository":{"id":44735043,"uuid":"285425301","full_name":"PKopel/PiG","owner":"PKopel","description":"Simple interpreted imperative language ","archived":false,"fork":false,"pushed_at":"2025-05-04T12:33:24.000Z","size":428,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-04T13:32:01.996Z","etag":null,"topics":["imperative-programming-language","interpreter"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/PKopel.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-05T23:22:25.000Z","updated_at":"2025-05-04T12:33:26.000Z","dependencies_parsed_at":"2023-12-16T12:42:10.355Z","dependency_job_id":"6c53d09f-94f2-4a6b-ad3a-bb62d10fcac3","html_url":"https://github.com/PKopel/PiG","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/PKopel/PiG","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PKopel%2FPiG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PKopel%2FPiG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PKopel%2FPiG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PKopel%2FPiG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PKopel","download_url":"https://codeload.github.com/PKopel/PiG/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PKopel%2FPiG/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262119782,"owners_count":23261910,"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":["imperative-programming-language","interpreter"],"created_at":"2025-06-26T18:11:36.322Z","updated_at":"2025-10-17T14:37:03.684Z","avatar_url":"https://github.com/PKopel.png","language":"Haskell","readme":"# PiG\n\n![tests](https://github.com/PKopel/PiG/actions/workflows/test.yaml/badge.svg)\n![release](https://github.com/PKopel/PiG/actions/workflows/release.yaml/badge.svg)\n\nInterpreter for a simple language, build with [Alex](https://www.haskell.org/alex/) and [Happy](https://www.haskell.org/happy/).\n\n## Usage  \n\nUse\n\n* `stack exec pig` to start interpreter\n* `stack install` to install `pig` executable on your machine\n\n### Options\n\n* `--version` show version of interpreter\n* `--help`: show options with short description\n* `-l|--load FILE`: start interpreter with `FILE` loaded\n\nCommand line arguments for scripts are stored in a list of strings named `args`. To distinguish script arguments from intepreter's arguments use `--`, for example with command `pig -l script.pig -- help` string `help` will be available in the script as `args(0)`.\n\nPiG interpreter can also be used with shebang with `#!\u003cpath\u003e/\u003cto\u003e/\u003cpig\u003e -l`, see [example](./examples/hello.pig).\n\n## Language\n\nIn PiG, everything is an expression:\n\n* literal values:\n  * `null`\n  * `true`/`false`\n  * numbers (integral and real)\n  * characters like `'a'` and strings like `\"abcd\"`\n  * functions (lambdas) in form `(\u003carg1\u003e,...,\u003cargn\u003e) =\u003e \u003csequence\u003e`. Return value of a function is either the value of its last expression or value explicitly marked with the `return` keyword.\n  * lists in form `[\u003cexpr1\u003e,...,\u003cexprn\u003e]`\n  * dictionaries (maps) in form `[\u003ckey1\u003e: \u003cvalue1\u003e,...,\u003ckeyn\u003e: \u003cvaluen]`\n* assignments: `\u003cname\u003e = \u003cexpr\u003e`, where name consists of alphanumeric characters, `\u003cname\u003e(\u003cnumber\u003e) = \u003cexpr\u003e` to assign value to a specific element of a list, or `\u003cname\u003e(\u003cexpr\u003e) = \u003cexpr\u003e` to add key-value pair to a dictionary. Value of assignment is the value of expression on the right.\n* sequence of expressions, separated and optionally ended by `;`. When sequence is enclosed by braces (`{...}`), it is treated as a single expression (sequences can be nested, like `{ \u003cexpr1\u003e; { \u003cexpr2\u003e; \u003cexpr3\u003e }; }`). Value of a sequence is the value of the last expression in it.\n* while loop: `while \u003cexpr1\u003e : \u003cexpr2\u003e`. Both `\u003cexpr1\u003e` and `\u003cexpr2\u003e` must be a single expressions, but they don't have to be enclosed in braces. `\u003cexpr2\u003e` will be executed as long as `\u003cexpr1\u003e` is a `true`, non-zero number, non-empty list or a non-empty string. Value of a while expression is a list of values of `\u003cexpr2\u003e` (for example value of `x = 3; while x \u003e 0 : x = x - 1` is `[2,1,0]`).\n* if: `if \u003cexpr\u003e : \u003cexpr\u003e elif \u003cexpr\u003e : \u003cexpr\u003e ... else : \u003cexpr\u003e` (`elif` and `else` are optional). Value of \"if\" is the value of expression after ifrst condition evaluated to `true`, non-zero number, non-empty list or a non-empty string, or value of expresion after `else` (`null` if no `else` is specified).\n* a variable name, as in assignment. If the variable is bound to a list, `\u003cname\u003e(\u003cnum1\u003e,...,\u003cnumn\u003e)` syntax can be used to get the value at specified index or a list of them.\n* function application, in form `\u003cname\u003e(\u003carg1\u003e,...,\u003cargn\u003e)`. If the `\u003cname\u003e` is a list, arguments that can be evaluated to numbers will be rounded to integers and treated as zero-based indices, and the return value will be the value associated with that index or a list of values in case of more than one indices (for example a value of `l = [1,2,3]; l(0)` is `1`, value of `l = [1,2,3]; l(0,2)` is `[1,3]`). If the `\u003cname\u003e` is a dictionary, the return value will be the value associated with the argument or a list of values in case of more than one argument (for example a value of `m = [\"a\":1,\"b\":3]; m(\"a\")` is `1`, value of `m = [\"a\":1,\"b\":3]; m(\"a\",\"b\")` is `[1,3]`).\n* expressions with build-in keywords and operators\n\nBuild-in functions provided:\n\n* `print(arg1,...,argn)` prints all its arguments to stdout\n* `read()` reads string from stdin\n* `open(\u003cfile path\u003e[, \u003cmode string\u003e])` opens file and returns its handle\n* `close(\u003chandle\u003e)` closes file\n* `readFile(\u003chandle\u003e)` reads line form file\n* `writeFile(\u003chande\u003e,arg1,...,argn)` writes all its arguments except handle to file\n* `strToNum(arg)` parses number from string\n* `strToList(arg)` turns string to a list of chars\n* `listToStr(arg)` turns a list of chars to string\n* `length(arg)` returns the length of a list, map or string\n* `isNum(arg)` checks if `arg` is a number\n* `isBool(arg)` checks if `arg` is a boolean\n* `isList(arg)` checks if `arg` is a list\n* `isStr(arg)` checks if `arg` is a string\n* `isFun(arg)` checks if `arg` is a function\n* `exit()` closes interpreter\n\nKeyword `load \"\u003cfile name\u003e\"` executes code from other files.\n\nBuild-in operators are:\n\n* `+`, `-`, `*`, `/`, `^` and `%` (modulo) for numbers\n* `-`, `||`, `\u0026\u0026` for booleans\n* `\u003c\u003e`, `-\u003c`, `\u003e-` for lists (`\u003e-` removes and returns first element, `-\u003c` the last one, `\u003c\u003e` concatenates second argument to the end of the first one, works with any type but results always in a list)\n* `\u003e\u003c` for strings (attaches second argument at the end of the firs one, works with any type but results always in a string)\n\nInterpreter also provides four directives:\n\n* `:exit | :e` (or Ctrl+d) to leave the interpreter\n* `:rm \u003cvariable name\u003e` to remove binding of a variable\n* `:clear | :c` to remove all bindings\n* `:help | :h` to display information about directives\n\nSee [examples](https://github.com/PKopel/PiG/tree/master/examples) for more info.\n\n## Author\n\n* **[Paweł Kopel](https://github.com/PKopel)**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkopel%2Fpig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkopel%2Fpig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkopel%2Fpig/lists"}