SceneDSL Renderer (CMSC 330 Project 1)
This project is a Java-based graphics scene renderer that parses a domain-specific language (DSL) defined in a scene file and displays the specified graphical elements using Java's AWT graphics library.
π Project Overview
This project was developed for CMSC 330 - Organization of Programming Languages. It extends a provided Java skeleton to support parsing and rendering of graphical scenes based on an expanded EBNF grammar.
Supported Shapes:
- Right Triangle
- Rectangle
- Isosceles Triangle
- Parallelogram
- Regular Polygon
- Text
The program reads a scene definition file, parses its contents, creates shape objects, and renders the full scene graphically.
π Grammar Specification
scene β SCENE IDENTIFIER number_list images END '.' images β image images | image image β right_triangle | rectangle | parallelogram | regular_polygon | isosceles | text
(Terminals, non-terminals, and formatting follow the original EBNF syntax provided.)
π Project Structure
/src βββ Parser.java # Modified to support new grammar rules βββ Lexer.java # Updated to tokenize new keywords and string literals βββ Tokens.java # Extended with new tokens βββ Text.java # New class for rendering text βββ SolidPolygon.java # New class for regular polygons βββ IsoscelesTriangle.java # New class for isosceles triangles βββ Parallelogram.java # New class for parallelograms βββ RegularPolygon.java # New class for regular polygons βββ ... # Other provided and updated skeleton files
π οΈ How to Run
-
Compile all
.javafiles:javac *.java -
Run the main class (usually
Mainor similar):java Main scene.txt
Replace
scene.txtwith your scene definition file.
β Test Plan
The program was tested using a variety of scene files that include:
- Single and multiple shapes
- Edge cases for color values and dimensions
- Valid and invalid syntax
- Mixed shape types
Example test file:
Scene Test (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; Text Color (0, 0, 0) at (400, 200) "Hello World"; End.
π§ Lessons Learned
- How to extend a recursive-descent parser
- Working with abstract classes and Java's graphics API
- Designing and implementing new grammar rules
- Handling custom tokens and string parsing
βοΈ Author
Dilen Patel
Project 1: Scene Renderer
Let me know if you want to include example output images or add GitHub Pages support for a demo!