JavaCC语法和.jjt

时间:2014-02-27 21:09:36

标签: java parsing javacc

我需要为程序编写语法。

程序:

app(name : 'App1') { 

  View(id: top) { 
    Label(id: l1, text: 'Hi') 
    Button(id: b1, text: 'Press')
    Button(id: b2, text: 'Exit')
    Panel(id: row3, orientation: 'verticall') { 
      Label(id: l2, text : 'Name') 
      Text(id: t1, text : 'Enter text')
    }
  }

}

语法:

/**
 * 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 > )* 
}

一旦我尝试使用JavaCC编译此文件,我在MADLParser.java生成的文件中出错。

我无法弄清楚问题。

0 个答案:

没有答案