• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help with a Recursive Descent Parser

 
Greenhorn
Posts: 7
Android Scala IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone, my name is Ryan. I have been a lurker around here for a while now, but this is my first post here. The reason I am posting is that I have project and I need some help with it. I am currently in an online programming class where we are learning about the differences between languages, and our first 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 project includes the grammar for the GUI language as well as the lexical analyzer for the project. With what we have learned so far in the class, I do not feel ready for this project and I am looking for some help to get me started. I want to make clear I am NOT looking for the answer to be handed to me, I am just looking for advice on where I should start and any resources that would be helpful. I appreciate any help that can be given. Thanks and have a good day!

 
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If writing a recursive descent parser by hand is not a part of your requirements, I suggest you look into the ANTLR tool which can generate lexers and parsers in Java.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest
- start small/simple with the equivalent of a "Hello World"
- use a test driven approach. Write a test, make it work.

Without knowing more about the assignment, I can't really give more advice than that.
I presume they have given you some libraries/templates to start from and some example input files?

Which bits of the process are you not confident about?
Which bits of the program do you have to write, and which are already there?
e.g. Do you have to open and read the file, or is that done for you?

 
Ryan Murphy
Greenhorn
Posts: 7
Android Scala IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize everyone. I let my lack of confidence cause me to panic before actually thinking things through. I am going to give things a try and come back on here if I run into a specific problem. Sorry for wasting everyone's time.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problemo.
And its fully understandable. - just looking at the term: "parsing a GUI Definition language using recursive descent" gave me the shivers.


 
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you been given a grammar for the language? Have you been given any semantic contents for any of its expressions?
 
Ryan Murphy
Greenhorn
Posts: 7
Android Scala IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI everyone,

Sorry for the delayed reply; I've been super busy. I am close to getting it working, but I am running into some Problems. I am including the grammar for this project:

gui ::= Window 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 ';'

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
• 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


This is the code provided by the professor






And this is the parser I built:


Sorry for the length of the file, I just want to give everyone a feel of what I have and the scope of the project. Right now, one problem I know I am having is that my Parser is not properly handling nested Panels.


Placing the below text into a text file:

Window "Testing" (600, 500) Layout Flow:
Button "Test1";
Textfield 20;
Label "Something";
Group
Radio "A";
Radio "B";
Radio "C";
Radio "D";
Radio "E";
Radio "F";
End;
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;
Panel Layout Flow:
Group
Radio "z";
Radio "x";
Radio "y";
Radio "v";
End;
Panel Layout Grid(3, 3):
Button "X";
Button "O";
Button "X";
Button "O";
Button "X";
Button "O";
Button "X";
Button "O";
Button "X";
End;
End;
End.

Should produce the following image:



Instead it produces this:



Any suggestions on what might be the source of the problem?

Thanks!
 
Carey Brown
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see the specific problem but it looks like a Panel is not dealing with the End properly and putting the following Panel inside of the first Panel.
 
Ryan Murphy
Greenhorn
Posts: 7
Android Scala IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the feedback, I was kinda wondering if that might have had something to do with it. The only question I have is how to I handle keeping track in the parser which panel I am adding to? I think that might be the root of the problem.
 
Carey Brown
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting at line 212:

getWidgets() on line 10 will return false when it encounters END. Maybe leave getWidgets() but remove enclosing if().
I tried to compile your code but there are pieces missing. I'm assuming you omitted them because they were too long.
 
Ryan Murphy
Greenhorn
Posts: 7
Android Scala IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I figured out the source of my problem. In between 242 and 243 on my parser class I inserted the following line:

currentLevel = Token.WINDOW;

I retired that and other examples and so far they all seem to be compline correctly. Thanks everyone for the welcome and the help. I look forward to learning more! :-)
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic