refers to structure; like grammar in English
syntax
refers to meaning; what the words actually do
semantics
why does semantics matter?
to know what certain combinations of words mean
common misunderstandings in semantics (3)
refers to the actual code written
source program
breaks the source program into tokens (identifiers, keywords, operators)
lexical analyzer
another term for tokens
lexical units
checks grammar of tokens
syntax analyzer
the syntax analyzer produces __ representing valid statements
parse trees
stores information about variables, functions, and identifiers
symbol table
used across multiple phases of compilation
symbol table
why use a symbol table?
it helps the compiler remember what each symbol is
refers to when the compiler fills in the gaps of information that are not explicitly written by programmers
default conventions
checks for errors
semantic analyzer
shortcuts or templates; pieces of code that get substituted before compilation
macros
can package a function or a formula so the programmer doesn’t rewrite it every time and everywhere
macros
improves programs
optimization
the compiler tries to make the code better and faster before generating the final output
optimization
what can be optimized? (6)
compiler finds repeated expressions in a program and computes them only once
removing redundant work
save time by avoiding redundant calculations
common subexpression elimination
if the code never executes, compiler removes it
dead code elimination
eliminate unnecessary assignments and make code simpler and more efficient
copy propagation
take calculations out of loops if they don’t change
loop optimizations