Noad
Noad
Lexical structure defines the vocabulary of a language, including the basic building blocks such as
keywords, operators, identifiers, literals, and comments.
Python
using '+'
• Identifiers: x, y, print
• Keywords: print
• Operators: =, +
• Literals: 10, 5
Syntactic structure defines the grammar rules for forming valid statements and expressions using
the lexical units.
Example (Python):
python
Copy code
print("Non-positive")
The syntax rules ensure that constructs like if statements and blocks are correctly
Contextual structure refers to the rules that go beyond syntax, including variable
declarations and scope rules. It ensures that variables are declared before use and that
Example (Python):
python
Copy code
def add(a, b): # function 'add' with parameters 'a' and 'b'
return a + b
print(result)
expressions. It involves type checking, data type compatibility, and other rules that ensure
Example (Python):
python
Copy code
• Semantic Error: Adding a string (x) and an integer (10) causes a type error.
Lexical Structure
• Advantages:
tokens.
o Error Detection: Catches errors like illegal characters early.
• Disadvantages:
Syntactic Structure
• Advantages:
• Disadvantages:
Contextual Structure
• Advantages:
• Disadvantages:
Semantic Structure
• Advantages:
• Disadvantages:
Programming Languages
Imperative programming focuses on how to execute, defining the steps that change the
Copy code
int main() {
int a = 5;
int b = 10;
int sum = a + b;
return 0;
• Advantages:
• Disadvantages:
OOP organizes code into objects containing data and methods, emphasizing classes,
python
Copy code
class Dog:
self.name = name
def bark(self):
dog = Dog("Buddy")
dog.bark()
• Advantages:
• Disadvantages:
3. Declarative Programming
rather than how to achieve it, expressing the logic of computation without describing its
control flow.
sql
Copy code
• Advantages:
• Disadvantages:
haskell
Copy code
factorial 0 = 1
factorial n = n * factorial (n - 1)
• Advantages:
• Disadvantages: