Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Parsing methods

Options
  • 07-11-2017 1:46pm
    #1
    Closed Accounts Posts: 1,758 ✭✭✭


    I'm reading through a code base and it has a parsing class with many various boolean methods like so...
    final private boolean jj_2_10(int xla) {
    		jj_la = xla;
    		jj_lastpos = jj_scanpos = token;
    		try {
    			return !jj_3_10();
    		} catch (LookaheadSuccess ls) {
    			return true;
    		} finally {
    			jj_save(9, xla);
    		}
    	}
    
    	final private boolean jj_3_7() {
    		if (jj_scan_token(PARAMSTART))
    			return true;
    		if (jj_scan_token(WORD))
    			return true;
    		return false;
    	}
    
    	final private boolean jj_3_5() {
    		if (jj_scan_token(WORD))
    			return true;
    		return false;
    	}
    
    	final private boolean jj_3_4() {
    		if (jj_scan_token(WORD))
    			return true;
    		Token xsp;
    		if (jj_3_3())
    			return true;
    		while (true) {
    			xsp = jj_scanpos;
    			if (jj_3_3()) {
    				jj_scanpos = xsp;
    				break;
    			}
    		}
    		return false;
    	}
    
    	final private boolean jj_3_6() {
    		if (jj_scan_token(PARAMSTART))
    			return true;
    		if (jj_scan_token(WORD))
    			return true;
    		if (jj_scan_token(WORD))
    			return true;
    		return false;
    	}
    

    Can anyone give me an idea what's happening here? The method names appear to have some meaning but google doesn't really help me figure out what.


Comments

  • Registered Users Posts: 768 ✭✭✭14ned


    Pelvis wrote: »
    Can anyone give me an idea what's happening here? The method names appear to have some meaning but google doesn't really help me figure out what.

    It looks to be output from a compiler compiler such as yacc, "yet another compiler compiler"

    (or whatever equivalent php uses)

    Niall


  • Registered Users Posts: 6,064 ✭✭✭Talisman


    The "jj_" prefixes are a dead giveaway that it's code that was originally generated for a Java project. The parser was originally created using the Java Compiler Compiler toolkit, JavaCC.

    It's been a while since I've seen the code but I think you may have an attempted port to PHP of the query parser from the Apache Solr project.


  • Closed Accounts Posts: 1,758 ✭✭✭Pelvis


    Sorry guys, it is actually a java project! Used the wrong tags in my post, oops!


  • Registered Users Posts: 6,064 ✭✭✭Talisman


    Check for a .jj file in the project, it will contain the parsing information. The javacc tool transforms the contents of a .jj grammar file into the Java code for the parser classes.

    Description of the JavaCC Grammar File


  • Closed Accounts Posts: 1,758 ✭✭✭Pelvis


    That's great, thanks. Now I don't feel so bad for not having a clue what's going on in the auto generated files.


  • Advertisement
Advertisement