Question: private void parseImages ( Scene scene, Token imageToken ) throws LexicalError, SyntaxError, IOException { int height, width, offset, radius, sides; verifyNextToken ( Token . COLOR

private void parseImages(Scene scene, Token imageToken) throws LexicalError, SyntaxError, IOException {
int height, width, offset, radius, sides;
verifyNextToken(Token.COLOR);
int[] colors = getNumberList(3); // Getting RGB values
Color color = new Color(colors[0], colors[1], colors[2]);
verifyNextToken(Token.AT);
int[] location = getNumberList(2); // Getting X and Y coordinates
Point point = new Point(location[0], location[1]);
if (imageToken == Token.RIGHT_TRIANGLE){
verifyNextToken(Token.HEIGHT);
verifyNextToken(Token.NUMBER);
height = lexer.getNumber();
verifyNextToken(Token.WIDTH);
verifyNextToken(Token.NUMBER);
width = lexer.getNumber();
RightTriangle triangle = new RightTriangle(color, point, height, width);
scene.addImage(triangle);
} else if (imageToken == Token.RECTANGLE){
verifyNextToken(Token.HEIGHT);
verifyNextToken(Token.NUMBER);
height = lexer.getNumber();
verifyNextToken(Token.WIDTH);
verifyNextToken(Token.NUMBER);
width = lexer.getNumber();
Rectangle rectangle = new Rectangle(color, point, height, width);
scene.addImage(rectangle);
} else if (imageToken == Token.PARALLELOGRAM){
verifyNextToken(Token.HEIGHT);
verifyNextToken(Token.NUMBER);
height = lexer.getNumber();
verifyNextToken(Token.WIDTH);
verifyNextToken(Token.NUMBER);
width = lexer.getNumber();
verifyNextToken(Token.OFFSET);
verifyNextToken(Token.NUMBER);
offset = lexer.getNumber();
Parallelogram parallelogram = new Parallelogram(color, point, height, width, offset);
scene.addImage(parallelogram);
} else if (imageToken == Token.REGULAR_POLYGON){
verifyNextToken(Token.SIDES);
verifyNextToken(Token.NUMBER);
sides = lexer.getNumber();
verifyNextToken(Token.RADIUS);
verifyNextToken(Token.NUMBER);
radius = lexer.getNumber();
RegularPolygon polygon = new RegularPolygon(color, sides, point, radius);
scene.addImage(polygon);
} else if (imageToken == Token.ISOSCELES){
verifyNextToken(Token.HEIGHT);
verifyNextToken(Token.NUMBER);
height = lexer.getNumber();
verifyNextToken(Token.WIDTH);
verifyNextToken(Token.NUMBER);
width = lexer.getNumber();
IsoscelesTriangle isosceles = new IsoscelesTriangle(color, point, height, width);
scene.addImage(isosceles);
} else if (imageToken == Token.TEXT){
// Fix: Ensure STRING is correctly handled
verifyNextToken(Token.STRING); // Expecting a STRING token
String text = lexer.getLexeme(); // Get the text from the lexer
if (text == null || text.isEmpty()){
throw new SyntaxError(lexer.getLineNo(), "Expected a valid text string, but found none.");
}
Text textImage = new Text(new Color(0,0,0), new Point(400,200), text);
scene.addImage(textImage);
}
else {
throw new SyntaxError(lexer.getLineNo(), "Unexpected image name "+ imageToken);
}
// Verify the semicolon and continue parsing the next image
verifyNextToken(Token.SEMICOLON);
token = lexer.getNextToken();
if (token != Token.END){
parseImages(scene, token);
}
}
Scene Polygons (500,500)
RightTriangle Color (255,0,0) at (50,30) Height 100 Width 300;
Rectangle Color (0,128,255) at (100,100) Height 200 Width 100;
Isosceles Color (255,0,0) at (120,120) Height 100 Width 200;
Parallelogram Color (0,0,255) at (340,50) Height 100 Width 200 Offset 30;
RegularPolygon Color(255,0,255) at (300,300) Sides 6 Radius 80;
Text Color(0,0,0) at (400,200)" Hello World";
End;
I keep getting an error for line 7 it is expecting a string not EOF but there is a string there could you help me

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!