MrScruff 0 Junior Poster in Training

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.