{"id":13629276,"url":"https://github.com/lotabout/Let-s-build-a-compiler","last_synced_at":"2025-04-17T08:34:35.204Z","repository":{"id":25522626,"uuid":"28954661","full_name":"lotabout/Let-s-build-a-compiler","owner":"lotabout","description":"A C \u0026 x86 version of the \"Let's Build a Compiler\" by Jack Crenshaw ","archived":false,"fork":false,"pushed_at":"2018-10-19T00:43:21.000Z","size":294,"stargazers_count":507,"open_issues_count":0,"forks_count":74,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-05T17:05:19.732Z","etag":null,"topics":[],"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/lotabout.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":"2015-01-08T07:40:08.000Z","updated_at":"2025-03-31T13:17:39.000Z","dependencies_parsed_at":"2022-08-08T22:00:32.920Z","dependency_job_id":null,"html_url":"https://github.com/lotabout/Let-s-build-a-compiler","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/lotabout%2FLet-s-build-a-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2FLet-s-build-a-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2FLet-s-build-a-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2FLet-s-build-a-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lotabout","download_url":"https://codeload.github.com/lotabout/Let-s-build-a-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249326186,"owners_count":21251735,"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":[],"created_at":"2024-08-01T22:01:06.286Z","updated_at":"2025-04-17T08:34:34.873Z","avatar_url":"https://github.com/lotabout.png","language":"C","funding_links":[],"categories":["Tutorials","C"],"sub_categories":[],"readme":"# Information\nA C version of the \"Let's Build a Compiler\" by Jack Crenshaw \nhttp://compilers.iecc.com/crenshaw/\n\nThis repository is forked form: https://github.com/vtudose/Let-s-build-a-compiler\n\nAnd since the original is far from complete(only the first two chapter), and\nthe author had been inactive for quite a long time, I decided to create a new\nrepository.\n\nIf there are are any licence issue, please inform.\n\n# Comments\nBelow are some comments about the source code here and the original article.\n\n## What to do with the generated code\nThe generated assembly code is devoted to x86 architecture. The syntax is AT\u0026T\nstyle and the experiment operating system is Linux. You may try to save the\ngenerated code to for example \"test.s\" and execute the following commands to\ncheck the output.\n```\nas --32 -o test.o test.s\nld -m elf_i386 test.o -o test\n./test\necho $?\n```\n\n## Assembly code\nIt is a C port of the original article which is written in Pascal. And the\ngenerated code are ported to x86 instead of 86000.\n\nIf you want to test the generated code, please keep in mind that the generated\ncode might be incomplete to be directly assembled. For example, when loading a\nvariable, we directly generate Assembly code \"movl X, %eax\", and variable 'X'\nmight not be declared since the article is far from mentioning \"variable types\".\nThus you'll have to type the missing parts all by yourself.\n\n## IO routines\nI am definitely NOT an assembly expert. When the author mentioned adding IO\nroutine by library, I cannot simply find the x86 alternative. The closest\nthing is C's library function \"printf\". But then I decided not no bother\nadding this kind of routine cause they are only used in two chapters.\n\nInstead, I'll save the value as the return code of a process. It's done by\nsaving the value to register \"%ebx\" and call \"int $0x80\", as follows:\n```\nmovl var, %ebx\nmovl $1, %eax  # exit function\nint $0x80\n```\n\n-Note from random github user-\n\nOn older operating systems IO was performed by an interrupt to an area of\nmemory that contains instructions for performing the operation with your\nparticular hardware configuration. This left the developers of the operating\nsystems unable to change the memory layout without forcing all the software\nwritten to be modified as well.\n\nThe POSIX standard on UNIX-like operating systems as well as Windows and\nMacintosh operating systems, started including libraries for C or Pascal\nwith functions for system calls. This means you will either have to compile\nfor DOS or learn some specialized things about your operating system and\nthe format of C libraries.\n\nFor anyone on Windows I would recommend getting a used copy of Charles\nPetzold's Programming Windows Fifth Edition and checking out\nhttp://www.godevtool.com for some free tools and tutorials for accessing\nWindows API from assembly.\n\n-End of note-\n\n## The Article\nThe article mainly talks about how to design compiler top-down. It covered a\nlot of aspects in compiler design like lexical scanning, BNF, symbols,\nprocedures, types, code generation, etc.\n\nIt is a good article to follow for beginners.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotabout%2FLet-s-build-a-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flotabout%2FLet-s-build-a-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotabout%2FLet-s-build-a-compiler/lists"}