Ejemplo n.º 1
0
 public virtual void VisitRoot(AbstractNode root)
 {
     root.Accept(this);
 }
 public override void VisitRoot(AbstractNode root)
 {
     SymbolTable.SetCurrentNode(root);
     root.Accept(this);
 }
Ejemplo n.º 3
0
        public override void Visit(SetQueryNode node)
        {
            if (node.SetAttributes)
            {
                foreach (var item in node.Attributes)
                {
                    string       InVaraible     = node.InVariable.Name;
                    string       VariableName   = item.Item1.Name.Trim('\'');
                    string       AssignOperator = item.Item2;
                    bool         IsCollection   = (item.Item1 as VariableAttributeNode).IsCollection;
                    AbstractNode expression     = item.Item3;
                    if (IsCollection)
                    {
                        _currentStringBuilder.Append($"foreach (var {HandleCSharpKeywords("val")} in {HandleCSharpKeywords(InVaraible)}) \n");

                        _currentStringBuilder.Append($"{{\n");

                        //Foreach body
                        if (node.WhereCondition != null)
                        {
                            _currentStringBuilder.Append($"if (");
                            node.WhereCondition.Accept(this);
                            _currentStringBuilder.Append($")\n {{\n");

                            // IfBody


                            _currentStringBuilder.Append($"{HandleCSharpKeywords("val")}.{HandleCSharpKeywords(VariableName)} {AssignOperator} ");
                            expression.Accept(this);
                            _currentStringBuilder.Append($";\n }}");
                        }
                        else
                        {
                            _currentStringBuilder.Append($"{HandleCSharpKeywords("val")}.{HandleCSharpKeywords(VariableName)} {AssignOperator} ");
                            expression.Accept(this);
                            _currentStringBuilder.Append($";\n");
                        }

                        _currentStringBuilder.Append($"\n }}\n");
                    }
                    else
                    {
                        _currentStringBuilder.Append($"{HandleCSharpKeywords(InVaraible)}.{HandleCSharpKeywords(VariableName)} {AssignOperator} ");
                        expression.Accept(this);
                        _currentStringBuilder.Append($";\n");
                    }
                }
            }
            else if (node.SetVariables)
            {
                foreach (var item in node.Attributes)
                {
                    string VariableName   = item.Item1.Name;
                    string AssignOperator = item.Item2;

                    AbstractNode expression = null;
                    if (item.Item3 is BoolComparisonNode boolNode && boolNode.ChildCount != 0 && boolNode.Children[0] is ExpressionNode)
                    {
                        expression = item.Item3.Children[0];
                    }
                    else
                    {
                        expression = item.Item3;
                    }


                    _currentStringBuilder.Append($"{HandleCSharpKeywords(VariableName)} {AssignOperator} ");
                    expression.Accept(this);
                    _currentStringBuilder.Append($";\n");
                }