Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA please Consider the following EBNF grammar for a very simple programming language: program-S (statemt) statemt assnmt | ifstmt do | inout | progcall assnmt

JAVA please

image text in transcribed

image text in transcribed

Consider the following EBNF grammar for a very simple programming language: program-S (statemt) statemt assnmt | ifstmt do | inout | progcall assnmt -ident exprsn ; ifstmt ::- 1 comp r sn @ {statemt } [% {statemt] & :D (statemt U comprsn E inout iosym ident f, ident ; 1osym progcallC program G comprsn :: oprnd opratr oprnd ) exprsn :factor factorh factoroprnd * oprnd) oprnd integer | ident | bolexprsn) ident letter (char char := letter | digit integerdigit (digith digit bool The tokens are: S 1 D U E R O C GWXYZ01TF.~@%&,()+*=>! Nonterminals are shown as lowercase words. The following characters are NOT tokens (they are EBNF metasymbols): Note that parentheses are TOKENS, not EBNF metasymbols in this particular grammar. Implement a recursive-descent recognizer: Prompt the user for an input stream The user enters an input stream of legal tokens, followed by a $ - You can assume: the user enters no whitespace, the user only enters legal tokens listed above, the user enters one and only one $, at the end The start symbol is *program (as defined above) - Your program should output "legal" or "errors found" (not both! You can report additional information as well, if you want. For example, knowing where your program finds an error could be helpful for me to assign partial credit if it's wrong - Assume the input stream is the TOKEN stream. Assume that any whitespace has already been stripped out by the lexical scanner (i.e., each token is one character - 1exical scanning has been completed) Since the incoming token stream is terminated with a $, you will need to add the to the grammar and incorporate it in your answers to questions #1 and #2 above, where appropriate. - Use Java, C, or C++ or ask your instructor if you wish to use another language. Limit your source code to ONE file. Consider the following EBNF grammar for a very simple programming language: program-S (statemt) statemt assnmt | ifstmt do | inout | progcall assnmt -ident exprsn ; ifstmt ::- 1 comp r sn @ {statemt } [% {statemt] & :D (statemt U comprsn E inout iosym ident f, ident ; 1osym progcallC program G comprsn :: oprnd opratr oprnd ) exprsn :factor factorh factoroprnd * oprnd) oprnd integer | ident | bolexprsn) ident letter (char char := letter | digit integerdigit (digith digit bool The tokens are: S 1 D U E R O C GWXYZ01TF.~@%&,()+*=>! Nonterminals are shown as lowercase words. The following characters are NOT tokens (they are EBNF metasymbols): Note that parentheses are TOKENS, not EBNF metasymbols in this particular grammar. Implement a recursive-descent recognizer: Prompt the user for an input stream The user enters an input stream of legal tokens, followed by a $ - You can assume: the user enters no whitespace, the user only enters legal tokens listed above, the user enters one and only one $, at the end The start symbol is *program (as defined above) - Your program should output "legal" or "errors found" (not both! You can report additional information as well, if you want. For example, knowing where your program finds an error could be helpful for me to assign partial credit if it's wrong - Assume the input stream is the TOKEN stream. Assume that any whitespace has already been stripped out by the lexical scanner (i.e., each token is one character - 1exical scanning has been completed) Since the incoming token stream is terminated with a $, you will need to add the to the grammar and incorporate it in your answers to questions #1 and #2 above, where appropriate. - Use Java, C, or C++ or ask your instructor if you wish to use another language. Limit your source code to ONE file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions