07-compilers-and-grammars

07-compilers-and-grammars - Language Translation: Compilers...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Language Translation: Compilers and Interpreters CSE 110: Introduction to Computer Science SUNY at Stony Brook
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Need for Translation • Computers (CPUs) only speak binary • People don’t speak binary well; we prefer high-level languages like Python • A compiler (or interpreter ) is a program that translates high-level languages into machine language (binary) • Real-world example: translators or interpreters at the United Nations
Background image of page 2
Compilers vs. Interpreters • Both perform the same basic function • A compiler translates an entire Fle/program at once • An interpreter translates and executes a program one line at a time • Python is interpreted • C is compiled • Java is both compiled AND interpreted
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Translation Process Source code Lexical Analyzer Parser Code Generator Executable
Background image of page 4
Translation Steps • Lexical analysis (“lexing”) • Identifes tokens (lexical units) • Parsing • Identifes the program’s “grammar” • Code generation • Creates machine code that corresponds to the parser output
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lexical Analysis • Uses regular expressions to identify different “parts of speech” • identiFers, keywords, numbers, etc. • Ex. [123456789][1234567890]* = number • This is like separating a sentence into individual words and categorizing each word according to its part of speech (noun, verb, adjective, etc.) • Computer languages (and thus compilers) are more interested in “parts of
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

07-compilers-and-grammars - Language Translation: Compilers...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online