📖 Scenario: You are learning how a compiler works by dividing its process into two main parts: the front-end and the back-end. This helps understand how source code is transformed into machine code step-by-step.
🎯 Goal: Create a simple representation of the compiler's front-end and back-end stages using Python dictionaries and variables. This will help you clearly see the difference between these two parts.
📋 What You'll Learn
Create a dictionary called front_end with keys 'lexical_analysis', 'syntax_analysis', and 'semantic_analysis' and assign each a short description string.
Create a dictionary called back_end with keys 'optimization' and 'code_generation' and assign each a short description string.
Create a variable called compiler_stages that combines front_end and back_end into one dictionary with keys 'Front-End' and 'Back-End'.
Add a variable called total_stages that counts how many stages the compiler has in total.
💡 Why This Matters
🌍 Real World
Understanding compiler stages helps software developers and computer scientists know how source code is transformed into executable programs.
💼 Career
Knowledge of compiler design is useful for roles in software development, programming language design, and systems engineering.
Progress0 / 4 steps
1
Create the Front-End dictionary
Create a dictionary called front_end with these exact entries: 'lexical_analysis' set to 'Tokenizing source code', 'syntax_analysis' set to 'Parsing tokens into syntax tree', and 'semantic_analysis' set to 'Checking meaning and types'.
Compiler Design
Hint
Use curly braces {} to create a dictionary and separate keys and values with colons.
2
Create the Back-End dictionary
Create a dictionary called back_end with these exact entries: 'optimization' set to 'Improving code performance' and 'code_generation' set to 'Producing machine code'.
Compiler Design
Hint
Remember to use the same dictionary syntax as in Step 1.
3
Combine Front-End and Back-End into compiler_stages
Create a dictionary called compiler_stages with two keys: 'Front-End' set to the front_end dictionary and 'Back-End' set to the back_end dictionary.
Compiler Design
Hint
Use the variable names exactly as given and assign them as values to the new dictionary.
4
Count total compiler stages
Create a variable called total_stages that counts the total number of stages by adding the length of front_end and back_end dictionaries.
Compiler Design
Hint
Use the len() function to count dictionary entries and add them.
Practice
(1/5)
1. Which part of a website is responsible for what users see and interact with directly?
easy
A. Server
B. Back-end
C. Database
D. Front-end
Solution
Step 1: Understand the role of front-end
The front-end is the part of a website or app that users see and interact with, like buttons, text, and images.
Step 2: Differentiate from back-end
The back-end works behind the scenes managing data and processes, not directly visible to users.
Final Answer:
Front-end -> Option D
Quick Check:
Front-end = User interface [OK]
Hint: Front-end = what users see and click [OK]
Common Mistakes:
Confusing front-end with back-end
Thinking database is visible to users
Mixing server with front-end
2. Which of the following is a common technology used in front-end development?
easy
A. Python
B. HTML
C. SQL
D. Node.js
Solution
Step 1: Identify front-end technologies
HTML is a core language used to create the structure of web pages, part of front-end development.
Step 2: Recognize other options
Python and Node.js are mostly back-end languages, and SQL is used for databases, not front-end.
Final Answer:
HTML -> Option B
Quick Check:
HTML = Front-end language [OK]
Hint: HTML is the building block of web pages [OK]
Common Mistakes:
Choosing Python or Node.js as front-end
Confusing SQL with front-end language
Not knowing HTML's role
3. Consider this scenario: A user clicks a button on a website, and the site fetches data from a database to show results. Which part handles the data fetching?
medium
A. Front-end
B. HTML code
C. Back-end
D. User's browser
Solution
Step 1: Understand the user action
The user clicks a button on the front-end interface, which triggers a request.
Step 2: Identify data fetching responsibility
The back-end receives the request, accesses the database, and sends data back to the front-end.
Final Answer:
Back-end -> Option C
Quick Check:
Data fetching = Back-end task [OK]
Hint: Back-end handles data and logic behind scenes [OK]
Common Mistakes:
Thinking front-end fetches data directly
Confusing browser with back-end
Assuming HTML does data fetching
4. A developer wrote this code snippet for a website: function showData() { fetch('/data').then(response => response.json()).then(data => console.log(data)); } But the data never appears on the page. What is the likely issue?
medium
A. The fetch URL is incorrect or server not responding
B. The function showData is not defined
C. The console.log is not a valid method
D. The data is shown automatically without code
Solution
Step 1: Analyze the fetch call
The fetch function requests data from '/data'. If the URL is wrong or server is down, no data returns.
Step 2: Check other parts
The function is defined, console.log is valid, and data won't show automatically without code.
Final Answer:
The fetch URL is incorrect or server not responding -> Option A
Quick Check:
Fetch failure = wrong URL or server issue [OK]
Hint: Check fetch URL and server status first [OK]
Common Mistakes:
Assuming function is undefined
Thinking console.log is invalid
Expecting automatic data display
5. You want to build a web app where users can upload photos and see them instantly. Which combination best describes the roles of front-end and back-end?
hard
A. Front-end handles photo upload interface; back-end stores photos and manages uploads
B. Back-end creates buttons; front-end stores photos
C. Front-end stores photos; back-end displays photos
D. Back-end handles user clicks; front-end manages database
Solution
Step 1: Identify front-end role
The front-end shows the upload button and preview interface where users interact.
Step 2: Identify back-end role
The back-end receives uploaded photos, stores them securely, and manages data.
Final Answer:
Front-end handles photo upload interface; back-end stores photos and manages uploads -> Option A
Quick Check:
Front-end = interface, Back-end = data management [OK]
Hint: Front-end = UI; Back-end = data and logic [OK]
Common Mistakes:
Reversing front-end and back-end roles
Thinking front-end stores data
Assuming back-end creates UI buttons
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.