Tuesday, 17 July 2012

Simple1.jj First JavaCC example

options {
   IGNORE_CASE = true;
   DEBUG_PARSER = false;
   DEBUG_LOOKAHEAD = false;
   DEBUG_TOKEN_MANAGER = false;
   LOOKAHEAD = 2;
   FORCE_LA_CHECK=true;
}

PARSER_BEGIN(Simple1)

public class Simple1 {

   /** Main entry point. */
   public static void main(String args[]) throws ParseException {
   Simple1 parser = new Simple1(System.in);

   parser.Input();
   }
}

PARSER_END(Simple1)

SKIP : {
   " "
   "\t"
   "\n"
   "\r"
}
TOKEN: { < TEST: "test" > }

TOKEN: {<CR_LF: "\r\n"> }

TOKEN : { < OTHER : ~[] > }

void Input() :
{System.out.println("Start");}
{
   ((<OTHER>)* <TEST> (<OTHER>)* <CR_LF>)*
}