javaCC

   1 样板:simples3.jj

options
{
  DEBUG_PARSER=true; //加上这个系统参数是为了可以显示文法推导的过程
}

PARSER_BEGIN(Simple3)

public class Simple3 {

  public static void main(String args[]) throws ParseException {
    Simple3 parser = new Simple3(System.in);//文字输入

   //下面这句就是对文件的直接读取。

   // parser = new TelParser(new java.io.FileInputStream(args[0]));
                 parser.Input();
  }

}

PARSER_END(Simple3)

SKIP :
{
  " "
| "/t"
| "/n"
| "/r"
}//忽略的字符

TOKEN :
{
  <LBRACE: "{">
| <RBRACE: "}">
}//记号,作为分析的记号

void Input() :
{ int count; }//函数的处世变量
{
  count=MatchedBraces()<EOF>//<EOF>代表不断循环,直到处错为止
  { System.out.println("The levels of nesting is " + count); }
}

int MatchedBraces() :
{ int nested_count=0; }
{
  <LBRACE> [ nested_count=MatchedBraces() ] <RBRACE>
  { return ++nested_count; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值