Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
packrat_grammar_rep Struct Reference

#include <packrat_grammar.hpp>

Inheritance diagram for packrat_grammar_rep:
Inheritance graph
[legend]
Collaboration diagram for packrat_grammar_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 packrat_grammar_rep (string s)
void accelerate (array< C > &def)
array< Cdefine (tree t)
void define (string s, tree t)
void set_property (string s, string var, string val)
bool has_property (string s, string var)
string get_property (string s, string var)
string decode_as_string (C sym)
array< stringdecode_as_array_string (C sym)
array< stringmembers (string s)

Public Attributes

string lan_name
hashmap< C, array< C > > grammar
hashmap< C, treeproductions
hashmap< D, stringproperties
string res_name

Detailed Description

Definition at line 71 of file packrat_grammar.hpp.


Constructor & Destructor Documentation


Member Function Documentation

Definition at line 277 of file packrat_grammar.cpp.

                                              {
  if (N(def) == 0 || def[0] != PACKRAT_OR) return;
  hashmap<C,bool> all;
  for (int i=1; i<N(def); i++)
    if (def[i] >= PACKRAT_OR) return;
    else all (def[i])= true;
  array<C> ret;
  ret << PACKRAT_OR;
  hashmap<C,bool> done;
  for (int i=1; i<N(def); i++) {
    C c= def[i];
    if (done->contains (c)) continue;
    C start= c;
    while (start > 0 && all->contains (start-1)) start--;
    C end= c;
    while (end+1 < PACKRAT_OR && all->contains (end+1)) end++;
    if (end == start) ret << c;
    else {
      tree t= compound ("range", packrat_decode[start], packrat_decode[end]);
      C sym= encode_symbol (t);
      array<C> rdef;
      rdef << PACKRAT_RANGE << start << end;
      grammar (sym)= rdef;
      ret << sym;
      //cout << "Made range " << packrat_decode[start]
      //<< "--" << packrat_decode[end] << "\n";
    }
    for (int j=start; j<=end; j++) done(j)= true;
  }
  if (N(ret) == 2) {
    ret= range (ret, 1, 2);
    if (ret[0] >= PACKRAT_SYMBOLS) ret= grammar[ret[0]];
  }
  //cout << "Was: " << def << "\n";
  //cout << "Is : " << ret << "\n";
  def= ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 427 of file packrat_grammar.cpp.

                                                  {
  array<string> r;
  array<C> def= grammar[sym];
  if (N(def) == 1 && def[0] >= PACKRAT_SYMBOLS)
    r << decode_as_array_string (def[0]);
  else if (N(def) >= 1 && def[0] == PACKRAT_OR)
    for (int i=1; i<N(def); i++)
      r << decode_as_array_string (def[i]);
  else if (N(def) == 3 && def[0] == PACKRAT_RANGE)
    for (C c=def[1]; c<=def[2]; c++)
      r << decode_as_string (c);
  else r << decode_as_string (sym);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 405 of file packrat_grammar.cpp.

                                            {
  string r;
  if (sym < PACKRAT_OR) {
    tree t= packrat_decode [sym];
    if (is_atomic (t)) r << t->label;
  }
  else {
    array<C> def= grammar[sym];
    if (N(def) == 1 && (def[0] < PACKRAT_OR || def[0] >= PACKRAT_SYMBOLS))
      r << decode_as_string (def[0]);
    else if (N(def) >= 1 && def[0] == PACKRAT_CONCAT)
      for (int i=1; i<N(def); i++)
       r << decode_as_string (def[i]);
    else {
      cout << "Warning: could not transform " << packrat_decode[sym]
          << " into a string\n";
    }
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 320 of file packrat_grammar.cpp.

                                   {
  //cout << "Define " << t << INDENT << LF;
  array<C> def;
  if (t == "")
    def << PACKRAT_CONCAT;
  else if (is_atomic (t)) {
    int pos= 0;
    string s= t->label;
    tm_char_forwards (s, pos);
    if (pos > 0 && pos == N(s)) def << encode_symbol (s);
    else def << PACKRAT_CONCAT << encode_tokens (s);
  }
  else if (is_compound (t, "symbol", 1))
    def << encode_symbol (t);
  else if (is_compound (t, "range", 2) &&
          is_atomic (t[0]) && is_atomic (t[1]) &&
          N(t[0]->label) == 1 && N(t[1]->label) == 1)
    def << PACKRAT_RANGE
       << encode_token (t[0]->label)
       << encode_token (t[1]->label);
  else if (is_compound (t, "or", 1))
    def << define (t[0]);
  else {
    if (is_compound (t, "or")) def << PACKRAT_OR;
    else if (is_compound (t, "concat")) def << PACKRAT_CONCAT;
    else if (is_compound (t, "while")) def << PACKRAT_WHILE;
    else if (is_compound (t, "repeat")) def << PACKRAT_REPEAT;
    else if (is_compound (t, "not")) def << PACKRAT_NOT;
    else if (is_compound (t, "except")) def << PACKRAT_EXCEPT;
    else if (is_compound (t, "tm-open")) def << PACKRAT_TM_OPEN;
    else if (is_compound (t, "tm-any")) def << PACKRAT_TM_ANY;
    else if (is_compound (t, "tm-args")) def << PACKRAT_TM_ARGS;
    else if (is_compound (t, "tm-leaf")) def << PACKRAT_TM_LEAF;
    else if (is_compound (t, "tm-char")) def << PACKRAT_TM_CHAR;
    else if (is_compound (t, "tm-cursor")) def << PACKRAT_TM_CURSOR;
    else def << PACKRAT_TM_FAIL;
    for (int i=0; i<N(t); i++) {
      (void) define (t[i]);
      def << encode_symbol (t[i]);
    }
    accelerate (def);
  }
  if (N (def) != 1 || def[0] != encode_symbol (t)) {
    C sym= encode_symbol (t);
    grammar (sym)= def;
  }
  //cout << UNINDENT << "Defined " << t << " -> " << def << LF;
  return def;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 371 of file packrat_grammar.cpp.

                                             {
  //cout << "Define " << s << " := " << t << "\n";
  if (left_recursive (s, t)) {
    string s1= s * "-head";
    string s2= s * "-tail";
    tree   t1= left_head (s, t);
    tree   t2= left_tail (s, t);
    define (s1, t1);
    define (s2, t2);
    tree   u1= compound ("symbol", s1);
    tree   u2= compound ("while", compound ("symbol", s2));
    define (s, compound ("concat", u1, u2));
  }
  else {
    C        sym= encode_symbol (compound ("symbol", s));
    array<C> def= define (t);
    grammar (sym)= def;
  }
}

Here is the call graph for this function:

Definition at line 443 of file packrat_grammar.cpp.

                                      {
  C sym= encode_symbol (compound ("symbol", s));
  //cout << s << " -> " << decode_as_array_string (sym) << "\n";
  return decode_as_array_string (sym);
}

Here is the call graph for this function:

void packrat_grammar_rep::set_property ( string  s,
string  var,
string  val 
)

Definition at line 392 of file packrat_grammar.cpp.

                                                                   {
  //cout << "Set property " << s << ", " << var << " -> " << val << "\n";
  C sym = encode_symbol (compound ("symbol", s));
  C prop= encode_symbol (compound ("property", var));
  D key = (((D) prop) << 32) + ((D) (sym ^ prop));
  properties (key)= val;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 73 of file packrat_grammar.hpp.

Definition at line 72 of file packrat_grammar.hpp.

Definition at line 74 of file packrat_grammar.hpp.

Definition at line 75 of file packrat_grammar.hpp.

string rep< packrat_grammar >::res_name [inherited]

Definition at line 17 of file resource.hpp.


The documentation for this struct was generated from the following files: