0% found this document useful (0 votes)
5 views

compiler1

The document discusses computer language representation, covering low-level and high-level languages, their syntax and semantics, and the differences between compiled and interpreted languages. It also addresses data representation, control structures, abstraction layers, domain-specific languages, and tools for language processing. Additionally, it outlines a typical workflow for compiling a C program from source code to executable.

Uploaded by

alula girma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

compiler1

The document discusses computer language representation, covering low-level and high-level languages, their syntax and semantics, and the differences between compiled and interpreted languages. It also addresses data representation, control structures, abstraction layers, domain-specific languages, and tools for language processing. Additionally, it outlines a typical workflow for compiling a C program from source code to executable.

Uploaded by

alula girma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Computer Language Representation

• Refers to the way programming languages and data are structured and interpreted by both humans
and machines.
• 1. Low-Level vs. High-Level Languages
• Low-Level Languages:
o Machine Code: Binary instructions (0s and 1s) directly executed by the CPU.
o Assembly Language: Human-readable mnemonics (e.g., MOV, ADD) that map to machine code.
Requires an assembler to translate.
• High-Level Languages (e.g., Python, Java, C++):
o Abstracted from hardware, focusing on readability and productivity.
o Require compilers or interpreters to convert code into machine-executable form.
• 2. Language Syntax and Semantics
• Syntax: Rules governing code structure (e.g., grammar, punctuation).
• Semantics: Meaning of the code (e.g., how loops or functions behave).
• 3. Compiled vs. Interpreted Languages

• Compiled Languages (e.g., C, Go):


o Translated entirely to machine code before execution (via a compiler).
o Faster execution but platform-dependent.

• Interpreted Languages (e.g., Python, JavaScript):


o Executed line-by-line by an interpreter at runtime.
o Platform-independent but slower.

• 4. Intermediate Representations (IR)

• Used by compilers/interpreters to optimize code before generating machine code.

• Examples:
o Bytecode (e.g., Java JVM, Python .pyc): Portable intermediate code.
o LLVM IR: A universal IR for optimization across languages.
• 5. Data Representation

• Primitive Data Types: Integers, floats, characters, booleans.

• Composite Types: Arrays, structs, objects.

• Memory Addressing: How data is stored (e.g., big-endian vs. little-endian).

• 6. Control Structures

• Sequential Execution: Code runs line-by-line.

• Conditionals: if-else, switch statements.

• Loops: for, while, do-while.


• 7. Abstraction Layers

• Hardware Abstraction: Operating systems manage hardware interactions.

• APIs/Libraries: Pre-written code for common tasks (e.g., math functions).

• Virtual Machines (e.g., JVM, CLR): Execute intermediate code across platforms.

• 8. Domain-Specific Languages (DSLs)

• Tailored for specific tasks (e.g., SQL for databases, HTML/CSS for web design).

• 9. Formal Language Theory

• Regular Expressions: Pattern matching in text.

• Context-Free Grammars: Describe programming language syntax (e.g., BNF notation).


• 10. Tools for Language Processing

• Lexers: Break code into tokens (e.g., keywords, operators).

• Parsers: Analyze token structure against grammar rules.

• Optimizers: Improve code efficiency (e.g., removing redundancies).

• Example Workflow (C Program):

1. Source Code: main.c (high-level code).

2. Compiler: Translates to assembly (main.s).

3. Assembler: Converts assembly to machine code (main.o).

4. Linker: Combines object files into an executable (a.out).


Compiler construction tools
Q&A

You might also like