コード例 #1
0
        private static string GetParameterType(CommonTree tree)
        {
            int index = 0;

            while (index < tree.ChildCount)
            {
                switch (tree.GetChild(index).Type)
                {
                case Java2Lexer.MONKEYS_AT:
                case Java2Lexer.FINAL:
                    index++;
                    continue;

                default:
                    break;
                }

                break;
            }

            string typeText = GetTypeText((CommonTree)tree.GetChild(index));

            if (tree.GetFirstChildWithType(Java2Lexer.ELLIPSIS) != null)
            {
                typeText = typeText + "...";
            }

            return(typeText);
        }
コード例 #2
0
        public void Construct(CommonTree syntaxExpressionNode)
        {
            ExpressionType = TreeHelper.GetExpressionType(syntaxExpressionNode.Type);
            var syntaxLeft = syntaxExpressionNode.GetChild(0).CastTo <CommonTree>();

            Left = TreeHelper.GetExpression(this, Scope, syntaxLeft);
            Left.Construct(syntaxLeft);
            if (syntaxExpressionNode.Children.Count > 1)
            {
                var syntaxRight = syntaxExpressionNode.GetChild(1).CastTo <CommonTree>();
                Right = TreeHelper.GetExpression(this, Scope, syntaxRight);
                Right.Construct(syntaxRight);
            }
            if (ExpressionType == ExpressionType.Sub && Right == null)
            {
                var zeroExpression = new IntExpression(Parent, Parent.Scope)
                {
                    Value = 0
                };
                Right = Left;
                Left  = zeroExpression;
            }
            ReturnType = ReturnType.Unset;
            //if (Right == null) ReturnType = Left.ReturnType;
            //else
            //    ReturnType = Left.ReturnType.Equals(Right.ReturnType)
            //        ? Left.ReturnType
            //        : ReturnType.Unset;
        }
コード例 #3
0
ファイル: IfStatement.cs プロジェクト: Frazi1/SharpCompiler
        public void Construct(CommonTree syntaxIf)
        {
            //Condition
            var syntaxCondition = syntaxIf.GetChild(0).CastTo <CommonTree>();

            ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxCondition);
            ConditionExpression.Construct(syntaxCondition);

            //check if we have an empty block
            if (syntaxIf.ChildCount < 2)
            {
                return;
            }

            //True
            var syntaxTrueStatementsBlock = syntaxIf.GetChild(1).CastTo <CommonTree>();

            TrueCaseBlockStatement = TreeHelper.GetStatements(this, Scope, syntaxTrueStatementsBlock)
                                     .First();
            TrueCaseBlockStatement.Construct(syntaxTrueStatementsBlock);


            //False
            if (syntaxIf.ChildCount < 3)
            {
                return;
            }
            var syntaxFalseStatementsBlock = syntaxIf.GetChild(2).CastTo <CommonTree>();

            FasleCaseBlockStatement = TreeHelper.GetStatements(this, Scope, syntaxFalseStatementsBlock)
                                      .First();
            FasleCaseBlockStatement.Construct(syntaxFalseStatementsBlock);
        }
コード例 #4
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
 public void Visit(VariableDeclarationStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     statement.Variable = tree.GetChild(0).Text;
     Visit(tree.GetChild(1));
 }
コード例 #5
0
        public static string GetRoutineName(string sql)
        {
            StringBuilder sb;

            MySQL51Parser.program_return pr = ParseSql(sql, false, out sb);
            if (sb.Length != 0)
            {
                throw new ApplicationException(string.Format("Syntactic error in stored routine: {0}", sb));
            }
            else
            {
                CommonTree t = (CommonTree)pr.Tree;
                if (t.IsNil)
                {
                    t = (CommonTree)t.GetChild(0);
                }
                string name;
                if (string.Equals(t.GetChild(1).Text, "definer", StringComparison.OrdinalIgnoreCase))
                {
                    name = t.GetChild(3).Text;
                }
                else
                {
                    name = t.GetChild(1).Text;
                }
                return(name.Replace("`", ""));
            }
        }
コード例 #6
0
 public NestedPropertyImpl(CommonTree tree, IReadOnlyDictionary <string, string> prefixMap)
     : base((CommonTree)((CommonTree)tree.GetChild(0)).GetChild(0), PropertyType.NESTED_PROPERTY,
            prefixMap, ((CommonTree)tree.GetChild(0)).Token.Type == OslcSelectParser.WILDCARD)
 {
     this.tree = tree;
     children  = PropertiesImpl.CreateChildren((CommonTree)tree.GetChild(1), prefixMap);
 }
コード例 #7
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
 public void Visit(InsertOverwriteStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     Visit(tree.GetChild(0));
     Visit(tree.GetChild(1));
 }
コード例 #8
0
        public void Construct(CommonTree syntaxArrayInitializer)
        {
            var simpleReturnType = TreeHelper.GetReturnType(syntaxArrayInitializer.GetChild(0).Text);

            ReturnType = ReturnType.ArrayOf(simpleReturnType);


            //ArraySize
            var syntaxArraySize = syntaxArrayInitializer.GetChild(1).CastTo <CommonTree>();

            if (syntaxArraySize.ChildCount > 0)
            {
                var syntaxArraySizeExpression = syntaxArraySize.GetChild(0).CastTo <CommonTree>();
                ArraySize = TreeHelper.GetExpression(this, Scope, syntaxArraySizeExpression);
                ArraySize.Construct(syntaxArraySizeExpression);
            }

            //ArrayInitializationParameters
            var syntaxArrayInitializationParameters = syntaxArrayInitializer.GetChild(2).CastTo <CommonTree>();

            if (syntaxArrayInitializationParameters.ChildCount > 0)
            {
                syntaxArrayInitializationParameters.Children.Cast <CommonTree>()
                .ForEach(syntaxArrayInitializationParameter =>
                {
                    var parameterExpression =
                        TreeHelper.GetExpression(this, Scope, syntaxArrayInitializationParameter);
                    InitializationParameters.Add(parameterExpression);
                    parameterExpression.Construct(syntaxArrayInitializationParameter);
                });
            }
        }
コード例 #9
0
        public void Construct(CommonTree syntaxClass)
        {
            Name = syntaxClass.Children[0].Text;
            var syntaxModifiers = syntaxClass.GetChild(1).CastTo <CommonTree>();

            if (syntaxModifiers.ChildCount > 0)
            {
                syntaxModifiers.Children.ForEach(mod =>
                {
                    if (mod.Text == Modifiers.Extern)
                    {
                        ModifiersList.Add(Modifier.Extern);
                    }
                    else if (mod.Text == Modifiers.Static)
                    {
                        ModifiersList.Add(Modifier.Static);
                    }
                    else
                    {
                        throw new Exception($"Modifier {mod.Text} is not defined");
                    }
                });
            }
            var classblock = syntaxClass.GetChild(2).CastTo <CommonTree>();

            if (classblock.ChildCount == 0)
            {
                return;
            }
            classblock.Children
            .Cast <CommonTree>()
            .ForEach(child =>
            {
                if (child.Type == MathLangParser.STATIC_DECLARATION)
                {
                    //List<VariableDeclaration> variableList
                    //    =  TreeHelper.RunMultiDeclaration(this, Scope, child.GetChild(0).CastTo<CommonTree>());
                    //VarDeclarationNodes.AddRange(variableList);
                    child.Children.Cast <CommonTree>()
                    .Select(syntaxVariableDeclaration =>
                    {
                        var variableDeclaration = TreeHelper
                                                  .GetStatements(this, Scope, syntaxVariableDeclaration).First()
                                                  .CastTo <VariableDeclaration>();
                        variableDeclaration.Construct(syntaxVariableDeclaration);
                        return(variableDeclaration);
                    })
                    .ForEach(declaration => VarDeclarationNodes.Add(declaration));
                }
                else if (child.Type == MathLangParser.FUNCDECLARATION)
                {
                    FunctionDeclaration function = new FunctionDeclaration(this, Scope);
                    FunctionDeclarationNodes.Add(function);
//                        Scope.AddFunction(function);
                    function.Construct(child);
                }
            });
        }
コード例 #10
0
 /** Set up a local evaluator for a nested function call. The evaluator gets the definition
  *  tree of the function; the set of all defined functions (to find locally called ones); a
  *  pointer to the global variable memory; and the value of the function parameter to be
  *  added to the local memory.
  */
 private ProfileTreeGrammar(CommonTree function,
                            List <CommonTree> functionDefinitions,
                            IDictionary <string, BigInteger> globalMemory,
                            BigInteger paramValue)
 // Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
     : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     this.globalMemory = globalMemory;
     localMemory[function.GetChild(1).Text] = paramValue;
 }
コード例 #11
0
        private VarType ParseElementaryOperation(CommonTree node, string methodName)
        {

            dynamic leftNode = node.GetChild(0);
            var left = Parsing(leftNode, methodName);

            dynamic rightNode = node.GetChild(1);
            var right = Parsing(rightNode, methodName);

            return (left == VarType.Double || right == VarType.Double) ? VarType.Double : VarType.Int;
        }
コード例 #12
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
 public void Visit(TableMemberReference variable, CommonTree tree)
 {
     Parent(tree).Children.Add(variable);
     variable.RowReference = new TableVariableRowReference()
     {
         Id = tree.GetChild(0).Text, Parent = variable
     };
     SetLine(variable.RowReference, tree.GetChild(0));
     variable.Member = tree.GetChild(1).Text;
     SetLine(variable, tree.GetChild(1));
 }
コード例 #13
0
        public void Construct(CommonTree tree)
        {
            var syntaxExtendedId = tree.GetChild(0).CastTo <CommonTree>();

            VariableName = TreeHelper.GetExpression(this, Scope, syntaxExtendedId).CastTo <ExtendedId>();
            VariableName.Construct(syntaxExtendedId);

            var assignmentSyntax = tree.GetChild(1).CastTo <CommonTree>();

            AssignmentValue = TreeHelper.GetExpression(this, Scope, assignmentSyntax);
            AssignmentValue.Construct(assignmentSyntax);
        }
コード例 #14
0
        public void Construct(CommonTree syntaxArrayElementReference)
        {
            var syntaxExtendedId = syntaxArrayElementReference.GetChild(0).CastTo <CommonTree>();

            Name = TreeHelper.GetExpression(this, Scope, syntaxExtendedId).CastTo <ExtendedId>();
            Name.Construct(syntaxExtendedId);

            var syntaxArrayIndex = syntaxArrayElementReference.GetChild(1).CastTo <CommonTree>();

            ArrayIndex = TreeHelper.GetExpression(this, Scope, syntaxArrayIndex);
            ArrayIndex.Construct(syntaxArrayIndex);
        }
コード例 #15
0
ファイル: ForStatement.cs プロジェクト: Frazi1/SharpCompiler
        public void Construct(CommonTree syntaxFor)
        {
            //Initialization
            var syntaxForInitialization = syntaxFor.GetChild(0).CastTo<CommonTree>();
            if (syntaxForInitialization.ChildCount > 0)
            {
                //TODO: IMPLEMENT / FIX THIS
                syntaxForInitialization.Children.Cast<CommonTree>()
                    .ForEach(syntaxVarDeclarationOrAssignment =>
                    {
                        InitializationStatement =
                            TreeHelper.GetStatements(this, Scope, syntaxVarDeclarationOrAssignment).First();
                        InitializationStatement.Construct(syntaxVarDeclarationOrAssignment);
                    });
            }

            //Condition
            var syntaxForCondition = syntaxFor.GetChild(1).CastTo<CommonTree>();
            if (syntaxForCondition.ChildCount > 0)
            {
                syntaxForCondition.Children.Cast<CommonTree>()
                    .ForEach(syntaxBoolExpression =>
                    {
                        ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxBoolExpression);
                        ConditionExpression.Construct(syntaxBoolExpression);
                    });
            }

            //Iteration
            var syntaxForIteration = syntaxFor.GetChild(2).CastTo<CommonTree>();
            if (syntaxForIteration.ChildCount > 0)
            {
                syntaxForIteration.Children.Cast<CommonTree>()
                    .ForEach(syntaxVarAssignment =>
                    {
                        IterationStatement = TreeHelper.GetStatements(this, Scope, syntaxVarAssignment).First();
                        //if(iterationExpression is Varial)
                        IterationStatement.Construct(syntaxVarAssignment);
                    });
            }


            //Block
            if (syntaxFor.ChildCount > 3)
            {
                var syntaxForBlock = syntaxFor.GetChild(3).CastTo<CommonTree>();
                BlockOrSingleStatement = TreeHelper.GetStatements(this, Scope, syntaxForBlock).First();
                BlockOrSingleStatement.Construct(syntaxForBlock);
            }
        }
コード例 #16
0
ファイル: FlashTeaseConverter.cs プロジェクト: d3vi0n/TeaseMe
 private string GetPageId(CommonTree node)
 {
     if (node.Type == FlashTeaseScriptLexer.RANGE)
     {
         var fromNode = node.GetChild(0) as CommonTree;
         var toNode   = node.GetChild(1) as CommonTree;
         if (fromNode != null && toNode != null)
         {
             var fromText = String.Concat(fromNode.Children.Select(child => child.Text).ToArray());
             var toText   = String.Concat(toNode.Children.Select(child => child.Text).ToArray());
             return(String.Format("({0}..{1})", fromText, toText));
         }
     }
     return(String.Concat(node.Children.Select(child => child.Text).ToArray()));
 }
コード例 #17
0
        public void Construct(CommonTree syntaxArrayElementAssignment)
        {
            //Array element reference
            var syntaxArrayElementReference = syntaxArrayElementAssignment.GetChild(0).CastTo <CommonTree>();

            ArrayElementReference = TreeHelper.GetExpression(this, Scope, syntaxArrayElementReference)
                                    .CastTo <ArrayElementReference>();
            ArrayElementReference.Construct(syntaxArrayElementReference);

            //Assignment Value
            var syntaxAssignmentExpression = syntaxArrayElementAssignment.GetChild(1).CastTo <CommonTree>();

            AssignmentExpression = TreeHelper.GetExpression(this, Scope, syntaxAssignmentExpression);
            AssignmentExpression.Construct(syntaxAssignmentExpression);
        }
コード例 #18
0
 /// <summary>
 /// Children will enumerate children of node t.
 /// </summary>
 /// <param name="t">node for which children are to be identified.</param>
 /// <returns>returns one child at a time.</returns>
 public IEnumerable <CommonTree> Children(CommonTree t)
 {
     for (int i = 0; i < t.ChildCount; i++)
     {
         yield return((CommonTree)t.GetChild(i));
     }
 }
コード例 #19
0
ファイル: TestTreeNodeStream.cs プロジェクト: ymf1/webgrease
        public void TestList() /*throws Exception*/
        {
            ITree root = new CommonTree((IToken)null);

            ITree t = new CommonTree(new CommonToken(101));

            t.AddChild(new CommonTree(new CommonToken(102)));
            t.GetChild(0).AddChild(new CommonTree(new CommonToken(103)));
            t.AddChild(new CommonTree(new CommonToken(104)));

            ITree u = new CommonTree(new CommonToken(105));

            root.AddChild(t);
            root.AddChild(u);

            ITreeNodeStream stream    = newStream(root);
            string          expecting = " 101 102 103 104 105";
            string          found     = ToNodesOnlyString(stream);

            assertEquals(expecting, found);

            expecting = " 101 2 102 2 103 3 104 3 105";
            found     = ToTokenTypeString(stream);
            assertEquals(expecting, found);
        }
コード例 #20
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
        public void Visit(TableAlias alias, CommonTree tree)
        {
            Parent(tree).Children.Add(alias);
            SetLine(alias, tree);

            alias.Id = tree.GetChild(0).Text;
        }
コード例 #21
0
 public static IEnumerable <CommonTree> GetChildren(this CommonTree node)
 {
     for (var i = 0; i < node.ChildCount; i++)
     {
         yield return((CommonTree)node.GetChild(i));
     }
 }
コード例 #22
0
        ComparisonTermImpl(
            CommonTree tree,
            IDictionary <string, string> prefixMap
            ) : base(tree, TermType.COMPARISON, prefixMap)
        {
            switch (((CommonTree)tree.GetChild(1)).Token.Type)
            {
            case OslcWhereParser.EQUAL:
                op = Operator.EQUALS;
                break;

            case OslcWhereParser.NOT_EQUAL:
                op = Operator.NOT_EQUALS;
                break;

            case OslcWhereParser.LESS:
                op = Operator.LESS_THAN;
                break;

            case OslcWhereParser.LESS_EQUAL:
                op = Operator.LESS_EQUALS;
                break;

            case OslcWhereParser.GREATER:
                op = Operator.GREATER_THAN;
                break;

            default:
            case OslcWhereParser.GREATER_EQUAL:
                op = Operator.GREATER_EQUALS;
                break;
            }
        }
コード例 #23
0
ファイル: ParsingUltility.cs プロジェクト: MinhHuong/WSN-PN
        public static void IsStateAValidOneForExpression(ParserRuleReturnScope <IToken> expression, CommonTree tree)
        {
            bool invalid = false;

            if (tree != null)
            {
                if (!ExpressionList.Contains(tree.Text))
                {
                    invalid = true;
                }
                else if (tree.Text == "CLASS_CALL_NODE" && tree.ChildCount == 2)
                {
                    if (tree.GetChild(1).Text == "FIELDS_CALL_NODE")
                    {
                        invalid = true;
                    }
                }
            }

            if (invalid)
            {
                if (tree.Token.TokenIndex == -1)
                {
                    throw new ParsingException("Only assignment, call, if, while, local variable declaration, new object creation and object method call can be used as a statement", expression.Start as IToken);
                }
                else
                {
                    throw new ParsingException("Only assignment, call, if, while, local variable declaration, new object creation and object method call can be used as a statement", tree.Token);
                }
            }
            return;
        }
コード例 #24
0
ファイル: QueryUtils.cs プロジェクト: nenaaki/oslc4net
        ParseSearchTerms(
            string searchTermsExpression
            )
        {
            try {
                OslcSearchTermsParser parser  = new OslcSearchTermsParser(searchTermsExpression);
                CommonTree            rawTree = (CommonTree)parser.Result;
                CommonTree            child   = (CommonTree)rawTree.GetChild(0);

                if (child is CommonErrorNode)
                {
                    throw ((CommonErrorNode)child).trappedException;
                }

                IList <ITree> rawList    = rawTree.Children;
                StringList    stringList = new StringList(rawList.Count);

                foreach (CommonTree str in rawList)
                {
                    string rawString = str.Text;

                    stringList.Add(rawString.Substring(1, rawString.Length - 2));
                }

                return(stringList);
            } catch (RecognitionException e) {
                throw new ParseException(e);
            }
        }
コード例 #25
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
        public void Visit(JavascriptCode code, CommonTree tree)
        {
            SetLine(code, tree);
            Parent(tree).Children.Add(code);
            VisitChildren(tree);

            code.Code = ParseQuoteLiteral(tree.GetChild(0).Text);
        }
コード例 #26
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
        public void Visit(AsExpression expression, CommonTree tree)
        {
            Parent(tree).Children.Add(expression);
            SetLine(expression, tree);
            VisitChildren(tree);

            expression.Alias = tree.GetChild(0).Text;
        }
コード例 #27
0
        public void Construct(CommonTree syntaxWhile)
        {
            //condition
            var syntaxCondition = syntaxWhile.GetChild(0).CastTo <CommonTree>();

            ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxCondition);
            ConditionExpression.Construct(syntaxCondition);

            if (syntaxWhile.ChildCount > 1)
            {
                var syntaxBlockOrSingleStatement = syntaxWhile.GetChild(1).CastTo <CommonTree>();

                BlockOrSingleStatement =
                    TreeHelper.GetStatements(this, Scope, syntaxBlockOrSingleStatement)[0];
                BlockOrSingleStatement.Construct(syntaxBlockOrSingleStatement);
            }
        }
コード例 #28
0
 public void Construct(CommonTree syntaxFuncCallExpression)
 {
     ReturnType = ReturnType.Unset;            var syntaxExtendedId = syntaxFuncCallExpression.GetChild(0).CastTo <CommonTree>();
     ExtendedId = TreeHelper.GetExpression(this, Scope, syntaxExtendedId).CastTo <ExtendedId>();
     ExtendedId.Construct(syntaxExtendedId);
     if (syntaxFuncCallExpression.ChildCount > 1)
     {
         syntaxFuncCallExpression.GetChild(1).CastTo <CommonTree>()
         .Children.Cast <CommonTree>()
         .ForEach(syntaxfuncCallParam =>
         {
             IExpression parameter = TreeHelper.GetExpression(this, Scope, syntaxfuncCallParam);
             parameter.Construct(syntaxfuncCallParam);
             FunctionCallParameters.Add(parameter);
         });
     }
 }
コード例 #29
0
ファイル: BridgeVisitor.cs プロジェクト: jeason0813/pickaxe
        public void Visit(EachStatement eachStatement, CommonTree tree)
        {
            Parent(tree).Children.Add(eachStatement);
            SetLine(eachStatement, tree);

            eachStatement.IterationVariable = new VariableDeclarationStatement()
            {
                Variable = tree.GetChild(0).Text
            };
            SetLine(eachStatement.IterationVariable, tree.GetChild(0));

            var rowGetter = new TableVariableRowGetter()
            {
                Id = tree.GetChild(1).Text
            };

            SetLine(rowGetter, tree.GetChild(1));
            eachStatement.IterationVariable.Children.Add(rowGetter);

            eachStatement.TableReference = new TableVariableReference()
            {
                Id = tree.GetChild(1).Text
            };
            SetLine(eachStatement.TableReference, tree.GetChild(1));

            Visit(tree.GetChild(2));
        }
コード例 #30
0
        public virtual void Construct(CommonTree syntaxVariableDeclaration)
        {
            if (IsConstructed)
            {
                throw new InvalidOperationException("Variable already constructed-");
            }
            var syntaxReturnType = syntaxVariableDeclaration.GetChild(0).CastTo <CommonTree>();

            ReturnType = TreeHelper.GetReturnType(TreeHelper.GetStringTypeFromSyntaxNode(syntaxReturnType));
            Name       = syntaxVariableDeclaration.GetChild(1).Text;
            //Check if we have a value assigned to the variable
            if (syntaxVariableDeclaration.ChildCount > 2)
            {
                var syntaxValueExpression = syntaxVariableDeclaration.GetChild(2).CastTo <CommonTree>();
                Value = TreeHelper.GetExpression(this, Scope, syntaxValueExpression);
                Value.Construct(syntaxValueExpression);
            }
            IsConstructed = true;
        }