private void translate_Outerproduct_List_SingleIdentifier(ParseTreeNode node)
        {
            var identName = GenUtils.Translate_Identifier(node);

            GMacFrameSubspace subspace;

            if (_frame.LookupSubspace(identName, out subspace))
            {
                AddBasisBladeIDs(subspace);
            }

            else
            {
                GMacFrameBasisVector basisVector;
                if (_frame.LookupBasisVector(identName, out basisVector))
                {
                    AddBasisBladeId(basisVector.BasisVectorId);
                }

                else
                {
                    translate_PredefinedBasisBladeIDs(identName, node);
                }
            }
        }
Exemplo n.º 2
0
        //public override void ResetOnAcquire()
        //{
        //    base.ResetOnAcquire();

        //    _vSpaceDim = 0;
        //    _baseFrame = null;
        //    _generatedFrame = null;
        //}


        ///Read the list of basis vectors names for the current frame
        private string[] translate_Frame_Vectors(ParseTreeNode node)
        {
            node.Assert(GMacParseNodeNames.FrameVectors);

            var basisVectorsNames = new List <string>();

            foreach (var subnode in node.ChildNodes)
            {
                var basisVectorName = GenUtils.Translate_Identifier(subnode);

                if (basisVectorsNames.Contains(basisVectorName))
                {
                    CompilationLog.RaiseGeneratorError <int>("Basis vector name already defined", subnode);
                }

                basisVectorsNames.Add(basisVectorName);
            }

            if (basisVectorsNames.Count > FrameUtils.MaxVSpaceDimension)
            {
                CompilationLog.RaiseGeneratorError <int>("Cannot handle spaces with dimension larger than " + FrameUtils.MaxVSpaceDimension, node);
            }

            return(basisVectorsNames.ToArray());
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private CommandDeclareVariable translate_Identifier_Declaration(ParseTreeNode node)
        {
            //Read the name of the member
            var identifierName = GenUtils.Translate_Identifier(node.ChildNodes[0]);

            if (Context.ActiveParentScope.SymbolExists(identifierName))
            {
                return(CompilationLog.RaiseGeneratorError <CommandDeclareVariable>("Identifier name already used", node.ChildNodes[0]));
            }

            var identifierType = GMacValueAccessGenerator.Translate_Direct_LanguageType(Context, node.ChildNodes[1]);

            return(translate_Declare(identifierName, identifierType));
        }
        //public override void ResetOnAcquire()
        //{
        //    base.ResetOnAcquire();

        //    _generatedExpression = null;
        //}


        //public GMacExpressionBasicGenerator BasicExpressionGenerator { get; private set; }


        //private GMacExpressionCompositeGenerator(GMacSymbolTranslatorContext context)
        //    : base(context)
        //{
        //    //BasicExpressionGenerator = new GMacExpressionBasicGenerator(context);
        //}

        //private GMacExpressionCompositeGenerator(GMacExpressionBasicGenerator basic_expr_gen)
        //    : base(basic_expr_gen.Context)
        //{
        //    BasicExpressionGenerator = basic_expr_gen;
        //}


        private SymbolLocalVariable translate_Identifier_Declaration(ParseTreeNode node)
        {
            //Read the name of the member
            var identifierName = GenUtils.Translate_Identifier(node.ChildNodes[0]);

            if (Context.ActiveParentScope.SymbolExists(identifierName))
            {
                return(CompilationLog.RaiseGeneratorError <SymbolLocalVariable>("Identifier name already used", node.ChildNodes[0]));
            }

            var identifierType = GMacValueAccessGenerator.Translate_Direct_LanguageType(Context, node.ChildNodes[1]);

            //Create the member in the symbol table
            return
                (Context
                 .ActiveParentCompositeExpression
                 .DefineLocalVariable(identifierName, identifierType)
                 .LocalVariable);
        }
        private void translate_BasisBladesSet_List_Item_GASpan(ParseTreeNode node)
        {
            var nodeIdentifierList = node.ChildNodes[0];

            //Create the set of unique spanning vectors for the GA subspace
            var basisVectorsList = new List <int>(nodeIdentifierList.ChildNodes.Count);

            foreach (var nodeIdentifier in nodeIdentifierList.ChildNodes)
            {
                GMacFrameBasisVector basisVector;
                var basisVectorName = GenUtils.Translate_Identifier(nodeIdentifier);

                if (_frame.LookupBasisVector(basisVectorName, out basisVector) == false)
                {
                    CompilationLog.RaiseGeneratorError <int>("Basis vector not recognized", nodeIdentifier);
                }

                //Only add unique basis vectors to the spanning set
                if (basisVectorsList.Exists(x => x == basisVector.BasisVectorId) == false)
                {
                    basisVectorsList.Add(basisVector.BasisVectorId);
                }
            }

            //Compute the dimension of the GA spanned by the basis vectors
            var subspaceDimension = 1 << basisVectorsList.Count;

            //Scalars are always part of the GA subspace based on any given set of basis vectors
            AddBasisBladeId(0);

            //Add the remaining basis blades to the GA subspace
            for (var idIndex = 1; idIndex <= subspaceDimension - 1; idIndex++)
            {
                var id = FrameUtils.ComposeGaSubspaceBasisBladeId(basisVectorsList, idIndex);

                AddBasisBladeId(id);
            }
        }
        private void translate_Outerproduct_List(ParseTreeNode node)
        {
            if (node.ChildNodes.Count == 1)
            {
                translate_Outerproduct_List_SingleIdentifier(node.ChildNodes[0]);
            }
            else if (node.ChildNodes.Count > 1)
            {
                var basisVectorsList = new List <GMacFrameBasisVector>(node.ChildNodes.Count);
                var basisBladeId     = 0;

                foreach (var nodeIdentifier in node.ChildNodes)
                {
                    GMacFrameBasisVector basisVector;
                    var basisVectorName = GenUtils.Translate_Identifier(nodeIdentifier);

                    if (_frame.LookupBasisVector(basisVectorName, out basisVector) == false)
                    {
                        CompilationLog.RaiseGeneratorError <int>("Basis vector not recognized", nodeIdentifier);
                    }

                    if (basisVectorsList.Exists(x => x.BasisVectorId == basisVector.BasisVectorId))
                    {
                        CompilationLog.RaiseGeneratorError <int>("Basis blades set not recognized", node);
                    }

                    basisVectorsList.Add(basisVector);
                    basisBladeId = basisBladeId | basisVector.BasisVectorId;
                }

                AddBasisBladeId(basisBladeId);
            }
            else
            {
                CompilationLog.RaiseGeneratorError <int>("Basis blades set not recognized", node);
            }
        }