Compiler Presentation Flashcards
The four parts of how a compiler works:
Lexer, Parser, Code generator, Optimization
Lexer
First part of compiler
Reads the entire source code
One character at a time
Parser
Second part of compiler
Converts each token from the Lexer into a “node” on a syntax tree
Code generator
Third part of compiler
translates nodes into machine language
Code optimizer
Fourth part of compiler
Inspects code produced by the code generator
looks for redundancies
Interpreter vs Compiler
Interpreter translates each statement line by line, compiler translates the entire thing, then runs
DOS command to see how many files are in a particular directory
> dir
Interpreter vs Compiler
Interpreter translates code line by line
Compiler translates the source code into an executable file, that the computer then runs without an interpreter
A software interpreter is a computer program that performs instructions that are written in a _____________ (_______ ____) or _________ (_____ _____) language
programming (batch file) or scripting (Linux shell) language
The area of memory that the interpreter creates when you run a file is called
The offset
Interpreters read each line of the file, comparing the _____ ____ in the line to a list of commands
first word
Unlike other interpreters, _____ can handle a ________ as the first word in a line
BASIC, variable
in a BASIC program, the interpreter will generate an error if the first word is not a _______ or a _________
command or a variable
in a batch file, the interpreter will look for ____, ____ or ____ if the first word of a line is not found
.com, .bat, or .exe
Commands or variables that are valid are turned into ______
tokens
Tokens are an abbreviation for
the instructions that get passed on to the CPU to execute
If the commands/variables are not valid, or they perform a forbidden action, the interpreter will generate
a syntax error
These commands CAN interrupt the interpreters usual processing pattern
GOTO and IF
Compiler’s Lexical analysis
Reads individual characters and tries to assemble them into computer commands or punctuation characters that it can understand
When the scanner comes across an interpretable word or punctuation mark
it generates a token
When the scanner finds a string of numeric characters it
converts the string into an int, then converts the int into a token
In the parser, each node on the syntax tree __________ a __________ _________ that generates data or an instruction
represents a program operation
In the parser, each node
passes instructions to the node above it
When the parser is finished, the entire program will have been converted into a
tree
The top most node in the parser is called the _______, and the nodes that pass results to it are _______ _, _______ _
Program, routine 1, routine 2