GUI Parser Project: Building a Recursive Descent Parser for GUI Design

Verified

Added on  2019/09/13

|3
|758
|57
Project
AI Summary
This project requires the implementation of a recursive descent parser for a GUI definition language. The assignment involves creating a lexer to recognize terminal symbols and a parser to analyze the input file, detecting and reporting syntax errors. The parser must handle nested panels and generate an output file detailing the parsing steps, following a format similar to that described in Sebesta's text. The project covers compiler design principles, including lexical and syntax analysis. Students are expected to implement the parser in C, C++, Java, or C# and test it with provided input files. The project aims to provide hands-on experience in parsing techniques and compiler construction. The final output file will report the parsing steps performed by the parser in a similar manner to the text book.
Document Page
Instructions
The first programming project involves writing a program that parses, using
recursive descent, a GUI definition language defined in an input file and
generates the GUI that it defines. The grammar for this language is defined
below:
gui ::= Window STRING '(' NUMBER ',' NUMBER ')' layout widgets End '.'
layout ::= Layout layout_type ':'
layout_type ::=
Flow '(' [ align ] ')'|
Border '(' [ NUMBER ',' NUMBER ] ')'|
Grid '(' NUMBER ',' NUMBER [',' NUMBER ',' NUMBER] ')'
align ::= LEFT | RIGHT | CENTER
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 ';'
In the above grammar, the red symbols are nonterminals, the blue symbols
are tokens and the black punctuation symbols are BNF metasymbols.
Among the tokens those in title case are keywords. The character literals
are punctuation tokens.
Below is an explanation of the meaning of some of the symbols in the above
productions that should help you understand the actions that are to be
performed when each of the productions is parsed:
In the window production the string is name that is to appear in the top
border of the window and the two numbers are the width and height of the
window
In the production for layout_type that define the grid layout, the first two
numbers represent the number of rows and columns, and the optional next
two the horizontal and vertical gaps
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
In the production for widget that defines a button, the string is the name of
the button
In the production for widget that defines a label, the string is text that is to
be placed in the label
In the production for widget that defines a text field, the number is the width
of the text field
In the production for radio_button, the string is the label of the button
You parser should properly handle the fact that panels can be nested in
other panels. Recursive productions must be implemented using recursion.
Lexical and syntactical errors should be detected and reported (the first
error only; after reporting the first error the program must exit gracefully).
Below is an example of an input file:
Window "Calculator" (200, 200) Layout Flow():
Textfield 20;
Panel Layout Grid(4, 3, 5, 5):
Button "7";
Button "8";
Button "9";
Button "4";
Button "5";
Button "6";
Button "1";
Button "2";
Button "3";
Label "";
Button "0";
End;
End.
Just to give you an idea where that input file came from, the above input file corresponds to the
GUI shown below:
Document Page
However, please keep in mind that you are NOT required to re-create the
GUI that corresponds to the input file. Instead, you are only required to:
1. Implement a lexer capable of recognizing all the terminal symbols of the
grammar (tokens/lexemes - those in blue)
2. Implement a recursive descent parser that (using the lexer from 1.) will
be able to parse the input file and detect a syntax error (the first one is
enough, then the parser should exit gracefully)
3. As a result of parsing the input file, an output file will be generated,
reporting the parsing steps followed by the parser in a manner similar to
the one described by Sebesta (10th edition) on pages 181-186.
Notes:
- You can implement the parser for this grammar in C, C++, Java or C#
- Additional input files will be provided for testing
- The complete list of deliverables will be specified very soon in a separate
post
Attachments
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]