SlideShare a Scribd company logo
2
Most read
3
Most read
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;}
bnf of c switch statement
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

PPTX
2D Array
DOC
3963066 pl-sql-notes-only
PPTX
Variable and constants in Vb.NET
PPTX
PHP FUNCTIONS
PPT
Architecture of .net framework
PPTX
Union in c language
PPT
Structure in C
PPT
Graphical User Interface in JAVA
2D Array
3963066 pl-sql-notes-only
Variable and constants in Vb.NET
PHP FUNCTIONS
Architecture of .net framework
Union in c language
Structure in C
Graphical User Interface in JAVA

What's hot (20)

PPT
UML Diagrams
PPT
Layered Architecture
PPTX
Fundamentals of database system - Relational data model and relational datab...
PDF
OpenCL 3.0 Reference Guide
PPTX
Java servlets
PPTX
Chapter 3 servlet & jsp
PPTX
Strings in Java
PDF
Command line-arguments-in-java-tutorial
PPT
Object Oriented Programming In .Net
PDF
UNIFIED MODELING LANGUAGE
PPTX
Pointers in C Programming
PDF
Python programming : Control statements
PPT
PPT
PPTX
Integrating Public & Private Clouds
PPTX
Files and streams In Java
PPTX
Android share preferences
PPTX
UML Diagrams
Layered Architecture
Fundamentals of database system - Relational data model and relational datab...
OpenCL 3.0 Reference Guide
Java servlets
Chapter 3 servlet & jsp
Strings in Java
Command line-arguments-in-java-tutorial
Object Oriented Programming In .Net
UNIFIED MODELING LANGUAGE
Pointers in C Programming
Python programming : Control statements
Integrating Public & Private Clouds
Files and streams In Java
Android share preferences
Ad

Similar to bnf of c switch statement (20)

PPTX
Presentation1
PPTX
Presentttttttss
PPT
My programming final proj. (1)
PDF
Fundamentals of programming)
PPTX
Switch.pptx
PDF
CP Handout#6
PPTX
Final project powerpoint template (fndprg) (1)
PPT
4b C switch structure .ppt
PDF
Principals of Programming in CModule -5.pdfModule_2_P2 (1).pdf
PPTX
Final requirement
PPTX
C Unit-2.ppt
PPTX
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
PPSX
Ramirez slideshow
PPTX
C PROGRAMMING p-3.pptx
PPTX
Control Structures.pptx
PDF
22 Jop Oct 08
PDF
POP Unit 2.pptx.pdf for your time and gauss with example
PDF
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
PPTX
C Programming Language Step by Step Part 5
PPTX
C Programming Language Part 5
Presentation1
Presentttttttss
My programming final proj. (1)
Fundamentals of programming)
Switch.pptx
CP Handout#6
Final project powerpoint template (fndprg) (1)
4b C switch structure .ppt
Principals of Programming in CModule -5.pdfModule_2_P2 (1).pdf
Final requirement
C Unit-2.ppt
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Ramirez slideshow
C PROGRAMMING p-3.pptx
Control Structures.pptx
22 Jop Oct 08
POP Unit 2.pptx.pdf for your time and gauss with example
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
C Programming Language Step by Step Part 5
C Programming Language Part 5
Ad

More from i i (15)

DOCX
Bouncing circle
 
DOCX
0-1 KNAPSACK PROBLEM
 
DOCX
sequential and combinational circuits exam
 
PPTX
hypothesis testing overview
 
PPTX
x86 architecture
 
PDF
boolean algebra exercises
 
PPTX
database normalization case study
 
DOC
cpbricks context diagram
 
DOC
cpbricks project document
 
DOC
cpbricks manual
 
PPTX
imperative programming language, java, android
 
PPTX
shortest job first
 
PPTX
designing reports
 
PPTX
shell and merge sort
 
PPTX
adders/subtractors, multiplexers, intro to ISA
 
Bouncing circle
 
0-1 KNAPSACK PROBLEM
 
sequential and combinational circuits exam
 
hypothesis testing overview
 
x86 architecture
 
boolean algebra exercises
 
database normalization case study
 
cpbricks context diagram
 
cpbricks project document
 
cpbricks manual
 
imperative programming language, java, android
 
shortest job first
 
designing reports
 
shell and merge sort
 
adders/subtractors, multiplexers, intro to ISA
 

Recently uploaded (20)

PPTX
Essential Infomation Tech presentation.pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
AI in Product Development-omnex systems
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
medical staffing services at VALiNTRY
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Odoo POS Development Services by CandidRoot Solutions
Essential Infomation Tech presentation.pptx
Softaken Excel to vCard Converter Software.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Digital Strategies for Manufacturing Companies
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Which alternative to Crystal Reports is best for small or large businesses.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
AI in Product Development-omnex systems
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
medical staffing services at VALiNTRY
Odoo Companies in India – Driving Business Transformation.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Odoo POS Development Services by CandidRoot Solutions

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;}
  • 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; }