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

For the following lexical specification: Give NFA and DFA Using your DFA, Implement a lexical analyzer...
For the following lexical specification: Give NFA and DFA Using your DFA, Implement a lexical analyzer using the state table approach shown in class • keywords: if wh pr • Identifiers. An identifier is a sequence of one or more letters • Integer literals. An integer literal is a sequence of one or more decimal digits. • Any of the following one- or two-character symbols: = ( ) { } / * - + < <= == != • Note...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
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?
Write a lex program that can identify each of the following tokens. The program should produce...
Write a lex program that can identify each of the following tokens. The program should produce a line for each token where the first word is token itself followed by the token type. • Identifiers: name of variables and functions (identifier name should be started by a letter followed by letters or digits and maximum eight characters in length). • Keywords: if, then, else, for, while, do, switch, case etc. • Numbers: integer, float (float number format that supports in...
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...
1. Be able to recognize specimens of Gymnosperms and Angiosperms 2. Be able to identify the...
1. Be able to recognize specimens of Gymnosperms and Angiosperms 2. Be able to identify the male and female gametophytes in the gymnosperm cones 3. Be able to label the basic parts of the alternation of generations of these groups 4. Within angiosperms, know the differences between monocots and dicots 5. Be able to identify the parts of the flower 6. Understand the process of double fertilization, AND the difference between pollination and fertilization
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT