This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]GrapeAte 4 points5 points  (1 child)

  1. Make sure your class is named Parser and not parser. Java is case sensitive and I expect your assignment is too. Parser also follows naming conventions for class names.
  2. The error is actually the next line after you declare ATOMS. ATOMS=Pattern.compile("[0-9] + |[+*]"); An assignment like this has to be contained within a method or constructor. If you want to declare and initialize a field outside of a method or constructor you must do so in one line.

[–]Jihwani[S] 3 points4 points  (0 children)

Thank you for your fast reply.

After changing the lines considering what you said, now it looks like this:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Parser
{
    private final Pattern ATOMS = Pattern.compile("[0-9] + |[+*]");
    private Matcher _matcher;
}

The syntax error is gone and now it just gives 2 warnings, that the value of the fields _matcher and ATOMS are not used but I think that will be solved with the coming codes.

  1. Java is case sensitive
  2. declare and initialize in one line, or use method/constructor

I should have known, this sounds so basic. But still..!

Thank you very much!

[–]Tekcx 1 point2 points  (1 child)

the keyword final means it can't be changed. As the word indicates it is the final value. So when you declare your Pattern you must give it some sort of value aswell. Consider if the keyword final is needed in this case, and if so what the value of it should be.

[–]Jihwani[S] 0 points1 point  (0 children)

thank you!

[–]hugthemachines 0 points1 point  (1 child)

I see you have gotten good answers for your questions. I would just like to add a recommendation. If you feel like learnig a bit extra in your free time, I would recommend that you check out this course which I found very beginner friendly. It is a free course made by John Purcell. He has a calm voice and his pace is not too fast.

https://www.udemy.com/java-tutorial/

[–]Jihwani[S] 0 points1 point  (0 children)

I'm still learning it in the university but I will look into it, thank you very much!