{"id":2814,"date":"2025-06-07T14:44:39","date_gmt":"2025-06-07T14:44:39","guid":{"rendered":"https:\/\/diznr.com\/?p=2814"},"modified":"2025-06-07T14:44:39","modified_gmt":"2025-06-07T14:44:39","slug":"example-of-phase-of-compiler-lexical-syntax-semantic-intermediate-target-code","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/example-of-phase-of-compiler-lexical-syntax-semantic-intermediate-target-code\/","title":{"rendered":"Example of phase of compiler &#8211; Lexical\/Syntax\/Semantic Intermediate Code Target"},"content":{"rendered":"<p>Example of phase of compiler &#8211; Lexical\/Syntax\/Semantic Intermediate Code Target<\/p>\n<p>[fvplayer id=&#8221;126&#8243;]<\/p>\n<h3 class=\"\" data-start=\"0\" data-end=\"56\"><strong data-start=\"4\" data-end=\"54\">Phases of a Compiler \u2013 Examples for Each Phase<\/strong><\/h3>\n<p class=\"\" data-start=\"58\" data-end=\"248\">A compiler translates <strong data-start=\"80\" data-end=\"99\">high-level code<\/strong> into <strong data-start=\"105\" data-end=\"121\">machine code<\/strong> through multiple phases. These phases can be categorized into <strong data-start=\"184\" data-end=\"208\">front-end (analysis)<\/strong> and <strong data-start=\"213\" data-end=\"237\">back-end (synthesis)<\/strong> processes.<\/p>\n<h3 data-start=\"255\" data-end=\"299\"><strong data-start=\"258\" data-end=\"299\">\u00a01. Lexical Analysis (Tokenization)<\/strong><\/h3>\n<ul data-start=\"300\" data-end=\"552\">\n<li class=\"\" data-start=\"300\" data-end=\"368\">\n<p class=\"\" data-start=\"302\" data-end=\"368\"><strong data-start=\"302\" data-end=\"314\">Purpose:<\/strong> Converts source code into a sequence of <strong data-start=\"355\" data-end=\"365\">tokens<\/strong>.<\/p>\n<\/li>\n<li class=\"\" data-start=\"369\" data-end=\"552\">\n<p class=\"\" data-start=\"371\" data-end=\"418\"><strong data-start=\"371\" data-end=\"383\">Example:<\/strong><br data-start=\"383\" data-end=\"386\" \/><strong data-start=\"388\" data-end=\"416\">Input Code (C language):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-c\"><span class=\"hljs-type\">int<\/span> x = <span class=\"hljs-number\">10<\/span>;<br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"448\" data-end=\"470\"><strong data-start=\"448\" data-end=\"468\">Output (Tokens):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-section\">Keyword: int<\/span><br \/>\n<span class=\"hljs-section\">Identifier: x<\/span><br \/>\n<span class=\"hljs-section\">Operator: =<\/span><br \/>\n<span class=\"hljs-section\">Number: 10<\/span><br \/>\n<span class=\"hljs-section\">Symbol: ;<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p class=\"\" data-start=\"554\" data-end=\"595\"><strong data-start=\"556\" data-end=\"570\">Tool Used:<\/strong> Lexical Analyzer (Lexer)<\/p>\n<h3 data-start=\"602\" data-end=\"640\"><strong data-start=\"605\" data-end=\"640\">\u00a02. Syntax Analysis (Parsing)<\/strong><\/h3>\n<ul data-start=\"641\" data-end=\"991\">\n<li class=\"\" data-start=\"641\" data-end=\"729\">\n<p class=\"\" data-start=\"643\" data-end=\"729\"><strong data-start=\"643\" data-end=\"655\">Purpose:<\/strong> Checks if tokens form a valid syntax according to the language grammar.<\/p>\n<\/li>\n<li class=\"\" data-start=\"730\" data-end=\"991\">\n<p class=\"\" data-start=\"732\" data-end=\"768\"><strong data-start=\"732\" data-end=\"744\">Example:<\/strong><br data-start=\"744\" data-end=\"747\" \/><strong data-start=\"749\" data-end=\"766\">Input Tokens:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-type\">int<\/span> x = <span class=\"hljs-number\">10<\/span>;<br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"797\" data-end=\"845\"><strong data-start=\"797\" data-end=\"843\">Parsing Tree (Abstract Syntax Tree &#8211; AST):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\">     =<br \/>\n\/  \\<br \/>\n<span class=\"hljs-type\">int<\/span>    <span class=\"hljs-number\">10<\/span><br \/>\n\\<br \/>\nx<br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"910\" data-end=\"991\"><strong data-start=\"912\" data-end=\"931\">Error Detected:<\/strong> Missing semicolon (<code data-start=\"951\" data-end=\"954\">;<\/code>) or incorrect placement of keywords.<\/p>\n<\/li>\n<\/ul>\n<p class=\"\" data-start=\"993\" data-end=\"1016\"><strong data-start=\"995\" data-end=\"1009\">Tool Used:<\/strong> Parser<\/p>\n<h3 data-start=\"1023\" data-end=\"1076\"><strong data-start=\"1026\" data-end=\"1076\">\u00a03. Semantic Analysis (Meaning Verification)<\/strong><\/h3>\n<ul data-start=\"1077\" data-end=\"1343\">\n<li class=\"\" data-start=\"1077\" data-end=\"1169\">\n<p class=\"\" data-start=\"1079\" data-end=\"1169\"><strong data-start=\"1079\" data-end=\"1091\">Purpose:<\/strong> Ensures code <strong data-start=\"1105\" data-end=\"1128\">makes logical sense<\/strong> (type checking, scope checking, etc.).<\/p>\n<\/li>\n<li class=\"\" data-start=\"1170\" data-end=\"1343\">\n<p class=\"\" data-start=\"1172\" data-end=\"1206\"><strong data-start=\"1172\" data-end=\"1184\">Example:<\/strong><br data-start=\"1184\" data-end=\"1187\" \/><strong data-start=\"1189\" data-end=\"1204\">Input Code:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-c\"><span class=\"hljs-type\">int<\/span> x;<br \/>\nx = <span class=\"hljs-string\">\"Hello\"<\/span>;  <span class=\"hljs-comment\">\/\/ Error: Type mismatch<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"1271\" data-end=\"1343\"><strong data-start=\"1271\" data-end=\"1281\">Error:<\/strong> <code data-start=\"1282\" data-end=\"1285\">x<\/code> is declared as an integer, but assigned a string value.<\/p>\n<\/li>\n<\/ul>\n<p class=\"\" data-start=\"1345\" data-end=\"1379\"><strong data-start=\"1347\" data-end=\"1361\">Tool Used:<\/strong> Semantic Analyzer<\/p>\n<h3 data-start=\"1386\" data-end=\"1427\"><strong data-start=\"1389\" data-end=\"1427\">\u00a04. Intermediate Code Generation<\/strong><\/h3>\n<ul data-start=\"1428\" data-end=\"1761\">\n<li class=\"\" data-start=\"1428\" data-end=\"1556\">\n<p class=\"\" data-start=\"1430\" data-end=\"1556\"><strong data-start=\"1430\" data-end=\"1442\">Purpose:<\/strong> Converts the code into an <strong data-start=\"1469\" data-end=\"1505\">intermediate representation (IR)<\/strong> that is <strong data-start=\"1514\" data-end=\"1553\">independent of machine architecture<\/strong>.<\/p>\n<\/li>\n<li class=\"\" data-start=\"1557\" data-end=\"1761\">\n<p class=\"\" data-start=\"1559\" data-end=\"1629\"><strong data-start=\"1559\" data-end=\"1607\">Example (Three-Address Code Representation):<\/strong><br data-start=\"1607\" data-end=\"1610\" \/><strong data-start=\"1612\" data-end=\"1627\">Input Code:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-c\">a = b + c * d;<br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"1662\" data-end=\"1713\"><strong data-start=\"1662\" data-end=\"1711\">Intermediate Code (Three-Address Code &#8211; TAC):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute bottom-0 right-0 flex h-9 items-center pr-2\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-attr\">t1<\/span> = c * d<br \/>\n<span class=\"hljs-attr\">t2<\/span> = b + t1<br \/>\n<span class=\"hljs-attr\">a<\/span> = t2<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p class=\"\" data-start=\"1762\" data-end=\"1808\"><strong data-start=\"1764\" data-end=\"1778\">Tool Used:<\/strong> Intermediate Code Generator<\/p>\n<h4 data-start=\"1815\" data-end=\"1850\"><strong data-start=\"1818\" data-end=\"1850\">\u00a05. Target Code Generation<\/strong><\/h4>\n<ul data-start=\"1851\" data-end=\"2065\">\n<li class=\"\" data-start=\"1851\" data-end=\"1955\">\n<p class=\"\" data-start=\"1853\" data-end=\"1955\"><strong data-start=\"1853\" data-end=\"1865\">Purpose:<\/strong> Converts <strong data-start=\"1875\" data-end=\"1896\">intermediate code<\/strong> into <strong data-start=\"1902\" data-end=\"1938\">machine code (assembly language)<\/strong> for execution.<\/p>\n<\/li>\n<li class=\"\" data-start=\"1956\" data-end=\"2065\">\n<p class=\"\" data-start=\"1958\" data-end=\"1992\"><strong data-start=\"1958\" data-end=\"1990\">Example (x86 Assembly Code):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\">MOV R1, c<br \/>\nMUL R1, d<br \/>\nMOV R2, <span class=\"hljs-selector-tag\">b<\/span><br \/>\nADD R2, R1<br \/>\nMOV <span class=\"hljs-selector-tag\">a<\/span>, R2<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p class=\"\" data-start=\"2067\" data-end=\"2098\"><strong data-start=\"2069\" data-end=\"2083\">Tool Used:<\/strong> Code Generator<\/p>\n<h3 class=\"\" data-start=\"2105\" data-end=\"2129\"><strong data-start=\"2109\" data-end=\"2129\">\u00a0Summary Table<\/strong><\/h3>\n<div class=\"overflow-x-auto contain-inline-size\">\n<table data-start=\"2130\" data-end=\"2621\">\n<thead data-start=\"2130\" data-end=\"2166\">\n<tr data-start=\"2130\" data-end=\"2166\">\n<th data-start=\"2130\" data-end=\"2138\">Phase<\/th>\n<th data-start=\"2138\" data-end=\"2148\">Purpose<\/th>\n<th data-start=\"2148\" data-end=\"2166\">Example Output<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2205\" data-end=\"2621\">\n<tr data-start=\"2205\" data-end=\"2291\">\n<td><strong data-start=\"2207\" data-end=\"2227\">Lexical Analysis<\/strong><\/td>\n<td>Converts code into tokens<\/td>\n<td><code data-start=\"2258\" data-end=\"2289\">int \u2192 Keyword, x \u2192 Identifier<\/code><\/td>\n<\/tr>\n<tr data-start=\"2292\" data-end=\"2371\">\n<td><strong data-start=\"2294\" data-end=\"2313\">Syntax Analysis<\/strong><\/td>\n<td>Creates syntax tree<\/td>\n<td>Parses expressions <code data-start=\"2357\" data-end=\"2369\">a = b + c;<\/code><\/td>\n<\/tr>\n<tr data-start=\"2372\" data-end=\"2458\">\n<td><strong data-start=\"2374\" data-end=\"2395\">Semantic Analysis<\/strong><\/td>\n<td>Checks for logical errors<\/td>\n<td><code data-start=\"2426\" data-end=\"2456\">Type mismatch: int vs string<\/code><\/td>\n<\/tr>\n<tr data-start=\"2459\" data-end=\"2542\">\n<td><strong data-start=\"2461\" data-end=\"2482\">Intermediate Code<\/strong><\/td>\n<td>Converts code to IR (Three-Address Code)<\/td>\n<td><code data-start=\"2528\" data-end=\"2540\">t1 = c * d<\/code><\/td>\n<\/tr>\n<tr data-start=\"2543\" data-end=\"2621\">\n<td><strong data-start=\"2545\" data-end=\"2571\">Target Code Generation<\/strong><\/td>\n<td>Generates machine\/assembly code<\/td>\n<td><code data-start=\"2608\" data-end=\"2619\">MOV R1, c<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"\" data-start=\"2623\" data-end=\"2690\">Would you like me to explain <strong data-start=\"2652\" data-end=\"2678\">Compiler Optimizations<\/strong> as well?<\/p>\n<h3 data-start=\"2623\" data-end=\"2690\"><a href=\"https:\/\/www.vssut.ac.in\/lecture_notes\/lecture1422914957.pdf\" target=\"_blank\" rel=\"noopener\">Example of phase of compiler &#8211; Lexical\/Syntax\/Semantic Intermediate Code Target<\/a><\/h3>\n<div>\n<div class=\"yuRUbf\">\n<div class=\"b8lM7\">\n<h3 class=\"LC20lb MBeuO DKV0Md\">Module 1 Compiler Phases of a Compiler ( Structure of &#8230;<\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/itsmeebin.wordpress.com\/wp-content\/uploads\/2020\/04\/module-1.pdf\" target=\"_blank\" rel=\"noopener\">Analysis of the source program, Phases of a compiler, &#8230;<\/a><\/h3>\n<div>\n<div class=\"yuRUbf\">\n<div class=\"b8lM7\">\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/epgp.inflibnet.ac.in\/epgpdata\/uploads\/epgp_content\/S000007CS\/P001069\/M013064\/ET\/1467009396CD-Mod2-Q1.pdf\" target=\"_blank\" rel=\"noopener\">Computer Science Compiler Design Module 2<\/a><\/h3>\n<p data-start=\"0\" data-end=\"129\">Here is a simple and clear <strong data-start=\"27\" data-end=\"72\">example of all major phases of a compiler<\/strong>, showing how one line of code is processed step by step:<\/p>\n<hr data-start=\"131\" data-end=\"134\" \/>\n<h2 data-start=\"136\" data-end=\"168\">\ud83d\udda5\ufe0f <strong data-start=\"143\" data-end=\"168\">Example Line of Code:<\/strong><\/h2>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">c<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-c\">a = b + c;<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"191\" data-end=\"275\">Now let\u2019s go through each phase of the compiler and see what it does with this line:<\/p>\n<hr data-start=\"277\" data-end=\"280\" \/>\n<h3 data-start=\"282\" data-end=\"327\">\ud83d\udd39 <strong data-start=\"289\" data-end=\"327\">1. Lexical Analysis (Tokenization)<\/strong><\/h3>\n<p data-start=\"329\" data-end=\"361\"><strong data-start=\"329\" data-end=\"360\">Breaks the code into tokens<\/strong>:<\/p>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"363\" data-end=\"594\">\n<thead data-start=\"363\" data-end=\"391\">\n<tr data-start=\"363\" data-end=\"391\">\n<th data-start=\"363\" data-end=\"378\" data-col-size=\"sm\">Token Type<\/th>\n<th data-start=\"378\" data-end=\"391\" data-col-size=\"sm\">Token<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"421\" data-end=\"594\">\n<tr data-start=\"421\" data-end=\"449\">\n<td data-start=\"421\" data-end=\"436\" data-col-size=\"sm\">Identifier<\/td>\n<td data-col-size=\"sm\" data-start=\"436\" data-end=\"449\">a<\/td>\n<\/tr>\n<tr data-start=\"450\" data-end=\"478\">\n<td data-start=\"450\" data-end=\"465\" data-col-size=\"sm\">Operator<\/td>\n<td data-col-size=\"sm\" data-start=\"465\" data-end=\"478\">=<\/td>\n<\/tr>\n<tr data-start=\"479\" data-end=\"507\">\n<td data-start=\"479\" data-end=\"494\" data-col-size=\"sm\">Identifier<\/td>\n<td data-col-size=\"sm\" data-start=\"494\" data-end=\"507\">b<\/td>\n<\/tr>\n<tr data-start=\"508\" data-end=\"536\">\n<td data-start=\"508\" data-end=\"523\" data-col-size=\"sm\">Operator<\/td>\n<td data-col-size=\"sm\" data-start=\"523\" data-end=\"536\">+<\/td>\n<\/tr>\n<tr data-start=\"537\" data-end=\"565\">\n<td data-start=\"537\" data-end=\"552\" data-col-size=\"sm\">Identifier<\/td>\n<td data-col-size=\"sm\" data-start=\"552\" data-end=\"565\">c<\/td>\n<\/tr>\n<tr data-start=\"566\" data-end=\"594\">\n<td data-start=\"566\" data-end=\"581\" data-col-size=\"sm\">Symbol<\/td>\n<td data-col-size=\"sm\" data-start=\"581\" data-end=\"594\">;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"596\" data-end=\"664\">\u2705 <strong data-start=\"598\" data-end=\"608\">Output<\/strong>: Stream of tokens<br data-start=\"626\" data-end=\"629\" \/>\u27a1\ufe0f Stored in symbol table (a, b, c)<\/p>\n<hr data-start=\"666\" data-end=\"669\" \/>\n<h3 data-start=\"671\" data-end=\"710\">\ud83d\udd39 <strong data-start=\"678\" data-end=\"710\">2. Syntax Analysis (Parsing)<\/strong><\/h3>\n<p data-start=\"712\" data-end=\"755\"><strong data-start=\"712\" data-end=\"742\">Checks grammar (structure)<\/strong> of the code.<\/p>\n<ul data-start=\"757\" data-end=\"805\">\n<li data-start=\"757\" data-end=\"802\">\n<p data-start=\"759\" data-end=\"802\">Builds a <strong data-start=\"768\" data-end=\"782\">parse tree<\/strong> or <strong data-start=\"786\" data-end=\"801\">syntax tree<\/strong>:<\/p>\n<\/li>\n<\/ul>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">markdown<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-code\">    =<br \/>\n\/ \\<br \/>\na   +<br \/>\n\/ \\<br \/>\nb   c<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<p data-start=\"855\" data-end=\"945\">\u2705 <strong data-start=\"857\" data-end=\"867\">Output<\/strong>: Syntax tree<br data-start=\"880\" data-end=\"883\" \/>\u274c If missing semicolon or wrong order, shows <strong data-start=\"928\" data-end=\"944\">syntax error<\/strong>.<\/p>\n<hr data-start=\"947\" data-end=\"950\" \/>\n<h3 data-start=\"952\" data-end=\"983\">\ud83d\udd39 <strong data-start=\"959\" data-end=\"983\">3. Semantic Analysis<\/strong><\/h3>\n<p data-start=\"985\" data-end=\"1016\"><strong data-start=\"985\" data-end=\"1003\">Checks meaning<\/strong> of the code.<\/p>\n<ul data-start=\"1018\" data-end=\"1098\">\n<li data-start=\"1018\" data-end=\"1047\">\n<p data-start=\"1020\" data-end=\"1047\">Is <code data-start=\"1023\" data-end=\"1026\">a<\/code> declared before use?<\/p>\n<\/li>\n<li data-start=\"1048\" data-end=\"1079\">\n<p data-start=\"1050\" data-end=\"1079\">Are <code data-start=\"1054\" data-end=\"1057\">b<\/code> and <code data-start=\"1062\" data-end=\"1065\">c<\/code> of same type?<\/p>\n<\/li>\n<li data-start=\"1080\" data-end=\"1098\">\n<p data-start=\"1082\" data-end=\"1098\">Can we add them?<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1100\" data-end=\"1195\">\u2705 <strong data-start=\"1102\" data-end=\"1112\">Output<\/strong>: Validated tree<br data-start=\"1128\" data-end=\"1131\" \/>\u274c If <code data-start=\"1136\" data-end=\"1139\">b<\/code> is <code data-start=\"1143\" data-end=\"1148\">int<\/code> and <code data-start=\"1153\" data-end=\"1156\">c<\/code> is <code data-start=\"1160\" data-end=\"1168\">string<\/code>, shows <strong data-start=\"1176\" data-end=\"1194\">semantic error<\/strong>.<\/p>\n<hr data-start=\"1197\" data-end=\"1200\" \/>\n<h3 data-start=\"1202\" data-end=\"1244\">\ud83d\udd39 <strong data-start=\"1209\" data-end=\"1244\">4. Intermediate Code Generation<\/strong><\/h3>\n<p data-start=\"1246\" data-end=\"1312\"><strong data-start=\"1246\" data-end=\"1289\">Converts code into an intermediate form<\/strong> (machine-independent):<\/p>\n<p data-start=\"1314\" data-end=\"1324\">Example:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">ini<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-attr\">t1<\/span> = b + c<br \/>\n<span class=\"hljs-attr\">a<\/span> = t1<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"1354\" data-end=\"1403\">\u2705 This makes optimization and translation easier.<\/p>\n<hr data-start=\"1405\" data-end=\"1408\" \/>\n<h3 data-start=\"1410\" data-end=\"1452\">\ud83d\udd39 <strong data-start=\"1417\" data-end=\"1452\">5. Code Optimization (Optional)<\/strong><\/h3>\n<p data-start=\"1454\" data-end=\"1504\"><strong data-start=\"1454\" data-end=\"1478\">Improves performance<\/strong> without changing meaning.<\/p>\n<p data-start=\"1506\" data-end=\"1513\">Before:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">ini<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-attr\">t1<\/span> = b + c<br \/>\n<span class=\"hljs-attr\">a<\/span> = t1<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"1543\" data-end=\"1549\">After:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">ini<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-attr\">a<\/span> = b + c    \/\/ Direct assignment<br \/>\n<\/code><\/div>\n<\/div>\n<hr data-start=\"1593\" data-end=\"1596\" \/>\n<h3 data-start=\"1598\" data-end=\"1634\">\ud83d\udd39 <strong data-start=\"1605\" data-end=\"1634\">6. Target Code Generation<\/strong><\/h3>\n<p data-start=\"1636\" data-end=\"1688\"><strong data-start=\"1636\" data-end=\"1666\">Converts into machine code<\/strong> (assembly or binary):<\/p>\n<p data-start=\"1690\" data-end=\"1729\">Example (in simple assembly-like code):<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">css<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\">LOAD R1, <span class=\"hljs-selector-tag\">b<\/span><br \/>\nADD R1, c<br \/>\nSTORE R1, <span class=\"hljs-selector-tag\">a<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"1777\" data-end=\"1819\">\u2705 This is what your machine actually runs.<\/p>\n<hr data-start=\"1821\" data-end=\"1824\" \/>\n<h3 data-start=\"1826\" data-end=\"1850\">\u2705 <strong data-start=\"1832\" data-end=\"1850\">Summary Table:<\/strong><\/h3>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"1852\" data-end=\"2539\">\n<thead data-start=\"1852\" data-end=\"1937\">\n<tr data-start=\"1852\" data-end=\"1937\">\n<th data-start=\"1852\" data-end=\"1877\" data-col-size=\"sm\">Compiler Phase<\/th>\n<th data-start=\"1877\" data-end=\"1906\" data-col-size=\"sm\">What it Does<\/th>\n<th data-start=\"1906\" data-end=\"1937\" data-col-size=\"sm\">Output<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2024\" data-end=\"2539\">\n<tr data-start=\"2024\" data-end=\"2109\">\n<td data-start=\"2024\" data-end=\"2049\" data-col-size=\"sm\">Lexical Analysis<\/td>\n<td data-col-size=\"sm\" data-start=\"2049\" data-end=\"2078\">Breaks into tokens<\/td>\n<td data-col-size=\"sm\" data-start=\"2078\" data-end=\"2109\">Tokens<\/td>\n<\/tr>\n<tr data-start=\"2110\" data-end=\"2195\">\n<td data-start=\"2110\" data-end=\"2135\" data-col-size=\"sm\">Syntax Analysis<\/td>\n<td data-col-size=\"sm\" data-start=\"2135\" data-end=\"2164\">Checks structure<\/td>\n<td data-col-size=\"sm\" data-start=\"2164\" data-end=\"2195\">Parse Tree<\/td>\n<\/tr>\n<tr data-start=\"2196\" data-end=\"2281\">\n<td data-start=\"2196\" data-end=\"2221\" data-col-size=\"sm\">Semantic Analysis<\/td>\n<td data-col-size=\"sm\" data-start=\"2221\" data-end=\"2250\">Checks meaning<\/td>\n<td data-col-size=\"sm\" data-start=\"2250\" data-end=\"2281\">Annotated Tree \/ Errors<\/td>\n<\/tr>\n<tr data-start=\"2282\" data-end=\"2367\">\n<td data-start=\"2282\" data-end=\"2307\" data-col-size=\"sm\">Intermediate Code Gen.<\/td>\n<td data-col-size=\"sm\" data-start=\"2307\" data-end=\"2336\">Machine-independent code<\/td>\n<td data-col-size=\"sm\" data-start=\"2336\" data-end=\"2367\">3-address code<\/td>\n<\/tr>\n<tr data-start=\"2368\" data-end=\"2453\">\n<td data-start=\"2368\" data-end=\"2393\" data-col-size=\"sm\">Code Optimization<\/td>\n<td data-start=\"2393\" data-end=\"2422\" data-col-size=\"sm\">Improves code<\/td>\n<td data-col-size=\"sm\" data-start=\"2422\" data-end=\"2453\">Optimized code<\/td>\n<\/tr>\n<tr data-start=\"2454\" data-end=\"2539\">\n<td data-start=\"2454\" data-end=\"2479\" data-col-size=\"sm\">Target Code Generation<\/td>\n<td data-col-size=\"sm\" data-start=\"2479\" data-end=\"2508\">Creates machine code<\/td>\n<td data-col-size=\"sm\" data-start=\"2508\" data-end=\"2539\">Assembly \/ Binary Code<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"2541\" data-end=\"2544\" \/>\n<p data-start=\"2546\" data-end=\"2659\" data-is-last-node=\"\" data-is-only-node=\"\">Would you like a <strong data-start=\"2563\" data-end=\"2597\">diagram of the compiler phases<\/strong>, a <strong data-start=\"2601\" data-end=\"2616\">PDF summary<\/strong>, or a <strong data-start=\"2623\" data-end=\"2631\">quiz<\/strong> to test your understanding?<\/p>\n<h3 data-start=\"2546\" data-end=\"2659\"><a href=\"https:\/\/gn.dronacharya.info\/itDept\/Downloads\/Questionpapers\/6th_sem\/CompilerDesign\/Phases_Compiler.pdf\" target=\"_blank\" rel=\"noopener\">Example of phase of compiler &#8211; Lexical\/Syntax\/Semantic Intermediate Code Target<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/gwcet.ac.in\/uploaded_files\/Compiler_Design_(Unit-_I)_6th_Sem.pdf\" target=\"_blank\" rel=\"noopener\">UNIT- I Introduction to Compiling<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.srsvidyamahapitha.org\/study_mat\/Sem-V_1598864586_CompilerDesign.pdf\" target=\"_blank\" rel=\"noopener\">Compiler Design by Md. Ajij (5th Semester)<\/a><\/h3>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Example of phase of compiler &#8211; Lexical\/Syntax\/Semantic Intermediate Code Target [fvplayer id=&#8221;126&#8243;] Phases of a Compiler \u2013 Examples for Each Phase A compiler translates high-level code into machine code through multiple phases. These phases can be categorized into front-end (analysis) and back-end (synthesis) processes. \u00a01. Lexical Analysis (Tokenization) Purpose: Converts source code into a sequence [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86],"tags":[],"class_list":["post-2814","post","type-post","status-publish","format-standard","hentry","category-compiler-design"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=2814"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2814\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=2814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=2814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=2814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}