Beispiel #1
0
 public CommandIfElse(LanguageScope parentScope, ILanguageExpression condExpr, ILanguageExpression trueExpr, ILanguageExpression falseExpr)
     : base(parentScope)
 {
     ConditionExpression = condExpr;
     TrueExpression      = trueExpr;
     FalseExpression     = falseExpr;
 }
Beispiel #2
0
        protected CommandBlock(LanguageScope parentScope, string localVariableRoleName)
            : base(parentScope)
        {
            ChildCommandBlockScope = ScopeCommandBlockChild.Create(this, "command_" + ObjectId + "_scope");

            LocalVariables = ChildCommandBlockScope.Symbols(localVariableRoleName).Cast <SymbolLocalVariable>();
        }
Beispiel #3
0
 internal GMacMultivectorTransform(string transformName, LanguageScope parentScope, GMacFrame sourceFrame, GMacFrame targetFrame, GaLinearTransform symbolicTransform)
     : base(transformName, parentScope, RoleNames.Transform)
 {
     SourceFrame = sourceFrame;
     TargetFrame = targetFrame;
     AssociatedSymbolicTransform = symbolicTransform;
 }
Beispiel #4
0
        /// <summary>
        /// Open a new scope
        /// </summary>
        /// <param name="scope"></param>
        public void OpenScope(LanguageScope scope)
        {
            //if (this._OpenedScopes.Exists((LanguageScope x) => (x.ScopeID == scope.ScopeID)))
            //    return;

            _openedScopes.Push(scope);
        }
Beispiel #5
0
        internal GMacRefResContextInfo Clear(LanguageScope scopeSymbol)
        {
            MainScope = scopeSymbol;
            _openedScopes.Clear();

            return(this);
        }
Beispiel #6
0
        public CommandComment(LanguageScope parentScope, string commentPrefix, string commentText)
            : base(parentScope)
        {
            CommentPrefix = commentPrefix;

            _commentTextLines = commentText.SplitLines();
        }
Beispiel #7
0
        protected TypeStructure(string symbolName, LanguageScope parentScope, string symbolRoleName, string dataMemberRoleName)
            : base(symbolName, parentScope, symbolRoleName)
        {
            //if (this.ChildScope.ContainsSymbolDictionary(data_member_role_name) == false)
            //    throw new Exception("Illegal symbol dictionary name: " + data_member_role_name);

            DataMembers = ChildSymbolScope.Symbols(dataMemberRoleName).Cast <SymbolStructureDataMember>();
        }
Beispiel #8
0
        protected LanguageSymbol(LanguageScope parentScope, string symbolRoleName)
            : base(parentScope)
        {
            ObjectName = "tmp_" + ObjectId.ToString("X");//.PadLeft(9, '_');
            SymbolRole = ParentScope.RootAst.RoleDictionary[symbolRoleName];

            ParentScope.AddLangugeSymbol(this);
        }
Beispiel #9
0
        protected LanguageSymbol(string symbolName, LanguageScope parentScope, string symbolRoleName)
            : base(parentScope)
        {
            ObjectName = symbolName;
            SymbolRole = ParentScope.RootAst.RoleDictionary[symbolRoleName];

            ParentScope.AddLangugeSymbol(this);
        }
Beispiel #10
0
 /// <summary>
 /// Create a sub-activation record
 /// </summary>
 /// <param name="callingAr">The dynamic link (the following activation record on the stack)</param>
 /// <param name="associatedScope">The associated scope</param>
 /// <param name="useUpperStaticAr">If true, use the dynamic link as the static link (make the upper static scope the same as the following activation record on the stack)</param>
 public ActivationRecord(ActivationRecord <TSymbolData> callingAr, LanguageScope associatedScope, bool useUpperStaticAr)
 {
     Arid = CreateNewId();
     ParentInterpreter = callingAr.ParentInterpreter;
     UpperStaticAr     = useUpperStaticAr ? callingAr : null;
     UpperDynamicAr    = callingAr;
     AssociatedScope   = associatedScope;
 }
 internal SymbolTranslatorContextState(LanguageScope parentScope, string curSymbolRoleName, ParseTreeNode curParseNode)
 {
     StateId           = CreateNewId();
     ParentScope       = parentScope;
     ParseNode         = curParseNode;
     SymbolRoleName    = curSymbolRoleName;
     IsCheckPointState = false;
 }
Beispiel #12
0
        /// <summary>
        /// Push the given state into the stack
        /// </summary>
        /// <param name="curParentScope"></param>
        /// <param name="curSymbolRoleName"></param>
        /// <param name="curParseNode"></param>
        /// <returns></returns>
        public SymbolTranslatorContext PushState(LanguageScope curParentScope, string curSymbolRoleName, ParseTreeNode curParseNode)
        {
            var state = new SymbolTranslatorContextState(curParentScope, curSymbolRoleName, curParseNode);

            StateStack.Push(state);

            return(this);
        }
Beispiel #13
0
        /// <summary>
        /// Push the given state into the stack. Any missing state information is set to be the active information
        /// </summary>
        /// <param name="curParentScope"></param>
        /// <returns></returns>
        public SymbolTranslatorContext PushState(LanguageScope curParentScope)
        {
            var state = new SymbolTranslatorContextState(curParentScope, ActiveSymbolRoleName, ActiveParseNode);

            StateStack.Push(state);

            return(this);
        }
Beispiel #14
0
        protected LanguageInterpreter(LanguageScope rootScope, LanguageValueAccessPrecessor valueAccessProc)
        {
            ParentDsl = rootScope.RootAst;

            ValueAccessProcessor = valueAccessProc;

            ActiveAr = new ActivationRecord <TSymbolData>(this, rootScope);
        }
Beispiel #15
0
        //public SymbolWithScope AssociatedSymbolWithScope { get { return (AssociatedScope is ScopeSymbolChild) ? ((ScopeSymbolChild)AssociatedScope).ParentLanguageSymbolWithScope : null; } }


        /// <summary>
        /// Create a root activation record
        /// </summary>
        /// <param name="interpreter">The controlling evaluator for this activation record</param>
        /// <param name="associatedScope">The associated scope</param>
        public ActivationRecord(ILanguageInterpreter <TSymbolData> interpreter, LanguageScope associatedScope)
        {
            Arid = CreateNewId();
            ParentInterpreter = interpreter;
            UpperStaticAr     = null;
            UpperDynamicAr    = null;
            AssociatedScope   = associatedScope;
        }
Beispiel #16
0
        public static ScopeScopeChild Create(LanguageScope parentScope, string scopeName)
        {
            var scope = new ScopeScopeChild(parentScope, scopeName);

            RegisterChildScope(scope.ParentScope, scope);

            return(scope);
        }
Beispiel #17
0
        internal GMacRefResContextInfo SetMainScope(LanguageScope scopeSymbol)
        {
            //If the main scope is one of the opened scopes, close it first
            CloseScope(scopeSymbol);

            MainScope = scopeSymbol;

            return(this);
        }
Beispiel #18
0
        /// <summary>
        /// Close the last scope that was opened
        /// </summary>
        /// <param name="scope"></param>
        public void CloseScope(LanguageScope scope)
        {
            if (_openedScopes.Count == 0 || _openedScopes.Peek().ObjectId != scope.ObjectId)
            {
                throw new Exception("Closed scope not matching last opened scope!");
            }

            _openedScopes.Pop();
        }
Beispiel #19
0
 public static IEnumerable <Language> FromScope(LanguageScope scope)
 {
     foreach (var language in database)
     {
         if (language.Scope == scope)
         {
             yield return(language);
         }
     }
 }
Beispiel #20
0
        private bool InitializeCompiler(LanguageScope scope, string targetObject, string codeText)
        {
            var progressTitle = InitProgressTitle(targetObject);

            var result = InitializeCompiler(codeText, GMacSourceParser.ParseQualifiedItem, scope);

            this.ReportNormal(progressTitle, codeText, result);

            return(result);
        }
        protected override void InitializeTranslatorContext(LanguageScope parentScope, IEnumerable <LanguageScope> openedScopes)
        {
            Context = GMacSymbolTranslatorContext.Create(this);

            Context.PushState(parentScope, RootParseNode);

            foreach (var scope in openedScopes)
            {
                Context.OpenScope(scope);
            }
        }
Beispiel #22
0
        //protected SymbolTranslatorContext(IronyAst rootAst, LanguageCompilationLog compilationLog)
        //{
        //    RootAst = rootAst;
        //    CompilationLog = compilationLog;
        //}


        /// <summary>
        /// If the stack has no states this pushes the given state. Else it pops the active state then pushes the given state
        /// </summary>
        /// <param name="curParentScope"></param>
        /// <param name="curSymbolRoleName"></param>
        /// <param name="curParseNode"></param>
        /// <returns>The newly pushed state</returns>
        public SymbolTranslatorContext SetActiveState(LanguageScope curParentScope, string curSymbolRoleName, ParseTreeNode curParseNode)
        {
            if (!HasActiveState)
            {
                return(PushState(curParentScope, curSymbolRoleName, curParseNode));
            }

            var state = PopState();

            return(PushState(curParentScope, curSymbolRoleName, curParseNode, state.IsCheckPointState));
        }
Beispiel #23
0
        /// <summary>
        /// Evaluates the given expression if it's a simple expression else it returns null
        /// </summary>
        /// <param name="rootScope"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        internal static ILanguageValue EvaluateExpressionIfSimple(LanguageScope rootScope, ILanguageExpression expr)
        {
            if (!expr.IsSimpleExpression)
            {
                return(null);
            }

            var evaluator = new GMacExpressionEvaluator(rootScope);

            return(expr.AcceptVisitor(evaluator));
        }
Beispiel #24
0
        /// <summary>
        /// Push the given state into the stack
        /// </summary>
        /// <param name="curParentScope"></param>
        /// <param name="curSymbolRoleName"></param>
        /// <param name="curParseNode"></param>
        /// <param name="isCheckpointState"></param>
        /// <returns>The newly pushed state</returns>
        private SymbolTranslatorContext PushState(LanguageScope curParentScope, string curSymbolRoleName, ParseTreeNode curParseNode, bool isCheckpointState)
        {
            var state =
                new SymbolTranslatorContextState(curParentScope, curSymbolRoleName, curParseNode)
            {
                IsCheckPointState = isCheckpointState
            };

            StateStack.Push(state);

            return(this);
        }
Beispiel #25
0
 public void Given_an_email_formatter_when_attempting_to_format_a_message_using_the_default_language_it_should_not_throw()
 {
     try
     {
         LanguageScope.SetDefaultLanguage("en-AU");
         _emailFormatter.BuildTemplatedEmailFrom(new SimpleEmailModel());
     }
     finally
     {
         LanguageScope.ClearDefaultLanguage();
     }
 }
Beispiel #26
0
        private Language([NotNull] string name, [NotNull] string part3, [CanBeNull] string part2B,
                         [CanBeNull] string part2, [CanBeNull] string part1, LanguageType type, LanguageScope scope)
        {
            Name  = name ?? throw new ArgumentNullException(nameof(name));
            Part3 = part3 ?? throw new ArgumentNullException(nameof(part3));
#pragma warning disable 612
            Part2B = part2B;
#pragma warning restore 612
            Part2 = part2;
            Part1 = part1;
            Type  = type;
            Scope = scope;
        }
Beispiel #27
0
        /// <summary>
        /// For the given parent scope this method extracts an identifier from the given node and
        /// returns it if it isn't already used for a child symbol of the scope.
        /// Else it raises a generator exception
        /// </summary>
        /// <param name="parentScope"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        protected string TranslateChildSymbolName(LanguageScope parentScope, ParseTreeNode node)
        {
            //Read the name of the new child symbol
            var childSymbolName = GenUtils.Translate_Identifier(node);

            //Make sure the child symbol name is not used inside the parent scope
            if (parentScope.SymbolExists(childSymbolName))
            {
                CompilationLog.RaiseGeneratorError <int>("Child symbol name already used", node);
            }

            return(childSymbolName);
        }
Beispiel #28
0
        internal GMacRefResContextInfo OpenScope(LanguageScope scopeSymbol)
        {
            var scopeName = scopeSymbol.QualifiedScopeName;

            if (MainScope.QualifiedScopeName == scopeName)
            {
                return(this);
            }

            if (_openedScopes.ContainsKey(scopeName))
            {
                _openedScopes.Remove(scopeName);
            }

            _openedScopes.Add(scopeName, scopeSymbol);

            return(this);
        }
Beispiel #29
0
        internal GMacFrame(string frameName, LanguageScope parentScope, GaFrame attachedFrame)
            : base(frameName, parentScope, RoleNames.Frame)
        {
            AssociatedSymbolicFrame = attachedFrame;

            FrameBasisVectors =
                ChildSymbolScope.Symbols(RoleNames.FrameBasisVector).Cast <GMacFrameBasisVector>();

            ChildConstants =
                ChildSymbolScope.Symbols(RoleNames.Constant).Cast <GMacConstant>();

            ChildMacros =
                ChildSymbolScope.Symbols(RoleNames.Macro).Cast <GMacMacro>();

            FrameSubspaces =
                ChildSymbolScope.Symbols(RoleNames.FrameSubspace).Cast <GMacFrameSubspace>();

            Structures =
                ChildSymbolScope.Symbols(RoleNames.Structure).Cast <GMacStructure>();

            Transforms =
                ChildSymbolScope.Symbols(RoleNames.Transform).Cast <GMacMultivectorTransform>();
        }
Beispiel #30
0
        internal GMacNamespace(string namespaceName, LanguageScope parentScope)
            : base(namespaceName, parentScope)
        {
            ChildNamespaces =
                ChildSymbolScope.Symbols(RoleNames.Namespace).Cast <GMacNamespace>();

            ChildFrames =
                ChildSymbolScope.Symbols(RoleNames.Frame).Cast <GMacFrame>();

            ChildConstants =
                ChildSymbolScope.Symbols(RoleNames.Constant).Cast <GMacConstant>();

            ChildMacros =
                ChildSymbolScope.Symbols(RoleNames.Macro).Cast <GMacMacro>();

            ChildMacroTemplates =
                ChildSymbolScope.Symbols(RoleNames.MacroTemplate).Cast <GMacMacroTemplate>();

            ChildTransforms =
                ChildSymbolScope.Symbols(RoleNames.Transform).Cast <GMacMultivectorTransform>();

            ChildStructures =
                ChildSymbolScope.Symbols(RoleNames.Structure).Cast <GMacStructure>();
        }
 public void TestFixtureSetUp()
 {
     _emailFormatter = Given.AnInitializedEmailFormatter();
     _languageScope = new LanguageScope("en-AU");
 }