{"id":21078527,"url":"https://github.com/criezy/script_cmd","last_synced_at":"2026-03-09T07:31:34.874Z","repository":{"id":7634037,"uuid":"8993811","full_name":"criezy/script_cmd","owner":"criezy","description":"A command line C-like script interpreter","archived":false,"fork":false,"pushed_at":"2021-11-29T20:57:26.000Z","size":95,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T08:43:58.172Z","etag":null,"topics":["c-plus-plus","equation-calculator","parser"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/criezy.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-24T21:46:36.000Z","updated_at":"2024-10-26T22:15:38.000Z","dependencies_parsed_at":"2022-09-08T12:01:45.057Z","dependency_job_id":null,"html_url":"https://github.com/criezy/script_cmd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/criezy/script_cmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criezy%2Fscript_cmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criezy%2Fscript_cmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criezy%2Fscript_cmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criezy%2Fscript_cmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/criezy","download_url":"https://codeload.github.com/criezy/script_cmd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criezy%2Fscript_cmd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30287425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c-plus-plus","equation-calculator","parser"],"created_at":"2024-11-19T19:40:49.800Z","updated_at":"2026-03-09T07:31:34.857Z","avatar_url":"https://github.com/criezy.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nThis program interprets C-like mathematical expressions and prints the result.\n\nIn Script mode, you can specify a multi-line script that contains variables,\nthen set the variable values and run the script multiple times (changing the\nvariable values between each run if you want to.\n\nIn simple mode, each line you type is interpreted as a simple equation and the\nresult is printed when you press return.\n\nThe program was written during free time in my universities days (in 2000) and\nwas cleaned in 2013 when I decided to share it. If you somehow stumble onto\nthis code and find it useful, or merely interesting, please drop me an email\nto let me know (although I doubt it will ever happen, if I receive even only\none email that will make my day :) ). Also fill free to open pull requests\non github.com/criezy/ for any improvement you make.\n\n\n1) Usage and options\n2) Simple Mode\n3) Script Mode\n4) Compilation and contributions\n\n\n1) Usage and options\n--------------------\nUsage: script [options]\n\nWhen no option is given it starts the program in interactive script mode.\n\nOptions can be:\\n\");\n  --help              Print this help.\n  --simple-mode       Interactive simple equation mode.\n  -e                  Same as --simple-mode\n  --script='command'  Start in script mode and set the script to the given one.\n  -s 'command'        Same as --script='command'\n  --file=path         Start in script mode and load the script from the given file.\n  -f path             Same as --file=path\n\n2) Simple Mode\n--------------\nEach line you type is interpreted as a mathematical expression and the result is\nprinted on the next line. Type 'help' to get a list of recognised constant names,\nfunctions and operators. Type 'exit' or 'quit' to quit the program.\n\nExample of expression syntax:\n$ ./script -e\nStarting simple equation mode.\nType 'help' to get some help.\n\u003e (3 + 12) / 5\n3\n\u003e 3 + 12 / 5\n5.4\n\u003e if (cos(3 + 12 / 5) \u003c 0, ceil(fabs(cos(3 + 12 / 5))), sqrt(3 + 12 / 5))\n2.32379000772\n\u003e cos(3 + 12 / 5) \n0.634692875943\n\u003e sqrt(3 + 12 / 5)\n2.32379000772\n\nYou can also use variables. Use 'define VAR' to define a variable and 'undefine VAR'\nto undefine a previously defined variable. You can also use 'variables' to list the\ndefined variables.\nFor example:\n$ ./script -e\nStarting simple equation mode.\nType 'help' to get some help.\n\u003e define a\n\u003e define b cos(PI / 3)\n0.5\n\u003e variables\nThere are 2 variables defined:\na = 0.000000\nb = 0.500000\n\u003e a + b\n0.5\n\u003e undefine a\n\u003e variables\nThere is 1 variable defined:\nb = 0.500000\n\nIf you enabled the tree debug feature at compile time, you can use the\ntree \u003cequation\u003e command to print the parser tree for the given equation.\nFor example:\n$ ./script -e\nStarting simple equation mode.\nType 'help' to get some help.\n\u003e tree (3 + 12) / 5\nDivideOperator\n  PlusOperator\n    Constant: 3.000000\n    Constant: 12.000000\n  Constant: 5.000000\n3\n\n\n3) Script Mode\n--------------\nIn script mode, you enter a multi-line script that may contain variables. Then\nyou can set the variable values and run the script multiple times. To define\nthe script you can:\n  - give it to the program on the command line (--script= option) \n  - give it to the program as a text file (--file= option)\n  - type it after starting the program\n\nTo type the script in the program, type 'START'. Then everything you type until\nyou type 'END' will define the script. If you start typing a script it will\nthrow away any script that might already have been defined (either passed to\nthe command line or previously typed in the program).\n\nWhen not typing the script, the following commands are recognised:\n  - 'start [name]'  Start defining the script with the given name.\n  - 'help [topic]'  Print a help message.\n  - 'scripts'       List defined scripts.\n  - 'clear [name]'  Undefined the script with the given name.\n  - 'run [name]'    Run the script previously defined with the given name.\n  - 'run [name] \u003e file' Run the script previously defined with the given name and redirect output\n                        to file.\n  - 'script [name]' Print the script previously defined with the given name.\n  - 'script [name] \u003c file' Initialise the script with the given name to the content of the given file.\n  - 'script [name] \u003e file' Save the script previously defined with the given name to the given file.\n  - 'variables'     Print the list of variables in the previously defined script.\n  - 'quit'          Quit the program ('exit' also works).\n  - Everything else will be interpreted as a one line script and run immediately.\n    This is usually used to set variable values (e.g. 'foo = 12.5').\n\nFor all the commands above that take a script name, the name is optional. Using\nnames allows to defined several scripts that will coexist.\n\nConsider the following script.\n$ ./script\nStarting script mode.\nType 'help' to get some help.\n\u003e start\n  if (z == 0) {\n      x = y;\n  } else {\n      x = y / (2. * z);\n  }\n  print(x);\n  print(y);\n  print(z);\n  z = z + 1;\n  end\n\u003e \n\nYou can then set the initial value for the variables y and z:\n\u003e y = 48;\n\u003e z = 0;\n\nAnd then run the script several times:\n\u003e run\nx = 48\ny = 48\nz = 0\n\u003e run\nx = 24\ny = 48\nz = 1\n\n\nYou can also use external text file for scripts and variable values. External\nvariable files contain the variable name on the first line and values on\nfollowing lines. The script is then run once for each line. And you can\nspecify external files to which print() outputs are written.\n\n\u003e script init \u003c examples/elastic_init.txt\n\u003e script compute \u003c examples/elastic_compute.txt\n\u003e script stats \u003c examples/elastic_stats.txt\n\u003e run init \u003e result.txt\n\u003e run compute \u003c examples/elastic_data.txt \u003e result.txt\n\u003e run stats\nTotal number of samples: 12\nNumber of invalid samples: 1\n\n\nYou can use the 'tree' command to print the parser tree for a script. This is\nonly available if you enabled the tree debugging feature when compiling.\n\n$ ./script\nStarting script mode.\nType 'help' to get some help.\n\u003e start\nif (z == 0) {\n  x = y;\n} else {\n  x = y / (2. * z);\n}\nprint(x);\nz = z + 1;\nend\n\u003e tree\nScript\n  If\n    Condition\n      Is equal\n        Variable: z\n        Constant: 0.000000\n    Then\n      Assign\n        Variable: x\n        Variable: y\n    Else\n      Assign\n        Variable: x\n        Divide\n          Variable: y\n          Multiply\n            Constant: 2.000000\n            Variable: z\n  Print\n    Variable: x\n  Assign\n    Variable: z\n    Add\n      Variable: z\n      Constant: 1.000000\n\nYou can also provide a script name for a previously defined script:\n\u003e start foo\n[...]\nend\n\u003e tree foo\n\nAnd you can redirect the output to a file:\n\u003e tree foo \u003e foo_tree.txt\n\n\n4) Compilation and contributions\n--------------------------------\nCompilation should be straightforward: type 'make' and that's it.\n\nYou can compile with support for the GNU deadline library for improved\ntext inout (including history). To do so you need to edit two lines in the\nMakefile.\n\nYou can also enable some debugging features by editing the corresponding\nline in the Makefile.\n\nThe source code was originally written on SunOS, IRIX and HP-UX. I have not\ntested compilation on those systems when cleaning the code as I don't have\naccess to those anymore. I can however confirm it compiles and works on\nDebian and Mac OS X. And I don't see why it would not work on any other\nLinux and Unix systems.\n\nPart of the code is documented as I was experimenting with doxygen, but\noverall there is little comments or documentation (now you have been warned\nfeel free to look at the code anyway).\n\nAnd if you do any modifications you deem worthwhile, please open a pull\nrequest on github.com/criezy/ where the code is hosted.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriezy%2Fscript_cmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcriezy%2Fscript_cmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriezy%2Fscript_cmd/lists"}