User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1805 | Replies: 0
Reply
Join Date: Nov 2004
Posts: 86
Reputation: MrScruff is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
MrScruff's Avatar
MrScruff MrScruff is offline Offline
Junior Poster in Training

Help Syntax Analyser and General Java Help

  #1  
Dec 1st, 2004
Hello, I am currently working on some coursework from which i have to write a syntax analyser to parse a grammer. Unfortunatly I am finding it hard to understand what I am meant to be doing - and if i am doing it right.
I have looked through many tutorials but they don't fill me with confidence that what i have to do is right. So hopefully you guys will be able to put me in the right direction so i can do some cool coding.

The main problem is:

Write a Java class SyntaxAnalyser This will have:
• a constructor with one String argument, the name of the file from which the tokens are to be read
• a single public method parse (there will, of course, also be some private methods). This is a void method with no
arguments, which is a recursive descent parser for this grammar applied to the file specified (or rather applied to
the tokens returned by the LexicalAnalyser class from the file specified).

This is my current attempt -
package comp;

import java.io.* ;
public class SyntaxAnalyser
{
  String file;
  Token nextSymbol;

  public SyntaxAnalyser(String fileName) {
    file = fileName;
  }

  public void parse() throws IOException {

    LexicalAnalyser lex = new LexicalAnalyser(file);
    Token t = null ;
              do
                  {
                  t = lex.getNextToken() ;
                  System.out.println(t) ;
                  }
              while (t.symbol != Token.eofSymbol) ;


  //define a set of all terminals/non-terminals which could be the left most token of (a). FIRST(a)
    //variable nextSymbol to recognise the next token from the lexical analyser

    //acceptTerminal Method
    if(lex.getNextToken() != null)
    {
      Token nextSymbol = lex.getNextToken();
    }
    else
    {
      System.out.println("There has been an Error with nextSymbol");
    }
  }

    //<program> ::= <procedure list>
    public void program()
    {

      if(nextSymbol.toString() == "<program>")
      {
      }

    }
    private void procedureList() {
      //call .procedureDefinition(); or .procedureList();.procedureDefinition()
    }
    //Second method to elimintate left recursion
    private void procedureList2(){

    }
    private void procedureDefinition() {
      //call procedureDefinition
    }
    private void procedureHeading() {
    }
    private void declerationList() {
    }
    //Second method to eliminate left recursion
    private void declerationList2(){

    }
    private void declaration() {
    }
    private void identifierList() {
    }
    //Second method to eliminate left recursion
    private void identifierList2()
    {

    }
    private void block() {
    }
    private void statementPart() {
    }
    private void statementList() {
    }
    private void statement() {
    }
    private void assignmentStatement() {
    }
    private void ifStatement() {
    }
    private void whileStatement() {
    }
    private void procedureStatement() {
    }
    private void untilStatement() {
    }
    private void argumtList() {
    }
    //Second method to eliminate left recursion
    private void argumetList(){

    }
    private void condtion() {
    }
    private void conditionOperator() {
      //if(op == '+' || op == '-' || op == '*' || op == '/')
      {
        //.getNextChar();
      }
    }
    private void expression() {
    }
    private void term() {
    }
    private void factor()
    {
    }
}

As you can see i have created a new method for each "non terminal" in the grammar. It may help you see what the grammar is which is here.

I am not so sure what to do next. I think i will have to fill these methods with actions depending on the grammar - but like i say i don't understand well.
Does the above file look like the correct structure?

Anyway thanks for any help you give. Below are some background links -

coursework questions (pdf)

Other java files.

Once again thanks for any help you give in helping me understand what i have to do

EDIT: i forgot to mention it is a "recrusive descent parser" which means it is a top down parser. The grammar is also in BNF form.

Ill will keep you up to date with any changes i make because i will be working on this constantly
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 11:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC