private LanguageValueAccess translate_Qualified_Identifier(ParseTreeNode node)
        {
            //If _QualList is not already filled, translate the current parse node into a list of identifiers
            if (_qualList == null)
            {
                _qualList = GenUtils.Translate_Qualified_Identifier(node);
            }

            //Lookup the first item of the translated list of identifiers within the current context
            LanguageSymbol symbol;

            var flag =
                _followScopeChain
                //? Context.LookupSymbolInOpenedDistinctScopes(_qualList.FirstItem, out symbol)
                ? Context.OpenedDistinctScopes().LookupSymbol(_qualList.FirstItem, out symbol)
                : Context.ActiveParentScope.LookupSymbol(_qualList.FirstItem, out symbol);

            if (flag == false)
            {
                return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Symbol name not recognized", RootParseNode));
            }

            //Ignore the first item from the list
            _qualList.IncreaseActiveStartOffset(1);

            if (_isLValue)
            {
                //This is an l-value
                switch (symbol.SymbolRoleName)
                {
                case RoleNames.StructureDataMember:
                case RoleNames.MacroParameter:
                case RoleNames.LocalVariable:
                    return(translate_StartAt_DataSymbol((SymbolDataStore)symbol));

                default:
                    return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("LValue symbol name not recognized", RootParseNode));
                }
            }

            //This is an r-value
            switch (symbol.SymbolRoleName)
            {
            case RoleNames.MacroParameter:
            case RoleNames.LocalVariable:
            case RoleNames.Constant:
                return(translate_StartAt_DataSymbol((SymbolDataStore)symbol));

            case RoleNames.FrameBasisVector:
            case RoleNames.BuiltinType:
            case RoleNames.FrameMultivector:
            case RoleNames.Structure:
            case RoleNames.Macro:
            case RoleNames.MacroTemplate:
            case RoleNames.Transform:
            case RoleNames.FrameSubspace:
                //case RoleNames.Binding:
                return(translate_StartAt_DirectSymbol(symbol));

            case RoleNames.Frame:
                return(translate_StartAt_FrameDefinition((GMacFrame)symbol));

            case RoleNames.Namespace:
                return(translate_StartAt_NamespaceDefinition((GMacNamespace)symbol));

            default:
                return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("RValue symbol name not recognized", RootParseNode));
            }
        }
Beispiel #2
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;
            }
        }
        private void translate_PredefinedBasisBladeIDs(string identName, ParseTreeNode node)
        {
            var firstChar = identName[0];

            switch (firstChar)
            {
            case 'E':
            {
                int id;
                if (Int32.TryParse(identName.Substring(1), out id) && _frame.IsValidBasisBladeId(id))
                {
                    AddBasisBladeId(id);
                }

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

            case 'B':
            {
                var id = identName.Substring(1).StringToPattern();

                if (_frame.IsValidBasisBladeId(id))
                {
                    AddBasisBladeId(id);
                }

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

            case 'G':
            {
                var pos = identName.IndexOf('I');

                if (pos < 2 || pos == identName.Length - 1)
                {
                    CompilationLog.RaiseGeneratorError <int>("Basis blades set not recognized", node);
                }

                var gradeText = identName.Substring(1, pos - 1);
                var indexText = identName.Substring(pos + 1);

                int grade, index;

                if (
                    Int32.TryParse(gradeText, out grade) &&
                    Int32.TryParse(indexText, out index) &&
                    _frame.IsValidBasisBladeGradeIndex(grade, index)
                    )
                {
                    AddBasisBladeId(GMacMathUtils.BasisBladeId(grade, index));
                }

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

            default:
                CompilationLog.RaiseGeneratorError <int>("Basis blades set not recognized", node);
                break;
            }
        }
Beispiel #4
0
        //public override void ResetOnAcquire()
        //{
        //    base.ResetOnAcquire();

        //    _generatedNamespace = null;
        //}


        private void translate_Namespace()
        {
            try
            {
                Context.MarkCheckPointState();

                //Read the namespace name: for example main.conformal.cga5d
                var qualList = GenUtils.Translate_Qualified_Identifier(RootParseNode.ChildNodes[0]);

                //Find the root namespace inside the root global scope of the GMacDSL (search for a namespace called 'main')
                GMacNamespace nameSpace;

                if (GMacRootAst.LookupRootNamespace(qualList.FirstItem, out nameSpace) == false)
                {
                    if (GMacRootAst.RootScope.SymbolExists(qualList.FirstItem))
                    {
                        CompilationLog.RaiseGeneratorError <int>("Namespace name already used", RootParseNode.ChildNodes[0]);
                    }

                    nameSpace = GMacRootAst.DefineRootNamespace(qualList.FirstItem);
                }

                //Starting from the created\found root namespace, repeat the previous operation for each child namespace in qual_list
                for (var i = 1; i < qualList.ActiveLength; i++)
                {
                    GMacNamespace childNamespace;

                    if (nameSpace.LookupNamespace(qualList[i], out childNamespace))
                    {
                        nameSpace = childNamespace;
                    }

                    else
                    {
                        if (nameSpace.CanDefineChildSymbol(qualList[i]) == false)
                        {
                            CompilationLog.RaiseGeneratorError <int>("Symbol with same name already exists", RootParseNode.ChildNodes[0]);
                        }

                        nameSpace = nameSpace.DefineNamespace(qualList[i]);
                    }
                }

                _generatedNamespace = nameSpace;

                _generatedNamespace.AddCodeLocation(Context.GetCodeLocation(RootParseNode));

                Context.UnmarkCheckPointState();

                Context.CompilationLog.ReportNormal("Translated Namespace: " + _generatedNamespace.SymbolAccessName, ProgressEventArgsResult.Success);
            }
            catch (CompilerException)
            {
                Context.RestoreToCheckPointState();
                Context.CompilationLog.ReportNormal("Translate Namespace Failed", ProgressEventArgsResult.Failure);
            }
            catch (Exception e)
            {
                Context.RestoreToCheckPointState();
                Context.CompilationLog.ReportError("Translate Namespace Failed With Error", e);
            }
        }