(DOCX, Unknown)

advertisement
Lexical and Syntax Analysis
What is Lexical and Syntax Analysis and what is the difference between them?
PARSE 1
Lexical analysis – When a compiler checks the
code for any spelling errors that have been
made for keywords of the programming
language. The compiler has a table of
acceptable keywords that it refers to in order
to see whether or not the word has been
spelt correctly and can be accepted.
For Example if the programmer wrote
Whiteline instead of Writeline the compiler
would take that as an error.
PARSE 2
Syntax Analysis – This is where the
compiler checks through the code for
any misuse of symbols and characters
in the code all to do with the grammar
of the language. So if the programmer
had not entered a colon where it was
expected the compiler would report an
error.
For example if the programmer wrote “””Louis” where the correct is “Louis”
then the compiler would report an error.
Main Features of Code Generation
PARSE 3
Code generation is when the source code is translated into low level code like
binary numbers for the computer to execute. This is known as the one to many
process as one line of high level source code can equate to several lines of low
level code. This means the program will often turn out a lot longer in the
executable file that is created.
Main Features of Code Optimisation
PARSE 4
Code optimisation is when the compiler goes
through all of the now translated code in order to
make it as efficient as possible for the processor.
This means removing all the extras that are added
to the code to make it easier for programmers to
understand like Indentation, Spaces and notation.
The computer does not need these extras as it
already understand the code without them. This
also helps to reduce the executable file size in turn.
This is often done during code generation.
Parses?
Parses are the different stages that the compiler goes through every time it
needs to translate the code.
Download