Пример #1
0
        private ILanguageExpression translate_Expression_Scoped(ParseTreeNode node)
        {
            var frame =
                (GMacFrame)GMacValueAccessGenerator.Translate_Direct(Context, node.ChildNodes[0], RoleNames.Frame);

            Context.OpenScope(frame);

            var expr = GMacExpressionGenerator.Translate(Context, node.ChildNodes[1]);

            Context.CloseScope(frame);

            return(expr);
        }
Пример #2
0
        ///Set the signature of the current frame to a reciprocal frame
        private GaFrame translate_Frame_Signature_Reciprocal(ParseTreeNode node)
        {
            var baseFrame =
                (GMacFrame)GMacValueAccessGenerator.Translate_Direct(Context, node.ChildNodes[0], RoleNames.Frame);

            if (baseFrame.VSpaceDimension != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Base frame must be of dimension " + _vSpaceDim, node.ChildNodes[0]);
            }

            _baseFrame = baseFrame;

            var derivedFrameSystem = GaFrame.CreateReciprocalCbmFrameSystem(baseFrame.AssociatedSymbolicFrame);

            return(derivedFrameSystem.DerivedFrame);
        }
Пример #3
0
        //protected void SetContext(GMacSymbolTranslatorContext context)
        //{
        //    this.SetContext((SymbolTranslatorContext)context);
        //}

        /// <summary>
        /// Take a qualified indetifier node and separate it into a parent symbol and a child symbol name
        /// </summary>
        /// <param name="node"></param>
        /// <param name="parentSymbol"></param>
        /// <param name="childSymbolName"></param>
        protected bool Translate_ParentSymbolAndChildSymbolName(ParseTreeNode node, out SymbolWithScope parentSymbol, out string childSymbolName)
        {
            var qualList = GenUtils.Translate_Qualified_Identifier(node);

            childSymbolName = qualList.LastItem;

            if (qualList.ActiveLength == 1)
            {
                parentSymbol = Context.ActiveParentSymbol;
            }

            else
            {
                qualList.DecreaseActiveEndOffset();

                parentSymbol = GMacValueAccessGenerator.Translate_Direct(Context, node, qualList) as SymbolWithScope;
            }

            return(ReferenceEquals(parentSymbol, null) == false);
        }
Пример #4
0
        ///Set the signature of the current frame to a base frame with a change of basis matrix
        private GaFrame translate_Frame_Signature_CBM(ParseTreeNode node)
        {
            var baseFrame =
                (GMacFrame)GMacValueAccessGenerator.Translate_Direct(Context, node.ChildNodes[0], RoleNames.Frame);

            if (baseFrame.VSpaceDimension != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Base frame must be of dimension " + _vSpaceDim, node.ChildNodes[0]);
            }

            var cbmMatrix = MathematicaMatrix.Create(Cas, GenUtils.Translate_StringLiteral(node.ChildNodes[1]));

            if (cbmMatrix.IsInvertable() == false || cbmMatrix.Rows != _vSpaceDim)
            {
                CompilationLog.RaiseGeneratorError <int>("Expecting a square invertable matrix with " + _vSpaceDim + " rows", node.ChildNodes[1]);
            }

            _baseFrame = baseFrame;

            var derivedFrameSystem = GaFrame.CreateDerivedCbmFrameSystem(baseFrame.AssociatedSymbolicFrame, cbmMatrix);

            return(derivedFrameSystem.DerivedFrame);
        }
        private ILanguageExpression translate_Expression_Function(ParseTreeNode node)
        {
            var expr = translate_TryBuiltinMacro(node);

            if (expr != null)
            {
                return(expr);
            }

            var nodeQualifiedIdentifier = node.ChildNodes[0];

            var nodeDefaultValueOpt = node.ChildNodes[1];

            var nodeInputsOpt = node.ChildNodes[2];

            ILanguageExpressionAtomic defaultValueSource;

            var symbol = GMacValueAccessGenerator.Translate_Direct(Context, nodeQualifiedIdentifier);

            var macro = symbol as GMacMacro;

            if (macro != null)
            {
                return
                    (nodeDefaultValueOpt.ChildNodes.Count == 0
                    ? translate_Expression_Function_Macro(macro, nodeInputsOpt)
                    : CompilationLog.RaiseGeneratorError <ILanguageExpression>("A default value cannot be used for a macro call operation", nodeDefaultValueOpt));
            }

            var structure = symbol as GMacStructure;

            if (structure != null)
            {
                if (nodeDefaultValueOpt.ChildNodes.Count <= 0)
                {
                    return(translate_Expression_Function_Structure(structure, null,
                                                                   nodeInputsOpt));
                }

                var nodeDefaultValue = nodeDefaultValueOpt.ChildNodes[0];

                defaultValueSource =
                    BasicExpressionGenerator.Generate_PolyadicOperand(
                        structure,
                        GMacExpressionGenerator.Translate(BasicExpressionGenerator, nodeDefaultValue.ChildNodes[0])
                        );

                return(translate_Expression_Function_Structure(structure, defaultValueSource, nodeInputsOpt));
            }

            var subspace = symbol as GMacFrameSubspace;

            if (subspace != null)
            {
                if (nodeDefaultValueOpt.ChildNodes.Count <= 0)
                {
                    return(translate_Expression_Function_Subspace(subspace, null, nodeInputsOpt));
                }

                var nodeDefaultValue = nodeDefaultValueOpt.ChildNodes[0];

                defaultValueSource =
                    BasicExpressionGenerator.Generate_PolyadicOperand(
                        subspace.ParentFrame.MultivectorType,
                        GMacExpressionGenerator.Translate(BasicExpressionGenerator, nodeDefaultValue.ChildNodes[0])
                        );

                return(translate_Expression_Function_Subspace(subspace, defaultValueSource, nodeInputsOpt));
            }

            var multivector = symbol as GMacFrameMultivector;

            if (multivector != null)
            {
                if (nodeDefaultValueOpt.ChildNodes.Count <= 0)
                {
                    return(translate_Expression_Function_MultivectorType(multivector,
                                                                         null, nodeInputsOpt));
                }

                var nodeDefaultValue = nodeDefaultValueOpt.ChildNodes[0];

                defaultValueSource =
                    BasicExpressionGenerator.Generate_PolyadicOperand(
                        multivector,
                        GMacExpressionGenerator.Translate(BasicExpressionGenerator, nodeDefaultValue.ChildNodes[0])
                        );

                return(translate_Expression_Function_MultivectorType(multivector, defaultValueSource, nodeInputsOpt));
            }

            var typePrimitive = symbol as TypePrimitive;

            if (typePrimitive != null)
            {
                return
                    (nodeDefaultValueOpt.ChildNodes.Count == 0
                    ? translate_Expression_Function_Cast(typePrimitive, nodeInputsOpt)
                    : CompilationLog.RaiseGeneratorError <ILanguageExpression>("A default value cannot be used for a type cast operation", nodeDefaultValueOpt));
            }

            var transform = symbol as GMacMultivectorTransform;

            if (transform != null)
            {
                return
                    (nodeDefaultValueOpt.ChildNodes.Count == 0
                    ? translate_Expression_Function_Transform(transform, nodeInputsOpt)
                    : CompilationLog.RaiseGeneratorError <ILanguageExpression>("A default value cannot be used for a multivector transform operation", nodeDefaultValueOpt));
            }

            return(CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expecting a macro, structure, transform, or multivector class", node));
        }
Пример #6
0
        private void translate_GMacDSL_Items_List(ParseTreeNode node)
        {
            if (CompilationLog.HasErrors && CompilationLog.StopOnFirstError)
            {
                return;
            }

            var subnode = node.ChildNodes[0];

            if (_translateNamespaceFirst && subnode.Term.ToString() != GMacParseNodeNames.Namespace)
            {
                CompilationLog.RaiseGeneratorError <int>("DSL definitions must start with a namespace", subnode);
            }

            _translateNamespaceFirst = false;

            switch (subnode.Term.ToString())
            {
            case GMacParseNodeNames.Breakpoint:
                GMacRootAst.EnableBreakpoints = true;
                break;

            case GMacParseNodeNames.Namespace:
                GMacNamespaceGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.OpenNamespace:
                //Only namespaces and frames can be used in the 'open' statement
                Context.OpenScope(
                    (SymbolWithScope)GMacValueAccessGenerator.Translate_Direct(
                        Context,
                        subnode.ChildNodes[0],
                        new[] { RoleNames.Namespace, RoleNames.Frame }
                        )
                    );

                break;

            case GMacParseNodeNames.Frame:
                GMacFrameGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Constant:
                GMacConstantGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Structure:
                GMacStructureGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Transform:
                GMacTransformGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Macro:
                GMacMacroGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.MacroTemplate:
                GMacMacroTemplateGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.TemplatesImplementation:
                GMacTemplatesImplementationGenerator.Translate(Context, subnode);
                break;

            default:
                CompilationLog.RaiseGeneratorError <int>("DSL definitions item not recognized", subnode);
                break;
            }
        }