{"id":21434371,"url":"https://github.com/z1skgr/flex-bison","last_synced_at":"2026-01-03T16:31:02.118Z","repository":{"id":163130781,"uuid":"314628107","full_name":"z1skgr/FLEX-BISON","owner":"z1skgr","description":"Building compilers for lexical analysis \u0026 parsing","archived":false,"fork":false,"pushed_at":"2022-02-20T07:27:21.000Z","size":322,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T09:11:29.883Z","etag":null,"topics":["bison-yacc","compiler","flex","lexer","lexical-analyzer","parser","parsing-expression-grammars","programming-language","ubuntu","yacc-lex"],"latest_commit_sha":null,"homepage":"","language":"Yacc","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/z1skgr.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":"2020-11-20T17:46:04.000Z","updated_at":"2024-11-02T08:30:14.000Z","dependencies_parsed_at":"2024-04-05T22:30:11.715Z","dependency_job_id":null,"html_url":"https://github.com/z1skgr/FLEX-BISON","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/z1skgr%2FFLEX-BISON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z1skgr%2FFLEX-BISON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z1skgr%2FFLEX-BISON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z1skgr%2FFLEX-BISON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z1skgr","download_url":"https://codeload.github.com/z1skgr/FLEX-BISON/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945529,"owners_count":20372894,"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":["bison-yacc","compiler","flex","lexer","lexical-analyzer","parser","parsing-expression-grammars","programming-language","ubuntu","yacc-lex"],"created_at":"2024-11-22T23:35:08.497Z","updated_at":"2026-01-03T16:31:02.065Z","avatar_url":"https://github.com/z1skgr.png","language":"Yacc","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compiler generation (TeaC Compiler)\n\u003e Source-to-source compiler (trans-compiler or transpiler) using FLEX \u0026 BISON. \n## Table of contents\n* [General Info](#general-information)\n* [Installation](#installation)\n* [Execution](#execution)\n* [Acknowledgements](#acknowledgements)\n\n## General Information\nThe input files (file .tc) is written in the fictional TeaC programming language and the generated code is in C. Each TeaC program is a set of word units, which are arranged according to syntax rules of a fictional language. We generate a compiler that recognizes .tc archives and generate the equivalent C code. The implementation is split to two parts:\n* Lexical Analyzer\n* Parser Generator\n  * Convertion fictional code to C code using bison actions.   \n\n\n### Flex\nGeneral form of description of a language programming. Scans words in text files in token format and corresponds them to grammatical rules (declared in `.l` file).\u003cbr\u003e\nWe specify the categories of rules:\n* Keywords\n* Identifiers\n* Constants\n    * Boolean\n    * Real positive\n    * Strings\n* Operators\n* Delimiters\n* Specials (white space, comments)\n\nIn this version, we have set some specific words for TeaC as keywords:\n\n| Keywords |     |  |\n| ------------- | ------------- | ------------  |\n| int  | real  | bool  |\n| string  | true| false  |\n| if  | then  | else  |\n| fi  | while  | loop |\n| pool  | const  | let  |\n| return  | not  | end  |\n| or  | start  |   |\n\nThe other categories have basic common programming language content (possibly with some shortcomings, check `.l` for clarifications). \u003cbr\u003e\u003cbr\u003eFor more information about Flex, see https://www.geeksforgeeks.org/flex-fast-lexical-analyzer-generator/.\u003cbr\u003e\n\n\n\n\n\n\n\n### Bison\nSyntactic rules of a language define the correct syntax of its word units. Here, we have:\n* Main\n    * Declarations\n    * Functions\n    * Body \n* Data Types\n* Array (one dimension)\n* Variables\n* Functions\n* Expressions\n* Commands\n* Constants\n\nIt builds `\u003cparser_name\u003e.tab.c, \u003cparser_name\u003e.tab.h` files.\u003cbr\u003e\u003cbr\u003e For more information https://www.geeksforgeeks.org/bison-command-in-linux-with-examples/\n\n## Installation\n* In linux terminal, run commands to install tools. \n\n```\n$ sudo apt-get install flex\n$ sudo apt update\n$ sudo apt install bison\n```\n\n\nFor any help, see\n```\n$ bison --help\n```\n\n* GCC install to converter parser rules to a recognized programming language (C in this case)\n```\n$ sudo apt install build-essential\n$ sudo apt-get update\n```\n* Verify correctly installation with the version of the GCC\n```\n gcc --version\n```\n\n## Execution\n* Syntax analysis from parser\n```\nbison -d -v -r  \u003cparser_name\u003e.y\n```\n* Lexical analysis from lexer\n```\nflex \u003canalyzer name\u003e.l\n```\n* Build compiler using the extracted rules\n```\ngcc -o teac \u003cparser_name\u003e.tab.c \u003canalyzer name\u003e.yy.c cgen.c -lfl\n```\n\n\n* Convert the fictional input to a .c file\n```\n./teac \u003c \u003cTeaC_input\u003e.tc\u003e output.c\n ```\n* Build and run\n```\ngcc -Wall -std=c99 -o out output.c\n./out\n```\nIn `\\scripts`, there are a few script for testing code for different sample inputs. ` correct1.tc` is a sample of source code of TeaC language. \n\n### Prerequisites\n```cgen.c``` contains function for lex to handle string. In other words, uses buffers to handle the parser's tokens. \u003cbr\u003eError in stream =\u003e Error in syntax =\u003e No executable \n \u003cbr\u003e\n\n## Acknowledgements\n- This project was created for the requirements of the lesson Theory of Computation\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz1skgr%2Fflex-bison","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz1skgr%2Fflex-bison","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz1skgr%2Fflex-bison/lists"}