Exemplo n.º 1
0
 def _followups(self, nonterm):
     """Return the set of token types that could follow the given
     nonterminal."""
     res = {}
     for nonterm2, symb in self._parse_table.keys():
         if nonterm == nonterm2:
             set_add(res, symb)
     return seq_sorted([Token.type_description(key) for key in res.keys()])
Exemplo n.º 2
0
    def init_builtins(self):
        "Initialize a global context with types for all the builtins."
        for b in gbs_builtins.get_builtins():
            bname, b = b.name(), b.underlying_construct()
            set_add(self.ribs[0], b.name())
            self.global_context[b.name()] = b.gbstype()

        for type_name, gbs_type in gbs_type.BasicTypes.items():
            self.global_context[type_name] = gbs_type()
Exemplo n.º 3
0
 def _add_var(self, token, new_type=None):
     """Add a variable to the context with the given type, checking
     that it is consistent with the types it might already have."""
     if new_type is None: # fresh
         new_type = gbs_type.GbsTypeVar()
     varname = token.value
     if varname in self.ribs[-1]:
         old_type = self.context[varname]
         gbs_type.unify(new_type, old_type)
     else:
         self.context[varname] = new_type
         set_add(self.ribs[-1], varname)
     return new_type