Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package recur;
- public class ParserG {
- Letter input;
- char next;
- public ParserG() { }
- public boolean analys(String word) {
- input = new Letter(word);
- try {
- next = input.nextChar();
- S();
- match('$');
- } catch (SyntaxError ex) {
- System.out.println(ex.getMessage());
- return false;
- }
- return true;
- }
- private void S() throws SyntaxError {
- match('a');
- match('b');
- if (next == 'b') {
- match('b');
- } else {
- A();
- B();
- match('d');
- }
- }
- private void A() throws SyntaxError {
- if (next == 'a') {
- next = input.nextChar();
- A();
- match('b');
- } else {
- match('d');
- }
- }
- private void B() throws SyntaxError {
- if (next == 'b') {
- match('b');
- } else {
- next = input.nextChar();
- B();
- match('c');
- A();
- }
- }
- private void match(char c) throws SyntaxError {
- if (next == c) {
- next = input.nextChar();
- }
- else throw new SyntaxError("Expecting " + c + ", found " + next);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement