{"id":16909366,"url":"https://github.com/yjdoc2/the-transpiler-project","last_synced_at":"2026-02-27T19:40:41.223Z","repository":{"id":100667076,"uuid":"264420878","full_name":"YJDoc2/The-Transpiler-Project","owner":"YJDoc2","description":"A transpiler which compiles c-like syntax to pure C. This supports classes, let declaration, for-in loops. Created using Flex and Bison.","archived":false,"fork":false,"pushed_at":"2020-06-25T14:24:41.000Z","size":2047,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T11:52:29.288Z","etag":null,"topics":["bison","c","compiler","flex","makefile"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YJDoc2.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-05-16T11:21:40.000Z","updated_at":"2024-11-22T18:04:00.000Z","dependencies_parsed_at":"2023-05-16T16:00:18.368Z","dependency_job_id":null,"html_url":"https://github.com/YJDoc2/The-Transpiler-Project","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/YJDoc2%2FThe-Transpiler-Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YJDoc2%2FThe-Transpiler-Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YJDoc2%2FThe-Transpiler-Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YJDoc2%2FThe-Transpiler-Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YJDoc2","download_url":"https://codeload.github.com/YJDoc2/The-Transpiler-Project/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248434690,"owners_count":21102886,"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","c","compiler","flex","makefile"],"created_at":"2024-10-13T18:55:29.874Z","updated_at":"2026-02-27T19:40:36.192Z","avatar_url":"https://github.com/YJDoc2.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Transpiler project\n\nA Transpiler which compiles from the custom syntax to pure C, using Flex and Bison.\u003cbr /\u003e\nThis was done as a project while learning Flex and Bison\n\n## About\n\nThis is a basically very simple syntax converter, which converts from the custom syntax as stated in \u003ca href='https://github.com/YJDoc2/The-Transpiler-Project/blob/master/syntax.md'\u003esyntax.md\u003c/a\u003e, to pure C files.\nThis supports only Basic of C syntax , and does not support :\n\n\u003cul\u003e\n    \u003cli\u003e Multi-dimensional Arrays\u003c/li\u003e\n    \u003cli\u003e Any kind of pointers \u003c/li\u003e\n    \u003cli\u003e asm and compiler directives, along with preprocessor commands\u003c/li\u003e\n    \u003cli\u003ebitwise operators\u003c/li\u003e\n    \u003cli\u003eenums and unions\u003c/li\u003e\n    \u003cli\u003eetc...\u003c/li\u003e\n\u003c/ul\u003e\n\nThis just supposed to be a fun project, not to be used in production environment\u003cbr /\u003e\n\nThis introduces some things that are not directly supported in C , like :\n\n\u003cul\u003e\n    \u003cli\u003elet a = ...\u003c/li\u003e\n    \u003cli\u003efor i in ... loops\u003c/li\u003e \n    \u003cli\u003eclasses ... or glorified structs \u003c/li\u003e\n\u003c/ul\u003e\n\nSee the \u003ca href='https://github.com/YJDoc2/The-Transpiler-Project/blob/master/project.md'\u003eproject.md\u003c/a\u003e for how the features were developed step-wise\n\nAlso thanks to \u003ca href='https://github.com/YatharthVyas'\u003eYatharth\u003c/a\u003e for helping with windows makefile\n\n## Build instructions\n\nThis can be directly built on linux systems using the outermost Makefile, and is built and tested on Ubuntu 20.04\n\nFor Windows, a program capable of running makefile is needed such as : \u003ca href = 'http://gnuwin32.sourceforge.net/packages/make.htm'\u003ethis\u003c/a\u003e. Note this is not tested, and should be used on one's own risk.\nThis assumes that the C compiler is linked to the name 'gcc' , in case the name is different , change it to correct name in the Makefile-windows in variable named CC. This also assumes archiving program ar is lined to name 'ar' change accordingly if name is different.\nOnce successfully run, this will generate an executable file named 'ttp' in the outermost folder.\n\n\u003cstrong\u003eNOTE\u003c/strong\u003e that for normal use, the files in transpiler folder should not be modified at all, or an accidental modification to any\n.l or .y file will force Make to run flex and bison programs on next building attempt, and as those are not strictly needed for non-development purposes, this may not allow to create the binary again.\n\n## Usage :\n\nThe command line syntax is :\nttp filename [ -hkl ][-o outfile]\u003cbr/\u003e\nwhere filename is the name of file to be transpiiled, which is necessary argument\u003cbr/\u003e\nh flag displays help\u003cbr/\u003e\nk flag keeps the generated files even if there were any errors in the transpilation, which are otherwise deleted\u003cbr/\u003e\nl prints the line numbers as pre-processor directives, which can be used by compilers to show the lines in original file, instead of generated, but these may be a bit off that actual\u003cbr/\u003e\no flag requires a name, which is given to the generated file instead of the name of input file.\u003cstrong\u003eNOTE\u003c/strong\u003e that this does not affect the generated class files, which are always named as 'class_classname.h' and 'class_classname.c'\u003cbr/\u003e\n\n## For general Users :\n\nThese are few points to be noted before use :\n\nAll generated files contain these basic headers :\n\n\u003cul\u003e\n\u003cli\u003estdio.h\u003c/li\u003e\n\u003cli\u003estdlib.h\u003c/li\u003e\n\u003cli\u003estdbool.h\u003c/li\u003e\n\u003cli\u003estring.h\u003c/li\u003e\n\u003cli\u003ecomplex.h\u003c/li\u003e\n\u003cli\u003emath.h\u003c/li\u003e\n\u003c/ul\u003e\n\nIn code the Order would be maintained in generated files, but not the adjacency.\nthat is the line 1 and line 2 are two consecutive lines, in generated files, line 1 will come before line 2, but there may be some extra generated code between those two lines\u003cbr /\u003e\n\nthis does not check well for void-type function returns, so that 5+ test() or test() +5 where test is a void returning function is transpiled without ay error message, even though in C these are incorrect\n\nFor input using input action :\nfor bool = nonzero true, zero false\u003cbr /\u003e\nfor complex two floats, real then img\u003cbr /\u003e\n\nIn defining string in the code,only single line strings are accepted\u003cbr /\u003e\n\nNote that in denoting complex numbers (a,b) a is part which will not be multiplied by I and b is part which will be multiplied by I.\nIn case the a and/or be themselves are complex, the resulting number will be formed by the said multiplications of I.\u003cbr /\u003e\n\nDoes Not Support bitwise operators \u0026 | ~ ^ \u003c\u003c \u003e\u003e, enums and unions\u003cbr /\u003e\n\nOnly 1D arrays supported\u003cbr/\u003e\nthe string should be used for read only / print only strings. for input-able string use charbuf : see \u003ca href='https://github.com/YJDoc2/The-Transpiler-Project/blob/master/syntax.md'\u003esyntax.md\u003c/a\u003e\n\nNote that it is not necessary to declare function before use, or to use function that are declared in this file only.\nThis works in two stages for scanning all function signatures before actual parsing, and any non-declared function is assumed as void-type, which must be type casted.\u003cbr/\u003e\n\nin for loops for var in a .. b, there must be a space in a and '..' and '..' and b\u003c/br\u003e\nAlso note that for using for loop over arrays, the array must be declared in the scope , enclosing scope or globally.This will not work on arrays passed as parameters to the functions\u003cbr/\u003e\n\nvariables declared with let must have an expression assigned to them, whose type can be inferred. also these variables will be of normal type, i.e. niether static nor const.\u003cbr/\u003e\n\nNote that one cannot access the fields of class if brackets are put around the variable, i.e. if class var A has a field B one can access by A.B but not by (A).B . Same applies for fn / method calls, if fn F returns Class type var, which has a field B, one can access it by\n\n\u003cul\u003e\n\u003cli\u003e F().B \u003c/li\u003e\n\u003cli\u003eclassname A = F();\u003cbr /\u003e\n    A.B\u003c/li\u003e\n\u003c/ul\u003e\nbut cannot access as (F()).B\n\u003cbr /\u003e\n\n## For those who will look into code\n\nProject is divided in three folders : lib contains all the functions that are used in parser, util contains Data structures required for parser, adn transpiler contains all bison and flex files\u003cbr /\u003e\n\nDo not go looking for ASTs as they are not there, as this has to print the expressions in the infix format only in C , ASTs are not used.\nThis is the very reason why it has a poor error detection for void return functions, as is void check is put between expr sign (here) expr, it gives a lot of Shift reduce errors, and if put on value, it gives error for externally declared functions,even though they are type casted.\u003cbr /\u003e\n\nFuntion declaration suntax is fn name(paramlist) -\u003e ret type {...} because otherwise there were Shift/reduce conflicts topstmt in declaration and fndeclaration And I didn't want to use GLR.\u003cbr /\u003e\n\nThe scheme used for recursively varifying expressionf in fncalls is (kind-of) ad-hoc. It basically pushes the arglist ptr and current type of expression in two individual stacks and when it completes parsing a fncall it pops those two back.\u003cbr /\u003e\n\nFor using Valgrind for leack checks : if normal installation gives error because of strlen bug, try uninstalling , then either : making from latest source or installing from apt-get/ respective package manages instead of snaps, also install libc6-dbg:i386 using package manager.\nThe snap of valgrind didn't work because of strlen error.\u003cbr /\u003e\n\nfor input-able strings, charbuf is introduced. it translates to char [ ][ ],and can be declared with [expr], [expr] = {...},[] = {...}, [expr][expr], [expr][expr] = {...}, [][expr] = {...}. these essentially creates char double array, where one can take in input.As C itself allows to take input in statically allocated strings, eg : char c[] = \"...\", ttp allows that as well by taking input in strings, but this will cause a seg fault at runtime, so it is best to create a charbuf [] to take string input, and charbuf[][] to make an array of input-able strings. \u003cbr /\u003e\n\nthe reason for for loops working only on arrays in scope not passed as pointers is because C can track size of arrays declared in the scope/globally but once it reduces to pointer, the scheme used for determining the size of array : sizeof(a)/sizeof(a[0]) does not work.\u003cbr/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjdoc2%2Fthe-transpiler-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjdoc2%2Fthe-transpiler-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjdoc2%2Fthe-transpiler-project/lists"}