{"id":18243975,"url":"https://github.com/akphi/mer-c-less","last_synced_at":"2025-04-08T18:29:21.122Z","repository":{"id":110158610,"uuid":"109739176","full_name":"akphi/Mer-C-less","owner":"akphi","description":"a simple parser for a simple language","archived":false,"fork":false,"pushed_at":"2017-11-06T19:23:58.000Z","size":293,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T06:04:49.888Z","etag":null,"topics":["lexical-analyzer","parser","syntax-analyzer"],"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/akphi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-06T19:21:54.000Z","updated_at":"2017-11-06T19:51:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d21d589-3597-4767-9b2c-0e83d54340a4","html_url":"https://github.com/akphi/Mer-C-less","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"25f4d9007361fca0c04c4a25b3c433c5778e6221"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akphi%2FMer-C-less","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akphi%2FMer-C-less/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akphi%2FMer-C-less/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akphi%2FMer-C-less/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akphi","download_url":"https://codeload.github.com/akphi/Mer-C-less/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247901528,"owners_count":21015279,"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":["lexical-analyzer","parser","syntax-analyzer"],"created_at":"2024-11-05T09:04:28.301Z","updated_at":"2025-04-08T18:29:21.099Z","avatar_url":"https://github.com/akphi.png","language":"C","readme":"# Mer-C-less\nA rudimentary parser concealing within itself a regex-based lexcial analyzer and a LL(1) top-down passer.\n\n## The Good, the Bad, and the Ugly\nThe grammar rules in EBNF are defined below. Note that [] and {} are not _terminals_. Besides, if any non-space characters are detected after a program end, an error is reported.\n\n\t\u003cprogram\u003e ::= program \u003cprogname\u003e \u003ccompound stmt\u003e\n\t\u003ccompound stmt\u003e ::= begin \u003cstmt\u003e {; \u003cstmt\u003e} end\n\t\u003cstmt\u003e ::= \u003csimple stmt\u003e | \u003cstructured stmt\u003e\n\t\u003csimple stmt\u003e ::= \u003cassignment stmt\u003e | \u003cread stmt\u003e | \u003cwrite stmt\u003e |\n\t\t\t  \u003ccomment\u003e\n\t\u003cassignment stmt\u003e ::= \u003cvariable\u003e := \u003cexpression\u003e\n\t\u003cread stmt\u003e ::= read ( \u003cvariable\u003e { , \u003cvariable\u003e } )\n\t\u003cwrite stmt\u003e ::= write ( \u003cexpression\u003e { , \u003cexpression\u003e } )\n \t\u003ccomment\u003e ::= # alltext to end of line ignored\n \t\u003cstructured stmt\u003e ::= \u003ccompound stmt\u003e | \u003cif stmt\u003e | \u003cwhile stmt\u003e\n \t\u003cif stmt\u003e ::= if \u003cexpression\u003e then \u003cstmt\u003e |\n \t\t      if \u003cexpression\u003e then \u003cstmt\u003e else \u003cstmt\u003e\n \t\u003cwhile stmt\u003e ::= while \u003cexpression\u003e do \u003cstmt\u003e\n \t\u003cexpression\u003e ::= \u003csimple expr\u003e |\n \t\t\t \u003csimple expr\u003e \u003crelational_operator\u003e \u003csimple expr\u003e\n\t\u003csimple expr\u003e ::= [ \u003csign\u003e ] \u003cterm\u003e { \u003cadding_operator\u003e \u003cterm\u003e }\n\t\u003cterm\u003e ::= \u003cfactor\u003e { \u003cmultiplying_operator\u003e \u003cfactor\u003e }\n\t\u003cfactor\u003e ::= \u003cvariable\u003e | \u003cconstant\u003e | ( \u003cexpression\u003e )\n\t\u003csign\u003e ::= + | -\n\t\u003cadding_operator\u003e ::= + | -\n\t\u003cmultiplying_operator\u003e ::= | /\n\t\u003crelational_operator\u003e ::= = | \u003c\u003e | \u003c | \u003c= | \u003e= | \u003e\n\t\u003cvariable\u003e ::= \u003cletter\u003e { \u003cletter\u003e | \u003cdigit\u003e }\n\t\u003cconstant\u003e ::= \u003cdigit\u003e { \u003cdigit\u003e }\n\t\u003cprogname\u003e ::= \u003ccapital_letter\u003e { \u003cletter\u003e | \u003cdigit\u003e }\n\t\u003ccapital_letter\u003e ::= A | B | C | ... | Z\n\t\u003cletter\u003e ::= a | b | c | ... | z | \u003ccapital_letter\u003e\n\t\u003cdigit\u003e ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n\nMer-C-less parser, at syntax analyzing step, will check if the current token matches what is expected, if a match occurs, the next token is requested from the lexcial analyzer, otherwise, it adds a syntax error and keep the current token for the next match, assuming that the current expected token has been satisfied. This behavior is crucial to the parser and must be noted.\n\n## Usage\nA `Makefile` is prepared for, of course, making. Several targets are available at your service. Simply `cd` to the source directory and use one of the followings:\n\n```\nmake\nmake clean\nmake re\nmake debug\nmake test\nmake test-debug\n```\n\nThe first is simply used to compile the source codes. The second is to cleanup all prior compilation. The third runs a `make clean` before running `make`. The third runs `make` with _DEBUG_ flag enabled. In debug mode, detailed messages from lexical analyzer, syntax analyzer and parser are shown. \n\n![](images/make_debug.png)\n\nThe target `make test` compiles the source code, runs prepared test cases in `test/case` and match the output with the expected_output in `test/expected_output`. Note that the filename must match for test to be run, otherwise, it is __SKIPPED__. Target `make test-debug` runs each test in debug mode without outcome matching.\n\n![](images/make_test.png)\n\nAs for the token definition list, they are stored in the text file called _token_definition.txt_ together with the POSIC regex pattern which can be used to match them. Note that the order of definition really matters and as you update the token list, remember to update the header of this file as well. The header, i.e. the first 3 lines indicate the number of entries, the maximum length allowed for token name and the maximum length allowed for pattern, respectively. _tl; dr - Edit this file with caution_\n\nIf one wishes to only parse a single file, use the following command\n\n```\n./parse \u003cfile_to_be_parsed\u003e\n```\n\n## Options\nRefer to the setting.h file to see all available options. Most options are rather comprehensible, such as:\n```\nPARSE_DEBUG_ENABLED\nLEX_DEBUG_ENABLED\nTAB_SIZE_WARNING_ENABLED\nTAB_SIZE\n...\t\n```\nYou might want to check the `TAB_SIZE` option for more accurate error location information. Mer-C-less hides within itself a hidden gem where it allows error mapping on source, this can be enabled by setting `CODE_DISPLAY_ENABLED` to `1`. This should allow the program to show error-mapped source in _normal_ and _debug_ mode.\n\n![](images/error_mapping_source.png)\n\nLast but not least, you can customize the color of output, they are all in ANSI format. A list of commonly used colors is also included at the bottom of the setting file.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakphi%2Fmer-c-less","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakphi%2Fmer-c-less","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakphi%2Fmer-c-less/lists"}