SlideShare a Scribd company logo
1 of 6
BNF OF C-SWITCHSTATEMENT
<switch_stmnt>-> switch (<int_exp>) {<case_list>}
<int_exp> -> <int_exp>+ <exp> |
<int_exp>- <exp> |
<int_exp>& <exp>|
<int_exp>| <exp>|
<int_exp>>> <exp>|
<int_exp><< <exp>|
<exp>
<exp> -> <exp>* <term > |
<exp>/ <term> |
<term >
<term > -> (<int_exp>) |
<num_exp>|
- <term> |
^<term>
<num_exp> -> <int_id>|
<int_const>
<int_id> -> [a-zA-Z_] |
<int_id>[a-zA-Z0-9_]
<int_const> -> [0-9] |
<int_const> [0-9] |
- <int_const>
<case_list> -> <case_line>|
<case_line><case_list>|
<case_list><default_line>
<case_line> -> case <int_const>: <stmnt_list>
<default_line> -> default: <stmnt_list>
<stmnt_list> -> |
<stmnt> |
<stmnt> <stmnt_list>|
<stmnt_list>break;
<stmnt> -> statement<count>;
<count> -> [0-9] |
[0-9] <count>
Example:
intx;
switch(x)
{
case 1:
statement1;
break;
case 2:
statement2;
break;
default:
statement3;
}
Derivation:
<switch_stmnt>=>switch ( <int_exp> ) { <case_list> }
=>switch ( <exp> ) { <case_list> }
=>switch ( <term> ) { <case_list> }
=>switch ( <num_exp> ) { <case_list> }
=>switch ( <int_id> ) { <case_list> }
=>switch ( x ) { <case_list> }
=>switch ( x ) { <case_line><case_line><default_line> }
=>switch ( x ) { case <int_const>:<stmnt_list><case_line><default_line> }
=>switch ( x ) { case 1: <stmnt_list><case_line><default_line> }
=>switch ( x ) { case 1: <stmnt>break; <case_line><default_line> }
=>switch ( x ) { case 1: statement<count>;break; <case_line><default_line> }
=>switch ( x ) { case 1: statement1;break; <case_line><default_line> }
=>switch ( x ) { case 1: statement1;break; case <int_const>:<stmnt_list><default_line> }
=>switch ( x ) { case 1: statement1;break; case 2:<stmnt_list><default_line> }
=>switch ( x ) { case 1: statement1;break; case 2:<stmnt>break;<default_line> }
=>switch ( x ) { case 1: statement1;break; case 2:statement<count>;break;<default_line> }
=>switch ( x ) { case 1: statement1;break; case 2:statement2;break;<default_line> }
=>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:<stmnt_list }
=>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:<stmnt>}
=>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:statement<count>;}
=>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:statement3;}
Parse Tree:
Crazy example:
int a, b, c;
switch((a*b)+c)>>9)
{
case 0:
case 1:
statement 2;
break;
case 2:
statement3;
break;
default:
statement4;
statement5;
}

More Related Content

What's hot

USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
vicci4041
 

What's hot (20)

Cocomo model
Cocomo modelCocomo model
Cocomo model
 
Web Technology Lab File
Web Technology Lab FileWeb Technology Lab File
Web Technology Lab File
 
BNF & EBNF
BNF & EBNFBNF & EBNF
BNF & EBNF
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
user support system in HCI
user support system in HCIuser support system in HCI
user support system in HCI
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Visual Basic(Vb) practical
Visual Basic(Vb) practicalVisual Basic(Vb) practical
Visual Basic(Vb) practical
 
JavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGIJavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGI
 
System Analysis and Design 6th edition chapter 14
System Analysis and Design 6th edition chapter 14System Analysis and Design 6th edition chapter 14
System Analysis and Design 6th edition chapter 14
 
Software process
Software processSoftware process
Software process
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Python idle introduction(3)
Python idle introduction(3)Python idle introduction(3)
Python idle introduction(3)
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
 
Software myths | Software Engineering Notes
Software myths | Software Engineering NotesSoftware myths | Software Engineering Notes
Software myths | Software Engineering Notes
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 

More from i i (15)

Bouncing circle
Bouncing circleBouncing circle
Bouncing circle
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
sequential and combinational circuits exam
sequential and combinational circuits examsequential and combinational circuits exam
sequential and combinational circuits exam
 
hypothesis testing overview
hypothesis testing overviewhypothesis testing overview
hypothesis testing overview
 
x86 architecture
x86 architecturex86 architecture
x86 architecture
 
boolean algebra exercises
boolean algebra exercisesboolean algebra exercises
boolean algebra exercises
 
database normalization case study
database normalization case studydatabase normalization case study
database normalization case study
 
cpbricks context diagram
cpbricks context diagramcpbricks context diagram
cpbricks context diagram
 
cpbricks project document
cpbricks project documentcpbricks project document
cpbricks project document
 
cpbricks manual
cpbricks manualcpbricks manual
cpbricks manual
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
shortest job first
shortest job firstshortest job first
shortest job first
 
designing reports
designing reportsdesigning reports
designing reports
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sort
 
adders/subtractors, multiplexers, intro to ISA
adders/subtractors, multiplexers, intro to ISAadders/subtractors, multiplexers, intro to ISA
adders/subtractors, multiplexers, intro to ISA
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 

bnf of c switch statement

  • 1. BNF OF C-SWITCHSTATEMENT <switch_stmnt>-> switch (<int_exp>) {<case_list>} <int_exp> -> <int_exp>+ <exp> | <int_exp>- <exp> | <int_exp>& <exp>| <int_exp>| <exp>| <int_exp>>> <exp>| <int_exp><< <exp>| <exp> <exp> -> <exp>* <term > | <exp>/ <term> | <term > <term > -> (<int_exp>) | <num_exp>| - <term> | ^<term> <num_exp> -> <int_id>| <int_const> <int_id> -> [a-zA-Z_] | <int_id>[a-zA-Z0-9_] <int_const> -> [0-9] | <int_const> [0-9] | - <int_const> <case_list> -> <case_line>| <case_line><case_list>| <case_list><default_line> <case_line> -> case <int_const>: <stmnt_list> <default_line> -> default: <stmnt_list> <stmnt_list> -> | <stmnt> | <stmnt> <stmnt_list>| <stmnt_list>break; <stmnt> -> statement<count>; <count> -> [0-9] | [0-9] <count>
  • 3. Derivation: <switch_stmnt>=>switch ( <int_exp> ) { <case_list> } =>switch ( <exp> ) { <case_list> } =>switch ( <term> ) { <case_list> } =>switch ( <num_exp> ) { <case_list> } =>switch ( <int_id> ) { <case_list> } =>switch ( x ) { <case_list> } =>switch ( x ) { <case_line><case_line><default_line> } =>switch ( x ) { case <int_const>:<stmnt_list><case_line><default_line> } =>switch ( x ) { case 1: <stmnt_list><case_line><default_line> } =>switch ( x ) { case 1: <stmnt>break; <case_line><default_line> } =>switch ( x ) { case 1: statement<count>;break; <case_line><default_line> } =>switch ( x ) { case 1: statement1;break; <case_line><default_line> } =>switch ( x ) { case 1: statement1;break; case <int_const>:<stmnt_list><default_line> } =>switch ( x ) { case 1: statement1;break; case 2:<stmnt_list><default_line> } =>switch ( x ) { case 1: statement1;break; case 2:<stmnt>break;<default_line> } =>switch ( x ) { case 1: statement1;break; case 2:statement<count>;break;<default_line> } =>switch ( x ) { case 1: statement1;break; case 2:statement2;break;<default_line> } =>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:<stmnt_list } =>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:<stmnt>} =>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:statement<count>;} =>switch ( x ) { case 1: statement1;break; case 2:statement2;break;default:statement3;}
  • 4.
  • 6. Crazy example: int a, b, c; switch((a*b)+c)>>9) { case 0: case 1: statement 2; break; case 2: statement3; break; default: statement4; statement5; }