语法分析

文法:

1) E→E+T


 2) E→T

 3) T→T*F

 4) T→F

 5) F→(E)

 6) F→id


核心代码:(其中的一个方法)

public String  Method(int i,Node node)
    {
        String message="";
        Expression currentExp;
        if (ACTION[node.state][i] > 0) {
            if(ACTION[node.state][i]==10000)
            {   
                System.out.println("分析成功");
                return "分析成功";
            }
            node = new Node(ACTION[node.state][i], letter[i]);
            message = "移进:"+letter[i]+"\n";
            System.out.println("移进:"+letter[i]+"\n");
            parseStack.push(node);
        } else if (ACTION[node.state][i] < 0) {
            currentExp = exps.get(-ACTION[node.state][i]);
            for (int j = 0; j < currentExp.length; j++) {
                parseStack.pop();
            }
            node = parseStack.pop();
            parseStack.push(node);
            message = "规约:" + currentExp.left + "->"
                    + currentExp.right + "\n";
            System.out.println("规约:" + currentExp.left + "->"
                    + currentExp.right + "\n");
            String left = currentExp.left;
            if (left.equals("E")) {
                node = new Node(GOTO[node.state][0], left);
                parseStack.push(node);
            } else if (left.equals("T")) {
                node = new Node(GOTO[node.state][1], left);
                parseStack.push(node);

            } else if (left.equals("F")) {
                node = new Node(GOTO[node.state][2], left);
                parseStack.push(node);

            }
        } else {
            message = "分析失败";
            
        }
        return message;
    }



源代码下载链接:

http://download.csdn.net/detail/snxhkg/8188841



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值