{"id":22222494,"url":"https://github.com/5nord/bison-example","last_synced_at":"2025-07-27T16:32:59.015Z","repository":{"id":231452225,"uuid":"72768250","full_name":"5nord/bison-example","owner":"5nord","description":"Simple example how to get a flex/bison project up and running","archived":false,"fork":false,"pushed_at":"2018-05-18T11:38:58.000Z","size":9,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T04:35:00.150Z","etag":null,"topics":["ast","bison","flex","grammar","parse","parser","scanner"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/5nord.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2016-11-03T17:10:09.000Z","updated_at":"2024-10-24T21:36:53.000Z","dependencies_parsed_at":"2024-04-04T03:56:15.525Z","dependency_job_id":null,"html_url":"https://github.com/5nord/bison-example","commit_stats":null,"previous_names":["5nord/bison-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/5nord/bison-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5nord%2Fbison-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5nord%2Fbison-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5nord%2Fbison-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5nord%2Fbison-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/5nord","download_url":"https://codeload.github.com/5nord/bison-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5nord%2Fbison-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267387140,"owners_count":24079180,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ast","bison","flex","grammar","parse","parser","scanner"],"created_at":"2024-12-02T23:18:29.126Z","updated_at":"2025-07-27T16:32:58.727Z","avatar_url":"https://github.com/5nord.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bison Example\n\nA parser generator like bison is very helpful for prototyping grammars,\nunfortunately is requires quite some code to get it up and running. This is just\na very small example to show what boilerplate code I need to build a bison-based\nparser.\n\nWhat I like about bison is, you can compile and deploy a bison-project without\nhaving any additional tools or runtime libraries installed. Further having a\nC-interface avoids common issues with C++ runtime compatibility when deploying\nshared libraries. \n\nThis example uses autotools, a pure flex-scanner and bison-parser with locations\n(in this this example only lines). Output is a simple tree, which links its\nelements using single-linked lists. Simple routines for tree traversal are\nprovided, too.\n\nThe example-grammar is just nonsense:\n\n    Names  ::= {Name}+\n    Name   ::= ID | FooBar\n    FooBar ::= \"foo\" [Bar]\n    Bar    ::= \"bar\"\n\n\n## Compilation\n\nNormally auto-generated files like Makefile.in or parser.c are included in the\nrepository to simplify compilation. But I left them out, to keep the example\nsmall. So, that's how you bootstrap autotools and compile this example:\n\n    $ autoreconf -i\n    $ ./configure\n    $ make\n\n# Notes\n\n## Autotools\n\n * the scanner and parser files must have different base-names, or they will\n   overwrite each other. I named them `lexer.l` and `parser.y` and put them into\n   a sub-directory, in case a project requires more than one parser.\n * The parser builds as library. Don't forget to give Automake the proper,\n   dependencies.\n\n\n## AST\n\n * Node types are defined in `example/node.def`.\n * Nodes either have a value _or_ children.\n * Appending nodes is inefficient due to single-linked lists.\n * Line handling seems to be over-engineered. That's because in my projects I\n   prefer to use file-offsets and line-caches instead; similar to clang or\n   golang parsers. See https://github.com/nokia/ntt/blob/bison-parser/ttcn3/syntax/source.h for example.\n\n\n## Bison\n\n * Virtually all rules have to return nodes, because nodes are lists. Empty\n   rules return an Epsilon node. This makes evaluating the AST easier.\n * I did not change `yy`-prefix. If you require more than one parser you'll\n   have to rename global symbols.\n\n## Flex\n\n * For simplicity values are just `strdup`ed. \n * Like with bison, you'll might have to change the prefix.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5nord%2Fbison-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F5nord%2Fbison-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5nord%2Fbison-example/lists"}