Example #1
0
  /**
   * Obtains the semantic tags associated with all the elements of the rule
   *
   * @param rules HashMap with all the grammar rules that have been already parsed. It is used to
   *     solve references to other rules within the current one
   * @return ArrayList with the semantic representations of all elements. It is composed of vectors
   *     containing 2 Strings: 0: text of the grammar element 1: its semantic interpretation
   */
  public ArrayList<String[]> getSemanticTags(HashMap<String, Rule> rules) {

    // Semantic tags
    ArrayList<String[]> semanticTags = new ArrayList<String[]>(elements.size());

    for (GrammarElement el : elements) {

      if (el.getSemanticTags() != null) // Careful: addAll throws Exception if its argument is null
      semanticTags.addAll(el.getSemanticTags());

      // If the element is a rule reference, then the referred rule is solved and is semantic tags
      // are added
      if (el instanceof RuleReference) {
        Rule referedRule = rules.get(((RuleReference) el).getRefId());
        if (referedRule.getSemanticTags(rules) != null)
          semanticTags.addAll(referedRule.getSemanticTags(rules));
      }
    }

    if (semanticTags.isEmpty()) return null;
    else return semanticTags;
  }
Example #2
0
 /**
  * Computes the regular expression corresponding to the rule by concatenating the expressions
  * corresponding to its constituent elements.
  */
 void setRegularExpression() {
   for (GrammarElement element : elements) {
     regularExpression += " " + element.getRegExpr();
   }
 }