0% found this document useful (0 votes)
10 views3 pages

Abdo Sharaf - Compilers Task 3

Uploaded by

Ahmed abd elbaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Abdo Sharaf - Compilers Task 3

Uploaded by

Ahmed abd elbaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Compilers

Dr. Heba El Hadidy

Task (3) – Parsing & Errors


‫ – علوم الحاسب‬802320061 – ‫عبد الحميد رأشف رشف‬

Write an example of Top-Down Parsing.


Suppose this is our grammar:
• S -> aAAb
• A -> cB | c
• B -> c | d
We will use this input “acdcb”. Now, we will follow these steps:
• Expand “S” to “aAAb”. => “aAAb”
• Expand the first “A” to “cB” and the second “A” to “c”. => “acBcb”
• Expand “B” to “d”. => “acdcb”
• We reached our goal!
Write some error examples.
Syntax Error:
• Syntax errors occur when the code violates the language's rules for writing correct
syntax.
• Example: print("Hello, world!"
o The closing parenthesis is missing, causing a syntax error.

Runtime Error:
• Runtime errors occur during program execution and typically indicate issues such
as division by zero, accessing an index out of range, or using variables before they
are initialized.
• Example:
x=5
y=0
print(x/y)
o Division by zero.

Logical Error:
• Logical errors occur when the code executes without errors but does not produce
the expected result due to incorrect logic or algorithmic mistakes.
• Example:
def calculate_average(a, b):
return (a + b) / 2
print(calculate_average(5, 10)) # gives 7 not 7.5
o The average formula (a + b) / 2 is incorrect; it should be (a + b) / 2.0 to get
the correct floating-point result.

Lexical Error:
• Lexical errors occur during the process of lexing or tokenizing when the lexer
encounters characters or sequences of characters that do not conform to the
syntax rules of the programming language.
• Example: a = @ # not valid in Python

You might also like