{"id":22472613,"url":"https://github.com/jcarrano/expr","last_synced_at":"2025-03-27T16:23:03.728Z","repository":{"id":8027768,"uuid":"9437118","full_name":"jcarrano/expr","owner":"jcarrano","description":"C library for parsing and evaluating simple expressions.","archived":false,"fork":false,"pushed_at":"2013-04-14T23:40:07.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T20:11:35.868Z","etag":null,"topics":["bytecode","c","expression-evaluator"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcarrano.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-14T23:33:02.000Z","updated_at":"2017-06-19T00:01:24.000Z","dependencies_parsed_at":"2022-08-30T11:01:56.153Z","dependency_job_id":null,"html_url":"https://github.com/jcarrano/expr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcarrano","download_url":"https://codeload.github.com/jcarrano/expr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245879598,"owners_count":20687407,"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":["bytecode","c","expression-evaluator"],"created_at":"2024-12-06T12:16:34.093Z","updated_at":"2025-03-27T16:23:03.686Z","avatar_url":"https://github.com/jcarrano.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\texpr\n\tC library for parsing and evaluating simple expressions.\n\n\tJuan I Carrano.\n\n## What is expr? ##\n\nexpr is a system for compiling and evaluating simple procedures, such as\nformulas. It does not support conditionals or loops. This allows for a fast\nand simple implementation, at the expense of Turing-completeness.\nExpressions are transformed into bytecode and evaluated by a stack-machine.\nEvaluation speed is ~45% versus native C functions.\n\n## What makes expr? ##\n\nExpr is fairly modular. Its components are\n\nexpr: Used for defining environments (variables and procedures) which will \n\tbe visible to expressions.\nparse: A simple reverse polish notation parser.\ncompile: Handles the construction of a high-level representation of the expr.\n\tThe parser directly uses this module.\nassemble: Takes the output of the compile module and translates it into a\n\tcompact representation (an 'expr' object). This includes resolving\n\treferences, allocating space for stack and variables, etc.\nvm: Executes the expr object.\n\nAny of these components can be modified. (For example, it would be highly\ndesirable to have an infix parser).\n\n## What can it be used for? ##\n\nAnything that requires fast evaluation of a (simple) procedure that is to be\ndetermined at runtime. For example, a calculator which does numerical\nintegration (see under the 'examples' directory) or data processing programs.\n\nAlso, note that, aside from the extra_math library, the rest of the code does\nnot assume anything about the type of expressions. While the default definition\nof 'data_t' is 'double', you can change it to whatever you like, recompile, and\nmake full use of the system. Of course you will have to define some builtin\nfunctions.\n\n## How is it used? ##\n\nExpressions take a number of arguments and return a number of values. They\ncan store values in local variables, and access global variables. Besides\nvariable access and stack manipulation, everything else (including + - * /) is\na function call.\n\nSee the code and the examples to learn the API.\n\n* RPN parser\n\nThe current parser gives a fairly low level access to the compiler primitives.\nThe latter will check, however, that the program is correctly defined and will\nreport any errors.\n\nExpressions are writen in RPN. For example '1 1 + 3 * sin' is equivalent to\nsin((1 + 1)*3).\nTo access arguments use '$ N' where N \u003e= 0 is the argument number. Note the \nspace between $ and N.\nTo assign to a variable use '-\u003e'. For example '1 + 1 -\u003e x1'. This does NOT pop\nany values out of the stack, so for example '3 -\u003e v 4 *' returns 12. It is an\nerror to reference a local variable before assignment.\nTo reference a variable just spell it's name. The same applies to a function.\nVariable names can mask function names, so be careful.\nThe operator ';' completely clears the stack. 'clear n' clears n positions. n\nmust be constant. For example '6 4 7 clear 1 +' gives 4.\n\n* Test it!\n\nUnder 'examples' lauch calc.test. If called without input arguments it is just\na RPN calculator. Call it with \"calc.test \u003cstart\u003e \u003cstop\u003e \u003csteps\u003e\" and it will\nintegrate each expression you input between a and b using \u003cstep\u003e steps (it\nimplements a simple rectangle rule).\n\n## Is is complete? ##\n\nNo.\n\nThere is no optimization module. The goal in the near future is to be able\nto eliminate constant subexpressions. There is already a way to specify which\nfunctions depend only on their input (and have no side effects).\n\nThe parser can be greatly improved.\n\nIt would be nice to be able to write functions in expr and use then inside other\nexpressions.\n\nThere are some comments in spanish that need to be translated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcarrano%2Fexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcarrano%2Fexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcarrano%2Fexpr/lists"}