Question

In: Computer Science

For an example BNF grammar, be able to identify the tokens which a lexical analyzer would...

For an example BNF grammar, be able to identify the tokens which a lexical analyzer would be able to produce.

For an example BNF grammar, and a list of tokens, construct a state diagram of the language’s lexical analyzer.

Solutions

Expert Solution

solution:

given data:

For an example BNF grammar:

Context free grammar(CFG) is a set of rules G(N,T,P,S) . It can be used to generate patterns of strings.

G(N,T,P,S)

Where N is set of non terminal symbol

T is set of terminal symbol

P is set of production rules

S is non terminal start symbo

BNF(Backus Naur Form)grammar is a variation of context free grammer.

Syntax

Left hand side ::= Riht hand side

where

::= ->  is defined as

Left hand side -> Non terminal symbol

Riht hand side is a sequence of terminal and nonterminal symbols.

Non terminal symbols are enclosed in angular brackets <>

Example

Consider a BNF grammar for binary numbers with a leading1

<Start> :: 1<BinNum> //First rule nonterminal BinNum with a leading1

<BinNum>= <BinValue>|<BinValue><BinNum> //With 2 alternative and second alternative //is recursive

<BinValue>=0|1 //Terminal symbols 0,1

Valid inputs are

10

11001

1000011

Invalid inputs are

1

0011

011

Consider the above grammar which accepts a string of 0 and 1 starting with 1. A state diagrom is a directed graph with each state is represented by a node with a start state and incoming arrow with no source. Final state is represented by double lined node.

please give me thumb up


Related Solutions

1. Which of the following would be an example of maturation? A. A child is able...
1. Which of the following would be an example of maturation? A. A child is able to learn the multiplication tables after working with flashcards each night with his mother. B. A young boy practices the violin until he is able to play his recital piece without a mistake. C. A high school track star is able to cut a minute off of her best time in the mile from one year to the next. D. Every tired executive overcomes...
What key words or phrases would we be able to identify that would tell us which...
What key words or phrases would we be able to identify that would tell us which time value table to use?
In which of the following cases would you be able to predict with certainty the change...
In which of the following cases would you be able to predict with certainty the change in the equilibrium price? There is more than one answer to this question. You must mark all of the correct answers to receive full credit for this question. There is a decrease in demand. There is a decrease in demand and an increase in supply. There is an increase in demand and an increase in supply. There is an increase in supply. There is...
Which of the following is NOT an example of a transaction that would appear in the...
Which of the following is NOT an example of a transaction that would appear in the financing section of the statement of cash flows? Select one: a. Selling shares of common stock b. None of the above c. Payment of interest expense on note d. Repayment of principal amount of long-term note e. Purchasing treasury stock
Which of the following is NOT an example of a transaction that would appear in the...
Which of the following is NOT an example of a transaction that would appear in the financing section of the statement of cash flows? Select one: a. Repayment of principal amount of long-term note b. Payment of interest expense on note c. Selling shares of common stock d. Purchasing treasury stock e. None of the above
Using the NBS framework, identify an example of an innovation which illustrates:
Using the NBS framework, identify an example of an innovation which illustrates:–Operational optimization–Organizational transformation–Systems building
Identify which of the following would be studied as a part of microeconomics, and which would be studied as a part of macroeconomics.
Identify which of the following would be studied as a part of microeconomics, and which would be studied as a part of macroeconomics. You may do this quite briefly. Simply list the letters A thruJ - and write "micro" or "macro" next to each one. a- Costco b - The Bahamas c - International trade d - GDP (Gross Domestic Product) e - Danielle's Plumbing and Heating f- Debra's Chicken Wings and Soda Fountain g - Inflation h - The Red Cross i - A trip to the grocery...
51. Which of the following would be the best example of an environment(s) that would contribute...
51. Which of the following would be the best example of an environment(s) that would contribute to a client’s increased confusion: a) Poor lighting, and excessive noise b) Unfamiliar surroundings such as furniture and pictures c) Quiet music playing d) Both a and b a) Poor lighting, and excessive noise b) Unfamiliar surroundings such as furniture and pictures c) Quiet music playing d) Both a and b 52. Persons with acute confusion should be: a) Restrained or confined b) Given...
Which of the following would be an example of an alteration in drug effect because of...
Which of the following would be an example of an alteration in drug effect because of a pharmacodynamic change? Question 5 options: a) diminished response to the heart rate lowering effects of a beta blocker in older adults because numbers of beta1 receptors on the heart decrease as the heart ages b) increased response to a sedative medication because of decreased metabolism in a patient with alcohol-induced liver disease c) increased toxicity from a chemotherautic drug in an older adult...
Be able to identify valid and non-valid programmer-defined identifiers. Which header file do you need in...
Be able to identify valid and non-valid programmer-defined identifiers. Which header file do you need in order to use the cout and cin objects? Which header file do you need to create string variables? Be able to recognize the correct syntax to define a constant. Be able to recognize the correct syntax to store a character in a char variable. What must you have for every variable you use in a program? Program Given a program, be able to fill...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT