bnf of c switch statement

i i
i iEnvironmental Services Professional at house
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;
}
1 of 6

Recommended

Form using html and java script validation by
Form using html and java script validationForm using html and java script validation
Form using html and java script validationMaitree Patel
1.4K views30 slides
Internet programming lab manual by
Internet programming lab manualInternet programming lab manual
Internet programming lab manualinteldualcore
8.2K views27 slides
Frames tables forms by
Frames tables formsFrames tables forms
Frames tables formsnobel mujuji
2.3K views27 slides
PHP variables by
PHP  variablesPHP  variables
PHP variablesSiddique Ibrahim
5.4K views46 slides
Web design - Applications and web application definition by
Web design - Applications and web application definitionWeb design - Applications and web application definition
Web design - Applications and web application definitionMustafa Kamel Mohammadi
3.7K views43 slides

More Related Content

What's hot

Tutorial: Develop an App with the Odoo Framework by
Tutorial: Develop an App with the Odoo FrameworkTutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo FrameworkOdoo
495 views52 slides
Javascript 101 by
Javascript 101Javascript 101
Javascript 101Shlomi Komemi
2.2K views32 slides
Fórmula visual rm totvs by
Fórmula visual rm totvsFórmula visual rm totvs
Fórmula visual rm totvsTiago Henrique Ribeiro Ferreira
2.9K views63 slides
Introduction to web programming with JavaScript by
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScriptT11 Sessions
1.4K views37 slides
Web Technology Lab File by
Web Technology Lab FileWeb Technology Lab File
Web Technology Lab FileKandarp Tiwari
10.6K views21 slides
Web Technology Lab files with practical by
Web Technology Lab  files with practicalWeb Technology Lab  files with practical
Web Technology Lab files with practicalNitesh Dubey
2.7K views39 slides

What's hot(20)

Tutorial: Develop an App with the Odoo Framework by Odoo
Tutorial: Develop an App with the Odoo FrameworkTutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo Framework
Odoo495 views
Introduction to web programming with JavaScript by T11 Sessions
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions1.4K views
Web Technology Lab File by Kandarp Tiwari
Web Technology Lab FileWeb Technology Lab File
Web Technology Lab File
Kandarp Tiwari10.6K views
Web Technology Lab files with practical by Nitesh Dubey
Web Technology Lab  files with practicalWeb Technology Lab  files with practical
Web Technology Lab files with practical
Nitesh Dubey2.7K views
Human Factors and User Interface Design by SaggitariusArrow
Human Factors and User Interface DesignHuman Factors and User Interface Design
Human Factors and User Interface Design
SaggitariusArrow6K views
Event In JavaScript by ShahDhruv21
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv213.2K views
HCI 3e - Ch 4: Paradigms by Alan Dix
HCI 3e - Ch 4:  ParadigmsHCI 3e - Ch 4:  Paradigms
HCI 3e - Ch 4: Paradigms
Alan Dix4.7K views
SQL querys in detail || Sql query slides by gourav kottawar
SQL querys in detail || Sql query slidesSQL querys in detail || Sql query slides
SQL querys in detail || Sql query slides
gourav kottawar644 views
SQL Tutorial - How To Create, Drop, and Truncate Table by 1keydata
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata2.4K views
Html events with javascript by YounusS2
Html events with javascriptHtml events with javascript
Html events with javascript
YounusS2371 views
JavaScript - Chapter 10 - Strings and Arrays by WebStackAcademy
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy1.7K views
The lazy programmer's guide to writing thousands of tests by Scott Wlaschin
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
Scott Wlaschin912 views
Javascript Arrow function by tanerochris
Javascript Arrow functionJavascript Arrow function
Javascript Arrow function
tanerochris857 views

More from i i

Bouncing circle by
Bouncing circleBouncing circle
Bouncing circlei i
528 views5 slides
0-1 KNAPSACK PROBLEM by
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEMi i
1.5K views15 slides
sequential and combinational circuits exam by
sequential and combinational circuits examsequential and combinational circuits exam
sequential and combinational circuits exami i
236 views9 slides
hypothesis testing overview by
hypothesis testing overviewhypothesis testing overview
hypothesis testing overviewi i
631 views32 slides
x86 architecture by
x86 architecturex86 architecture
x86 architecturei i
2.7K views42 slides
boolean algebra exercises by
boolean algebra exercisesboolean algebra exercises
boolean algebra exercisesi i
3.5K views8 slides

More from i i(15)

Bouncing circle by i i
Bouncing circleBouncing circle
Bouncing circle
i i528 views
0-1 KNAPSACK PROBLEM by i i
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
i i1.5K views
sequential and combinational circuits exam by i i
sequential and combinational circuits examsequential and combinational circuits exam
sequential and combinational circuits exam
i i236 views
hypothesis testing overview by i i
hypothesis testing overviewhypothesis testing overview
hypothesis testing overview
i i631 views
x86 architecture by i i
x86 architecturex86 architecture
x86 architecture
i i2.7K views
boolean algebra exercises by i i
boolean algebra exercisesboolean algebra exercises
boolean algebra exercises
i i3.5K views
database normalization case study by i i
database normalization case studydatabase normalization case study
database normalization case study
i i568 views
cpbricks context diagram by i i
cpbricks context diagramcpbricks context diagram
cpbricks context diagram
i i504 views
cpbricks project document by i i
cpbricks project documentcpbricks project document
cpbricks project document
i i90 views
cpbricks manual by i i
cpbricks manualcpbricks manual
cpbricks manual
i i85 views
imperative programming language, java, android by i i
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
i i191 views
shortest job first by i i
shortest job firstshortest job first
shortest job first
i i1.8K views
designing reports by i i
designing reportsdesigning reports
designing reports
i i699 views
shell and merge sort by i i
shell and merge sortshell and merge sort
shell and merge sort
i i1.5K views
adders/subtractors, multiplexers, intro to ISA by i i
adders/subtractors, multiplexers, intro to ISAadders/subtractors, multiplexers, intro to ISA
adders/subtractors, multiplexers, intro to ISA
i i250 views

Recently uploaded

aATP - New Correlation Confirmation Feature.pptx by
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptxEsatEsenek1
222 views6 slides
Quality Engineer: A Day in the Life by
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the LifeJohn Valentino
10 views18 slides
How Workforce Management Software Empowers SMEs | TraQSuite by
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteTraQSuite
7 views3 slides
Understanding HTML terminology by
Understanding HTML terminologyUnderstanding HTML terminology
Understanding HTML terminologyartembondar5
8 views8 slides
Electronic AWB - Electronic Air Waybill by
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill Freightoscope
6 views1 slide
Techstack Ltd at Slush 2023, Ukrainian delegation by
Techstack Ltd at Slush 2023, Ukrainian delegationTechstack Ltd at Slush 2023, Ukrainian delegation
Techstack Ltd at Slush 2023, Ukrainian delegationViktoriiaOpanasenko
7 views4 slides

Recently uploaded(20)

aATP - New Correlation Confirmation Feature.pptx by EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1222 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino10 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite7 views
Understanding HTML terminology by artembondar5
Understanding HTML terminologyUnderstanding HTML terminology
Understanding HTML terminology
artembondar58 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 6 views
Mobile App Development Company by Richestsoft
Mobile App Development CompanyMobile App Development Company
Mobile App Development Company
Richestsoft 5 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 views
Automated Testing of Microsoft Power BI Reports by RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS11 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom16 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino8 views

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