Class NametableStack.LocalNametable

  • All Implemented Interfaces:
    Nametable
    Enclosing class:
    NametableStack

    private static class NametableStack.LocalNametable
    extends java.lang.Object
    implements Nametable
    The local nametable defines a scope where local variables mask out the global variables, but the global variable can still be accessed. This is useful for implementing function context
    Author:
    TiongHiang Lee (thlee@onemindsoft.org)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Nametable _global
      the global map
      private java.util.Map _locals
      the local variables
      private int _scope
      the scope
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LocalNametable​(Nametable global, int scope)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object access​(java.lang.String name)
      Access the value associated with name
      java.util.Map asMap()
      Return map representation of this nametable
      java.lang.Object assign​(java.lang.String name, java.lang.Object value)
      Assign a variable in the name table
      boolean containsName​(java.lang.String key)
      Whether the nametable contains the name
      void declare​(java.lang.String name, java.lang.Object value)
      Declare a variable in the name table
      private Nametable getGlobal()
      Get the global
      java.lang.String toString()  
      void undeclare​(java.lang.String name)
      Undeclare the name
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _locals

        private final java.util.Map _locals
        the local variables
      • _global

        private final Nametable _global
        the global map
      • _scope

        private final int _scope
        the scope
    • Constructor Detail

      • LocalNametable

        private LocalNametable​(Nametable global,
                               int scope)
        Constructor
        Parameters:
        global - the global
        scope - the scope # where this local nametabe is openned
    • Method Detail

      • getGlobal

        private Nametable getGlobal()
        Get the global
        Returns:
        the global
      • containsName

        public boolean containsName​(java.lang.String key)
        Whether the nametable contains the name
        Specified by:
        containsName in interface Nametable
        Parameters:
        key - the name
        Returns:
        true if contains the name
      • declare

        public void declare​(java.lang.String name,
                            java.lang.Object value)
        Declare a variable in the name table
        Specified by:
        declare in interface Nametable
        Parameters:
        name - the name
        value - the value
      • assign

        public java.lang.Object assign​(java.lang.String name,
                                       java.lang.Object value)
        Assign a variable in the name table
        Specified by:
        assign in interface Nametable
        Parameters:
        name - the name
        value - the value
        Returns:
        the old value, or null
      • access

        public java.lang.Object access​(java.lang.String name)
        Access the value associated with name
        Specified by:
        access in interface Nametable
        Returns:
      • undeclare

        public void undeclare​(java.lang.String name)
        Undeclare the name
        Specified by:
        undeclare in interface Nametable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • asMap

        public java.util.Map asMap()
        Description copied from interface: Nametable
        Return map representation of this nametable
        Specified by:
        asMap in interface Nametable
        Returns:
        unmodifiable map representation of this nametable