{"id":13782807,"url":"https://github.com/Gyumeijie/an-embedded-c-interpreter","last_synced_at":"2025-05-11T16:33:01.338Z","repository":{"id":37336392,"uuid":"110535719","full_name":"Gyumeijie/an-embedded-c-interpreter","owner":"Gyumeijie","description":"a very simple interpreter for c, inspired by c4, but it is embedded","archived":false,"fork":false,"pushed_at":"2018-07-06T05:23:22.000Z","size":81,"stargazers_count":11,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T17:01:32.827Z","etag":null,"topics":["c","configuration-file","embedded","executor","interpreter","parse"],"latest_commit_sha":null,"homepage":"https://github.com/rswier/c4","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/Gyumeijie.png","metadata":{"files":{"readme":"README.md","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":"2017-11-13T10:45:35.000Z","updated_at":"2024-08-18T09:44:59.000Z","dependencies_parsed_at":"2022-08-18T02:10:57.316Z","dependency_job_id":null,"html_url":"https://github.com/Gyumeijie/an-embedded-c-interpreter","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/Gyumeijie%2Fan-embedded-c-interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fan-embedded-c-interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fan-embedded-c-interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fan-embedded-c-interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gyumeijie","download_url":"https://codeload.github.com/Gyumeijie/an-embedded-c-interpreter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253595947,"owners_count":21933475,"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":["c","configuration-file","embedded","executor","interpreter","parse"],"created_at":"2024-08-03T18:01:45.044Z","updated_at":"2025-05-11T16:33:01.080Z","avatar_url":"https://github.com/Gyumeijie.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# introduction\nThis is a very simple interpreter for c-like code, inspired by [c4](https://github.com/rswier/c4). The key difference between c4 and this interpreter is the latter one is embedded, and by it's very name, we can use this embedded interpreter to interpret and run a c-like code sinppet which, more often than not, is used to configure the main program, and can take the form of sole xml-file or string.\n\n# components\nThis tiny embedded c interpreter is mainly composed of four parts:\n- dependency\n- lex\n- parser\n- executor\n\n# example\nSuppose a scenario where there are two variables in main program named `result` and `data`, and we want to multiply the `data` by a number say 6, and store the result in the `result` variable. This sounds simple right? but what we do here is to write the logical code as an external configuration data not directly in the program, yes it is data not code. \n\nIn order to realize this, we need the program to have the ability to parse the configuration data with logic into some thing can be executed,say bytecode, and the bytecode can intereact with the main program by accessing the two variables,`result` and `data`. The following steps show how to do it.\n\n1. Initilizatize the parser and the executor\n```c\n parser_init();  \n executor_init();\n```\n\n2. Add dependecy\n```c\n   dep_itemsp = init_dependency_items(2);\n   add_dependency_item(dep_itemsp, \"data\", \u0026data, INT);\n   add_dependency_item(dep_itemsp, \"result\", \u0026result, INT);\n```\n\u003eNotice that the ***data*** and ***result*** are variables in the main program, both with integer type, and the two will be used\nin the code block.\n\n3. Get the code block ready\n```c\n char* src = \"use{} action{result = data * 6;}\";\n```\n\u003e***\"use{} action{result = data * 6;}\"*** is what we call ***code block***, which can be place in the source file or configuration\nfile, say xml-format file. The following xml snippet is a simple demo of xml-format code block:\n\u003e ```xml\n\u003e \u003ccode_block name=\"arbitary-name-you-like\"\u003e\n\u003e   use{} action{result = data * 6;} \n\u003e \u003c/code_block\u003e\n\u003e ```\n\n4. Compile the source code\n```c\nint* code = compile_src_code(dep_itemsp, src);\n```\n\n5. Run the compiled byte code\n```c\nrun_code(code);\n```\nWhen excution is done, the ***result*** ,in the main program, will have a value of 6, given ***data*** is 1.\n\n# usage\n1. dowload the repository\n```bash\ngit clone https://github.com/Gyumeijie/an-embedded-c-interpreter.git\n```\n2. cd into the `an-embedded-c-interpreter` directory\n```bash\ncd an-embedded-c-interpreter\n```\n3. type `make` command\n```bash\nmake\n```\n4. run the code\n```bash\n./main\n```\n\n# link\nThere is a project named [satellite-borne-device-management](https://github.com/Gyumeijie/satellite-borne-device-management) uses this embedded interpreter to configure the program.\n\n# todo \n- [ ] redesign the APIs for more usablity.\n\u003e Mainly center on seperating dependency variable info into two parts, the first part is static decalrative info \n\u003e including type and name of a dependency; And the second part is about the dynamic runtime info concerning address\n\u003e of that dependency.\n- [ ] refactor code for more Maintainability.\n- [ ] support more grammar.\n- [ ] add safety check for accessing dependency variable(s) in code block.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGyumeijie%2Fan-embedded-c-interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGyumeijie%2Fan-embedded-c-interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGyumeijie%2Fan-embedded-c-interpreter/lists"}