Page 1 of 1

DO NOT COPY AND PASTE ANY ANSWER ON THIS SITE AS THE ANSWER TO THIS QUESTION SINCE NONE OF THEM USE RECURSIVE DESCENT. E

Posted: Thu May 05, 2022 12:53 pm
by answerhappygod
DO NOT COPY AND PASTE ANY ANSWER ON THIS SITE AS THE
ANSWER TO THIS QUESTION SINCE NONE OF THEM USE RECURSIVE
DESCENT.
Experts If you post an answer that is already on
this site, it doesn't use recursive descent and is therefore
wrong(I've checked almost all of them). If your answer involves
copying text found on this site and pasting it as an answer it
doesn't answer the basic requirement of the question posted.
RECURSIVE DESCENT has to be used and implemented. If your
answer has the word calculator in it or it makes a calculator, it
is wrong. Notice my question doesn't have that word in it. Please
READ the question carefully BEFORE answering. I am a little
upset because this is the third time I have asked the same
question and got the same wrong answer the previous two
times.
DO NOT COPY AND PASTE ANY ANSWER ON THIS SITE AS THE
ANSWER TO THIS QUESTION SINCE NONE OF THEM USE RECURSIVE
DESCENT.
In Java using RECURSIVE DESCENT PARSING,
write a program that reads from a text file and generates
what that file defines. It should handle
panels nested in other panels. Recursive descent
parsing must be implemented. It should also detect
incorrect syntax and report the error.
Example of an input file:
-----------------------------------------------------------------------------------
Start "GUI" (150, 150) Layout Flow:
Textfield 50;
Panel Layout Grid(3, 1 , 3, 3):
Label "Enter";
Group "Jump";
Radio "Super";
Label "Enter";
Group "Jump";
Radio "Super";
End;
End.
-----------------------------------------------------------------------------------
Words in Bold are terminal keyword
tokens and symbols are punctuation tokens.
For...
- Start, the input for STRING needs to
appear on the top border of the window, and '(' NUMBER','
NUMBER ')' is the width and height of that window
- layout_type grid, the first '('
NUMBER',' NUMBER are the rows and columns, and the next
[',' NUMBER',' NUMBER] are optional and represent the
horizontal and vertical gaps
- radio_button, the input for STRING is
the label
For the following production widget ...
- button, the input for STRING
represents the name
- label, the input for STRING represents
what is to be placed on the label
- text field, NUMBER represents the length
of the input field
The grammar for this language is as follows:
-----------------------------------------------------------------------------
gui -> Start STRING '(' NUMBER','
NUMBER ')' layout widgets End '.'
layout
-> Layout layout_type':'
layout_type
-> Flow | Grid '('
NUMBER',' NUMBER [',' NUMBER',' NUMBER] ')'
widgets -> widget widgets | widget
widget -> Button STRING';'
| Group radio_buttons End ';'
| Label STRING';'
| Panel layout widgets End ';'
| Textfield NUMBER';'
radio_buttons -> radio_button radio_buttons |
radio_button
radio_button
-> Radio STRING';'
--------------------------------------------------------------------------------
Wrong, not even close (seriously how is this person
an "expert"?):
https://www.answers.com/homework-help/que ... n-q5426372

Answers that start like this don't use RECURSIVE DESCENT which
makes them incorrect...
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
try {
inp_file = new File("Input.txt");
scnr = new Scanner(inp_file);
if (scnr.hasNextLine()) {
strng = scnr.nextLine().trim();
lbl = getLabel(strng);
if (!lbl.equalsIgnoreCase("Window")) {
System.out.println("First label should be WINDOW");
return;
}
strng = strng.substring(lbl.length()).trim();
JFrame frame = (JFrame) addCompntRec(strng, lbl);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
} else {
System.out.println("Unknown Error");
}
} catch (FileNotFoundException exp) {
System.out.println("File not found");
exp.printStackTrace();
} catch (Exception excep) {
System.out.println("Unknown Error");
excep.printStackTrace();
}
}
private static ArrayList<Integer> getIntAray(String
strng)
throws Exception {
int lp, lpj;
ArrayList<Integer> result = new
ArrayList<Integer>();
for (lp = 0; lp < strng.length(); lp++) {
for (lpj = lp; lpj < strng.length() &&
Character.isDigit(strng.charAt(lpj)); lpj++);
if (lp != lpj) {
result.add(Integer.parseInt(strng.substring(lp, lpj)));
}
this isn't the complete answer just the start of
it.
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Answers that start like this are close but still
wrong...they repeat code (something recursive descent when done
correctly would avoid doing) and are written very
poorly.
https://www.answers.com/homework-help/que ... i-q8108157
https://www.answers.com/homework-help/que ... -q22572175
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.io.IOException;
import java.io.*;
//Define class lLexer
class lLexer {
//Declare variables
private static final int lKEYWORDS = 11;
private StreamTokenizer ltokenizer;
private String lpunctuation = ",:;.()";
//Define punctuationTokens
private Token[] punctuationTokens = {
Token.COMMA, Token.COLON, Token.SEMICOLON, Token.PERIOD,
Token.LEFT_PAREN, Token.RIGHT_PAREN
};
//Define constructor
public lLexer(String lfileName) throws FileNotFoundException
{
ltokenizer = new StreamTokenizer(new FileReader(lfileName));
ltokenizer.ordinaryChar('.');
ltokenizer.quoteChar('"');
}
// Define lgetNextToken()
public Token lgetNextToken() throws SyntaxError, IOException
{
int ltoken = ltokenizer.nextToken();
switch (ltoken) {
case StreamTokenizer.TT_NUMBER:
return Token.NUMBER;
case StreamTokenizer.TT_WORD:
for (Token laToken : Token.values()) {
if (laToken.ordinal() == lKEYWORDS)
break;
this isn't the complete answer just the start of
it.