Hi,
I want to know how do i write the grammer for the program below in JavaCC.

app(name : 'First App') { 

  View(id: top) { 
    Label(id: l1, text: 'Hello') 
    Button(id: b1, text: 'Press')
    Button(id: b2, text: 'Exit')
  }
}

appreciate a reply thanks

Hi, Below I wrote a grammer for the above program in .jjt in JavaCC. I juat want to verify if it is correct. Appreciate your comments. thanks

/**
 * JJTree template file created by SF JavaCC plugin 1.5.17+ wizard for JavaCC 1.5.0+
 */
options
{

}

PARSER_BEGIN(MADLParser)
package ui.parser;

public class MADLParser extends MADLParserBase
{}

PARSER_END(MADLParser)

//  =================================================================
//  Define the token manager.
//  =================================================================
TOKEN_MGR_DECLS :
{
  void CommonTokenAction(Token t)
  {}
}


TOKEN :
{
   < OPAR  : "(" > 
 | < CPAR  : ")" >
 | < COL   : ":" >
 | < APOS   : "'" >
 | < OBR   : "{" >
 | < CBR   : "}" >
 | < COMMA : "," >
 | < SCOL  : ";" >
 | < APP : "app" >
 | < NAME : "name">
 | < VIEW : "View" >
 | < LABEL : "Label" >
 | < BUTTON : "Button" >
 | < PANEL : "Panel" >
 | < TEXT : "Text">
 | < PAID  : "id">
 | < PATEXT : "text">
 | < PAORIENTATION : "orientation" >
 | < PABACKGROUND : "background" >
 | < PAALIGN : "align" >
 | < PACOLOR : "color" >
 | < WIDGETNAME : ( "Label"  | "Button" | "Text" ) > 

 | < PARAMETERTYPE : ( "text" | "orientation" | "background" | "align" | "color" ) >

 | < ALPHANUMERIC    : ("_" | <LETTER>) ("_" | <ALPHANUM>)* >
 | < #DIGIT    : ["0"-"9"] >
 | < #LETTER   : ["a"-"z","A"-"Z"] >
 | < #ALPHANUM : <LETTER> | <DIGIT> >  

 | < EOL :
    "\r\n"
  | "\r"
  | "\n" >

}

SimpleNode Start() #Start:
{}
{
   MainProgram()
  < EOF >
  {
    return jjtThis;
  }
}

void MainProgram() :
{}
{
     < APP > < OPAR > < NAME > < COL > < APOS > < ALPHANUMERIC > < APOS > < CPAR > < OBR >
     < EOL >
      MainView()
      < EOL >
      < CBR > 
}

void MainView() :
{}
{
     < VIEW > < OPAR > < PAID > < COL > < ALPHANUMERIC > < CPAR > < OBR >
     < EOL >
     Widgets()
     < EOL >
}

void Widgets() :
{}
{
     < WIDGETNAME > < OPAR > < PAID > < COL > < ALPHANUMERIC >
      ( < COMMA > < PARAMETERTYPE > < COL > < APOS > < ALPHANUMERIC > < APOS > < CPAR > )* 
}

Appreciate a reply
thanks in advance

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.