Пример #1
0
        //public static bool TryTranslate_LValue(GMacSymbolTranslatorContext context, ParseTreeNode node, out LanguageValueAccess varAccess)
        //{
        //    var qualList = GenUtils.Translate_Qualified_Identifier(node);

        //    LanguageSymbol symbol;

        //    var flag =
        //        context
        //        .OpenedDistinctScopes()
        //        .LookupSymbol(qualList.FirstItem, out symbol);

        //    if (flag == false || (symbol is SymbolLValue) == false)
        //    {
        //        varAccess = null;
        //        return false;
        //    }

        //    varAccess = LanguageValueAccess.Create(symbol);

        //    return true;
        //}

        public static LanguageValueAccess Translate(GMacSymbolTranslatorContext context, ParseTreeNode node, bool isLvalue, TrimmedList <string> qualList)
        {
            context.PushState(node);

            var translator = new GMacValueAccessGenerator();//new GMacValueAccessGenerator(qualList, context, isLvalue, true);

            translator.SetContext(qualList, context, isLvalue, true);
            translator.Translate();

            context.PopState();

            var result = translator._generatedValueAccess;

            //MasterPool.Release(translator);

            return(result);
        }
Пример #2
0
        private LanguageValueAccess translate_Command_Let_LHS_Qualified_Item(ILanguageType rhsType, ParseTreeNode node)
        {
            node.Assert(GMacParseNodeNames.QualifiedItem);

            var subNode = node.ChildNodes[0];

            switch (subNode.ToString())
            {
            case GMacParseNodeNames.QualifiedBasisBladesSet:
            case GMacParseNodeNames.QualifiedBasisBladeCoefficient:
                return(GMacValueAccessGenerator.Translate(Context, subNode, true));

            case GMacParseNodeNames.QualifiedIdentifier:
                if (subNode.ChildNodes.Count == 1)
                {
                    LanguageValueAccess varAccess;
                    var flag = TryTranslate_LValue(Context, subNode, out varAccess);

                    if (flag)
                    {
                        return(varAccess);
                    }

                    var identifierName = subNode.ChildNodes[0].FindTokenAndGetText();

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

                    var declareCommand = translate_Declare(identifierName, rhsType);

                    return(LanguageValueAccess.Create(declareCommand.DataStore));
                }

                return(GMacValueAccessGenerator.Translate(Context, subNode, true));

            default:
                return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Unknown LHS node!!", node));
            }
        }
Пример #3
0
        public static LanguageValueAccess Translate_LValue_MacroParameter(GMacSymbolTranslatorContext context, ParseTreeNode node, GMacMacro macro)
        {
            context.PushState(macro.ChildSymbolScope, node);

            var translator = new GMacValueAccessGenerator();//new GMacValueAccessGenerator(context, true, false);

            translator.SetContext(context, true, false);
            translator.Translate();

            context.PopState();

            if (translator._generatedValueAccess.RootSymbol is SymbolProcedureParameter)
            {
                var result = translator._generatedValueAccess;

                //MasterPool.Release(translator);

                return(result);
            }

            return(context.CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Expecting a macro parameter", node));
        }
Пример #4
0
        //private ILanguageExpression translate_Expression_Cast(ParseTreeNode node)
        //{
        //    var langType = GMacValueAccessGenerator.Translate_Direct_LanguageType(this.Context, node.ChildNodes[0]);

        //    var expr = GMacExpressionGenerator.Translate(this.BasicExpressionGenerator, node.ChildNodes[0]);

        //    return this.BasicExpressionGenerator.Generate_TypeCast(langType, expr);
        //}

        protected override void Translate()
        {
            var subNode = RootParseNode.ChildNodes[0];

            switch (subNode.Term.Name)
            {
            case GMacParseNodeNames.ConstantNumber:
                _generatedExpression = translate_Constant_Number(subNode);
                break;

            case GMacParseNodeNames.ExpressionScoped:
                _generatedExpression = translate_Expression_Scoped(subNode);
                break;

            case GMacParseNodeNames.QualifiedItem:
                _generatedExpression = GMacValueAccessGenerator.Translate(Context, subNode.ChildNodes[0], false);
                break;

            case GMacParseNodeNames.ExpressionBracketed:
                _generatedExpression = GMacExpressionGenerator.Translate(BasicExpressionGenerator, subNode.ChildNodes[0]);
                break;

            case GMacParseNodeNames.StringLiteral:
                _generatedExpression = GMacExpressionAtomicSymbolicGenerator.Translate(Context, subNode);
                break;

            case GMacParseNodeNames.ExpressionComposite:
                _generatedExpression = GMacExpressionCompositeGenerator.Translate(Context, subNode);
                break;

            case GMacParseNodeNames.ExpressionFunction:
                _generatedExpression = GMacExpressionAtomicFunctionGenerator.Translate(BasicExpressionGenerator, subNode);
                break;

            default:
                CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expression not recognized", RootParseNode);
                break;
            }
        }