private void codeTextCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_codeTextCaretUpdate
// TODO add your handling code here:
    String code;
    code = codeText.getText();
    System.out.println(code);
    if (codeText.getText().equals("")) {
        return;
    }
    
    
    RulesSet rules = new RulesSet();
    rules.addRule("S", _s("S", "S5"), _s("S1", "S2"));
    rules.addRule("S5", _s("AMP", "S"));
    rules.addRule("S", _s("S", "S"), _s("S4", "CAB"));
    rules.addRule("S4", _s("OAB", "S"));
    rules.addRule("S5", _s("AMP", "S"));
    rules.addRule("S1", _s("OB", "N"));
    rules.addRule("S2", _s("COM", "S3"));
    rules.addRule("S3", _s("N", "CB"));
    rules.addRule("OB", _st(typeToken.openTok_brace));
    rules.addRule("CB", _st(typeToken.closeTok_brace));
    rules.addRule("COM", _st(typeToken.comma));
    rules.addRule("N", _st(typeToken.Num));
    rules.addRule("AMP", _st(typeToken.ParallelSign));
    rules.addRule("CAB", _st(typeToken.closeBrace));
    rules.addRule("OAB", _st(typeToken.openBrace));
    CompoParser cp = new CompoParser(rules);
    CompoParser.Comp res_comp = cp.getOverallComp(code);
    try {
        if (res_comp != null) {
            resultLabel.setText(String.format("valid, overall component is %s .", res_comp.toString()));
        } else {
            resultLabel.setText("not valid.");
        }
    } catch (RuntimeException e) {
        resultLabel.setText(e.toString());
    }
}//GEN-LAST:event_codeTextCaretUpdate