The document discusses semantics and code generation in programming languages. It provides background on semantics and how it is used in compiler design to determine if code is meaningful or meaningless through semantic analysis. It also describes code generation, which takes the parse tree after semantic analysis and converts the code into machine language that can be executed. Examples are given of semantic records used in analysis and how code is converted during generation. The roles of semantics and code generation in allowing computers to understand and run programs are summarized.
1. Semantics & Code
Generation
By: Minh (1065432@cc.peralta.edu), Rayvonne (nonniejoelle@gmail.com), and Jose (josemanuelmata31@gmail.com)
CIS-5-40867-F22
2. Minh
FAMILY:
● My mom and dad, 3 sisters, and 1 brother.
OCCUPATION
● A full-time student in High School.
RECREATION
● Playing sports and videogames!
MISSION
● To live to 70 years old and be skilled at programing.
My Learning Style (According to the quiz)
1. 38% Auditory Learner
2. 33% Visual Learner
3. 29% Kinesthetic Learner
3. Rayvonne
FAMILY:
● I have 2 kids aged 11 and 5
OCCUPATION:
● I recycle old technology
RECREATION:
● Teaching myself to code/ learning new things
MISSION:
● To be the best mom I can be to my children
My Learning Style (According to the quiz)
1. 27% Auditory Learner
2. 42% Visual Learner
3. 31% Kinesthetic Learner
4. Jose
FAMILY:
● I have two sisters, two brothers, and eight nieces and nephews.
OCCUPATION:
● I am a Clerk at The Alameda County Probation Department.
RECREATION:
● I enjoy riding My Harley cross country, and i also enjoy working on it.
MISSION:
● My mission is to receive an Associates Degree, and continue on to my Bachelors.
My Learning Style(According to the Quiz)
1. 27% Auditory
2. 40% Visual Learner
3. 33% Kinesthetic Learner
5. A Brief History
1. The idea of semantics starts from 1690, with a Greek rendering of the term semiotics.
2. In 1922, the concept of semantics is brought up in mathematical logic to a group of scholars in
Poland.
3. In the 1960s, semantics for programming languages is brought up in publications by Robert W.
Floyd and Tony Hoare and they coined that a semantics chief application is to verify computer
programs. Tony Hoare brought up axiomatic semantics.
4. Later, in the 1970s, the terms operational semantics and denotational semantics emerged.
As for Code Generation, research into code generation process sought to build a truly automatic compiler-writing system and the effort designed
the BLISS-11 compiler.
● It was developed to handle language specific constructs and the research project investigated techniques of automated compiler
construction. The design concepts proved useful in optimizing compilers and compilers for the (since 1995, object-oriented) programming
language Ada.
6. Trend of
Semantics and
Code Generation
● Recently, researchers have combined Semantics
and Data as they look to take AI to the next level.
● ‘The Semantic Web‘ paper described a new way to
use and search on the Internet. It says that while a
human can read the text of an HTML web page, a
computer/search engine cannot.
● The World Wide Web needs a human, while the
Semantic Web does not. It uses the “hidden,”
encoded data and natural languages, to search
for, compile, and organize information from the
web. The Semantic Web needs a human only to
initiate the request.
● The World Wide Web is described as a web of
linked “documents,” while Linked Data describes a
web of linked “data.” Linked Data gives computers
a way to bring data and information together in
many complex ways.
● Code Generation has gotten better and better as
time progressed with new technology allowing for
faster and more efficient compilers.
How has it been used and has it
changed?
7. What are Semantics?
● Semantics refers to the meaning of the syntax of the
computer language
● Syntax are rules that define the combination of symbols
that are correctly structured statements in the language
● The meaning of the syntax refers to data or the action
attached to the code itself
● The image show examples of MEANINGFUL and
MEANINGLESS syntax
8. Semantic Records
● During Semantic Analyzation, the compiler must determine
the data types of certain expressions like a + b.
● They use a semantic record, which is a data structure that
stores information about a nonterminal, such as the actual
name of the object that it represents and its data type.
● Nonterminal symbols are those symbols that can be
replaced. They may also be called simply syntactic variables.
This example shows a variable: CH
● The SEMANTIC RECORD
stores the variable name and
its associated type: char
9. The Semantic Analyzation Process (p.1)
● The first part of code generation is the Semantic Analysis.
● The compiler takes a first pass through the parse tree and
using the Semantic Records it determines whether all
branches are semantically valid.
● If the data is determined meaningful the compiler can
generate machine language instructions through Code
Generation.
● If the data is not meaningful, i.e trying to add an integer
with a character, the compiler will throw an error.
This parse tree shows an expression of addition where the
semantic record has determined the data in each variable is
real, therefore it will generate machine language
instructions.
10. The Semantic Analyzation Process (p.2)
In the example to the right, it shows a parse tree during the
analyzation process where it has determined the data to be
un-meaningful.
Using the semantic record, it compared the entire expression to
the variables used and the data inside the variables
The compiler determined the whole expression as addition so
now it checks for the variables and the correct data.
Its determined not meaningful when it realizes variable B
contains a character value instead of an integer. Therefore, the
expression cannot be processed so no machine language code is
generated.
11. What is Code Generation?
● After the semantic analysis, the compiler makes a
second pass over the parse tree to produce the
translated machine language code.
● Each branch of the parse tree represents an action, a
transformation of one or more grammatical objects
into other grammatical objects.
● The compiler must determine how that
transformation can be accomplished in machine
language. This pass is called code generation.
In this example, on the parse tree, y (a
variable), is stored in code as: Y: .DATA 0
12. Analyzing Code
● The Code shown represents the idea of Semantic Analyzation.
● It creates “data” that contains random words and random
numbers.
● It then sorts the “data” into meaningful and un-meaningful and
only keeps meaningful data in a separate list.
● The separate list containing meaningful data is then finally
used for the addition operation.
*The code works because each VARIABLE IS DEFINED and rendered
meaningful to performing the operation.
13. Summary
● Semantics are a big part of compilers and their ability to distinguish
meaningful code from meaningless code through Semantic Anaylsis.
● Code Generation allows computers to execute code because of their
ability to transfer code into machine language that can be easily read by
a machine.
● Both play an important role in allowing computer to understand and
execute what we want them to do.
14. Sources (p.1)
● Gersting, Judith, and G.Michael Schneider. Invitation to Computer Science. Cengage Learning, 2019. Accessed 4 December 2022.
● “Semantics.” Wikipedia, https://en.wikipedia.org/wiki/Semantics. Accessed 4 December 2022.
● “Syntax (programming languages).” Wikipedia, https://en.wikipedia.org/wiki/Syntax_(programming_languages). Accessed 4 December 2022.
● “Code generation (compiler).” Wikipedia, https://en.wikipedia.org/wiki/Code_generation_(compiler). Accessed 3 December 2022.
● “Semantics (computer science).” Wikipedia, https://en.wikipedia.org/wiki/Semantics_(computer_science). Accessed 3 December 2022.
● “Compiler.” Wikipedia, https://en.wikipedia.org/wiki/Compiler. Accessed 3 December 2022.
● “Terminal and nonterminal symbols.” Wikipedia, https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols. Accessed 3 December 2022.
15. Sources (p.2)
● Foote, Keith D. “A Brief History of Semantics - DATAVERSITY.” Dataversity, 12 May 2016, https://www.dataversity.net/brief-history-semantics/.
Accessed 3 December 2022.
● “Code Generation | What Is, Purpose, Types, Examples, Summary.” Teach Computer Science, https://teachcomputerscience.com/code-generation/.
Accessed 3 December 2022.
● Wolff, Rachel. “Semantic Analysis, Explained.” MonkeyLearn, 12 August 2020, https://monkeylearn.com/blog/semantic-analysis/. Accessed 3
December 2022.
● Kanade, Vijay. “Semantic Features Analysis Definition, Examples, Applications.” Spiceworks, 16 June 2022,
https://www.spiceworks.com/tech/artificial-intelligence/articles/what-is-semantic-analysis/#_002. Accessed 3 December 2022.
● “Code Generation | What Is, Purpose, Types, Examples, Summary.” Teach Computer Science, https://teachcomputerscience.com/code-generation/.
Accessed 3 December 2022.