Example #1
0
 public ScriptFuncContract(AstNodeArgs args)
     : base(args)
 {
     pre  = ChildNodes[0] as ScriptFuncContractPre;
     post = ChildNodes[1] as ScriptFuncContractPost;
     inv  = ChildNodes[2] as ScriptFuncContractInv;
 }
 public ScriptForEachStatement(AstNodeArgs args)
     : base(args)
 {
     name      = (Token)ChildNodes[1];
     expr      = (ScriptExpr)ChildNodes[3];
     statement = (ScriptStatement)ChildNodes[4];
 }
        public ScriptTypeConvertExpr(AstNodeArgs args)
            : base(args)
        {
            if (ChildNodes.Count == 2)
            {
                if (args.ChildNodes[0] is ScriptExpr &&
                    !(args.ChildNodes[1] is ScriptExpr))
                {
                    // ( Expr )
                    expr = args.ChildNodes[0] as ScriptExpr;
                }
                else
                {
                    //(Type) Expr
                    typeExpr = args.ChildNodes[0] as ScriptExpr;
                    expr     = args.ChildNodes[1] as ScriptExpr;
                }
            }
            else
            {
                throw new ScriptException("Grammar error!");
            }

            @operator = RuntimeHost.GetBinaryOperator("+");
            if (@operator == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Example #4
0
        public ScriptFuncParameters(AstNodeArgs args)
            : base(args)
        {
            if (ChildNodes.Count == 1)
            {
                for (int index = 0; index < ChildNodes[0].ChildNodes.Count; index++)
                {
                    AstNode astNode = ChildNodes[0].ChildNodes[index];
                    Identifiers.Add((astNode as Token).Text);
                }
            }

            //if (ChildNodes[0] is Token)
            //{
            //  Identifiers.Add((ChildNodes[0] as Token).Text);
            //}
            //else
            //{
            //  for (int index = 0; index < ChildNodes[0].ChildNodes.Count; index++)
            //  {
            //    AstNode astNode = ChildNodes[0].ChildNodes[index];
            //    Identifiers.Add((astNode as Token).Text);
            //  }
            //}
        }
Example #5
0
        public ScriptFunctionDefinition(AstNodeArgs args)
            : base(args)
        {
            Token funcName = ChildNodes[1] as Token;
            int   index    = 0;

            if (funcName != null)
            {
                Name = funcName.Text;
            }
            else
            //Function expression
            {
                Name  = null;
                index = 1;
            }

            if (ChildNodes.Count == 5 - index)
            {
                Contract   = ChildNodes[3 - index] as ScriptFuncContract;
                Parameters = ChildNodes[3 - index] as ScriptFuncParameters;
            }

            if (ChildNodes.Count == 6 - index)
            {
                Parameters = ChildNodes[2 - index] as ScriptFuncParameters;
                GlobalList = ChildNodes[3 - index] as ScriptGlobalList;
                Contract   = ChildNodes[4 - index] as ScriptFuncContract;
            }

            Body = (ScriptAst)ChildNodes[ChildNodes.Count - 1];
        }
 public ScriptTryCatchFinallyStatement(AstNodeArgs args)
     : base(args)
 {
     tryBlock     = ChildNodes[1] as ScriptStatement;
     expName      = (ChildNodes[3] as Token).Text;
     catchBlock   = ChildNodes[4] as ScriptStatement;
     finallyBlock = ChildNodes[6] as ScriptStatement;
 }
Example #7
0
 public ScriptForStatement(AstNodeArgs args)
     : base(args)
 {
     init      = (ScriptAst)args.ChildNodes[1];
     cond      = (ScriptAst)args.ChildNodes[2];
     next      = (ScriptAst)args.ChildNodes[3];
     statement = (ScriptStatement)args.ChildNodes[4];
 }
Example #8
0
 public ScriptFunctionCall(AstNodeArgs args)
     : base(args)
 {
     if (ChildNodes.Count != 0)
     {
         funcArgs = ChildNodes[0] as ScriptExprList;
     }
 }
Example #9
0
 public ScriptArrayResolution(AstNodeArgs args)
     : base(args)
 {
     if (args.ChildNodes.Count != 0)
     {
         this.args = args.ChildNodes[0] as ScriptExprList;
     }
 }
        public ScriptQualifiedName(AstNodeArgs args)
            : base(args)
        {
            if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0)
            {
                Identifier = ((Token)ChildNodes[0]).Text;

                evaluation = EvaluateIdentifier;
                assignment = AssignIdentifier;
            }
            else
            if (ChildNodes[0] is Token && ChildNodes[1].ChildNodes.Count != 0)
            {
                Identifier = (ChildNodes[0] as Token).Text;

                //NOTE: There might be two cases:
                //      1) a()[]...()
                //      2) a<>.(NamePart)
                Modifiers = new List <ScriptAst>();
                foreach (ScriptAst node in ChildNodes[1].ChildNodes)
                {
                    Modifiers.Add(node);
                }

                ScriptGenericsPostfix generic = Modifiers.FirstOrDefault() as ScriptGenericsPostfix;
                if (generic != null && Modifiers.Count == 1)
                {
                    //Case 2
                    evaluation = EvaluateGenericType;
                    assignment = null;
                }
                else
                {
                    //Case 1
                    evaluation = EvaluateFunctionCall;
                    assignment = AssignArray;
                }
            }
            else
            {
                NamePart   = ChildNodes[0] as ScriptQualifiedName;
                Identifier = ((Token)ChildNodes[2]).Text;
                if (ChildNodes.Count == 4 && ChildNodes[3].ChildNodes.Count != 0)
                {
                    Modifiers = new List <ScriptAst>();
                    foreach (ScriptAst node in ChildNodes[3].ChildNodes)
                    {
                        Modifiers.Add(node);
                    }
                }
                evaluation = EvaluateNamePart;
                assignment = AssignNamePart;
            }
        }
Example #11
0
        public ScriptIsExpr(AstNodeArgs args)
            : base(args)
        {
            Debug.Assert(oper == "is");

            @operator = RuntimeHost.GetBinaryOperator(oper);
            if (@operator == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
 public ScriptIfStatement(AstNodeArgs args)
     : base(args)
 {
     condition = (ScriptCondition)ChildNodes[1];
     statement = (ScriptStatement)ChildNodes[2];
     //Else exists
     if (ChildNodes.Count == 4 && ChildNodes[3].ChildNodes.Count == 2 && ChildNodes[3].ChildNodes[1] is ScriptStatement)
     {
         elseStatement = (ScriptStatement)ChildNodes[3].ChildNodes[1];
     }
 }
Example #13
0
    public AstNode(AstNodeArgs args)
    {
      Term = args.Term;
      Span = args.Span;
      if (args.ChildNodes == null || args.ChildNodes.Count == 0) return;

      foreach (AstNode child in args.ChildNodes)
      {
        if (child != null && !child.Term.IsSet(TermOptions.IsPunctuation))
          AddChild(child);
      }
    }
Example #14
0
        public static TokenAst Create(ITerminal term, CompilerContext context, SourceLocation location, string text, object value)
        {
            int textLen = text == null ? 0 : text.Length;
            var span    = new SourceSpan(location, textLen);
            var args    = new AstNodeArgs(term, span, null);
            var token   = new TokenAst(args)
            {
                Text = text, Value = value
            };

            return(token);
        }
Example #15
0
        private AstNode CreateNode(ActionRecord reduceAction, SourceSpan sourceSpan, AstNodeList childNodes)
        {
            IGrammarTerm nonTeminal = reduceAction.NonTerminal;
            AstNode      result;

            AstNodeArgs args = new AstNodeArgs(nonTeminal, sourceSpan, childNodes);

            Type ntNodeType = nonTeminal.NodeType ?? typeof(AstNode);

            bool isList = nonTeminal.IsSet(TermOptions.IsList);

            if (isList && childNodes.Count > 1 && childNodes[0].Term == nonTeminal)
            {
                result = childNodes[0];
                AstNode newChild = childNodes[childNodes.Count - 1];
                newChild.Parent = result;
                result.ChildNodes.Add(newChild);
                return(result);
            }

            if (nonTeminal.IsSet(TermOptions.IsStarList) && childNodes.Count == 1)
            {
                childNodes = childNodes[0].ChildNodes;
            }

            if (!isList && !nonTeminal.IsSet(TermOptions.IsPunctuation) && childNodes.Count == 1)
            {
                Type childNodeType = childNodes[0].Term.NodeType ?? typeof(AstNode);
                if (childNodeType == ntNodeType || childNodeType.IsSubclassOf(ntNodeType))
                {
                    return(childNodes[0]);
                }
            }

            result = null;
            if (ntNodeType == typeof(AstNode))
            {
                result = new AstNode(args);
            }
            else
            {
                ConstructorInfo ctor = ntNodeType.GetConstructor(new Type[] { typeof(AstNodeArgs) });
                if (ctor == null)
                {
                    throw new Exception("Failed to located constructor: " + ntNodeType.ToString() + "(AstNodeArgs args)");
                }

                result = (AstNode)ctor.Invoke(new object[] { args });
            }

            return(result);
        }
Example #16
0
        public ScriptBinExpr(AstNodeArgs args)
            : base(args)
        {
            left  = (ScriptExpr)ChildNodes[0];
            oper  = ((Token)ChildNodes[1]).Text;
            right = (ScriptExpr)ChildNodes[2];

            operatorFunction = RuntimeHost.GetBinaryOperator(oper);
            if (operatorFunction == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Example #17
0
        public ScriptFlowControlStatement(AstNodeArgs args)
            : base(args)
        {
            Token oper = ChildNodes[0] as Token;

            operation = oper.Text;
            Debug.Assert(oper.Text == "return" || oper.Text == "break" || oper.Text == "continue" || oper.Text == "throw");

            if (operation == "return" || operation == "throw")
            {
                expression = (ScriptExpr)ChildNodes[1];
            }
        }
        public ScriptMetaExpr(AstNodeArgs args)
            : base(args)
        {
            AstNodeArgs progArgs = new AstNodeArgs();

            progArgs.ChildNodes = new AstNodeList();
            progArgs.ChildNodes.Add(ChildNodes[1]);
            progArgs.Span = args.Span;
            progArgs.Term = args.Term;

            metaProg        = new ScriptProg(progArgs);
            metaProg.Parent = this;
        }
Example #19
0
 public ScriptSwitchStatement(AstNodeArgs args)
     : base(args)
 {
     cases = new List <ScriptSwitchCaseStatement>();
     foreach (ScriptSwitchCaseStatement caseStatement in ChildNodes[0].ChildNodes)
     {
         cases.Add(caseStatement);
     }
     if (ChildNodes.Count == 2)
     {
         defaultCase = ChildNodes[1] as ScriptSwitchDefaultStatement;
     }
 }
Example #20
0
        public IfElseStmtNode(AstNodeArgs args)
            : base(args)
        {
            _condition      = (IJSBasicNode)args.ChildNodes[1];
            _thenExpression = (IJSBasicNode)args.ChildNodes[3];
            //Child #4 is ELSE_CLAUSE
            AstNode elseClause = args.ChildNodes[4];

            if (elseClause.ChildNodes.Count > 0)
            {
                _elseExpression = (IJSBasicNode)elseClause.ChildNodes[1];
            }
        }
Example #21
0
 public ForStmtNode(AstNodeArgs args)
     : base(args)
 {
     _assignment = (AssignStmtNode)args.ChildNodes[1];
     _upperBound = (ExpressionNode)args.ChildNodes[3];
     if (args.ChildNodes.Count == 6)
     {
         _step = int.Parse(((Token)args.ChildNodes[5]).Text, CultureInfo.InvariantCulture);
     }
     else
     {
         _step = 1;
     }
 }
Example #22
0
 public ScriptUnaryExpr(AstNodeArgs args)
     : base(args)
 {
     if (ChildNodes[0] is ScriptExpr)
     {
         expr = (ScriptExpr)ChildNodes[0];
         oper = ((Token)ChildNodes[1]).Text;
     }
     else
     {
         expr = (ScriptExpr)ChildNodes[1];
         oper = ((Token)ChildNodes[0]).Text;
     }
 }
Example #23
0
        public ScriptAssignExpr(AstNodeArgs args)
            : base(args)
        {
            nameExpr = (ScriptQualifiedName)args.ChildNodes[0];
            oper     = ((Token)args.ChildNodes[1]).Text;
            if (args.ChildNodes.Count == 3)
            {
                rightExpr = (ScriptExpr)args.ChildNodes[2];
            }

            Debug.Assert(oper == "=" || oper == ":=" || oper == "+=" || oper == "-=" || oper == "++" || oper == "--" || oper == ":=");

            switch (oper)
            {
            case "=":
                assignOperation = Assign;
                break;

            case ":=":
                assignOperation = AssignEx;
                break;

            case "++":
                assignOperation = PlusPlus;
                break;

            case "--":
                assignOperation = MinusMinus;
                break;

            case "+=":
                assignOperation = PlusEqual;
                break;

            case "-=":
                assignOperation = MinusEqual;
                break;

            default:
                throw new ScriptException("Assignment operator:" + oper + " is not supported");
            }

            minus = RuntimeHost.GetBinaryOperator("-");
            plus  = RuntimeHost.GetBinaryOperator("+");

            if (plus == null || minus == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Example #24
0
 public LineNode(AstNodeArgs args)
     : base(args)
 {
     LineTypes  = LineTypes.InternalLine;            // overwritten later by JavaScriptGenerator
     LineNumber = (int)((Token)args.ChildNodes[0]).Value;
     if (args.ChildNodes.Count > 2)
     {
         StatementList = (GenericJsBasicNode)args.ChildNodes[1];
     }
     else
     {
         StatementList = new GenericJsBasicNode(args);                 //empty node
     }
 }
Example #25
0
        public RemStmtNode(AstNodeArgs args)
            : base(args)
        {
            Token  token = (Token)args.ChildNodes[0];
            string text  = token.Text;

            if (text.Length < 5)
            {
                _comment = "no comment";
            }
            else
            {
                _comment = text.Substring(4);
            }
        }
Example #26
0
        public GlobalFunctionExpr(AstNodeArgs args)
            : base(args)
        {
            this.FunctionName = (Token)args.ChildNodes[0].DepthFirstTraversal().OfType <Token>().Single();
            AstNodeList funcArgs = args.ChildNodes[2].ChildNodes;

            this.InputParameter1 = (ExpressionNode)funcArgs[0];
            if (funcArgs.Count > 1)
            {
                this.InputParameter2 = (ExpressionNode)funcArgs[1];
            }
            if (funcArgs.Count > 2)
            {
                this.InputParameter3 = (ExpressionNode)funcArgs[2];
            }
        }
Example #27
0
        public AstNode(AstNodeArgs args)
        {
            Term = args.Term;
            Span = args.Span;
            if (args.ChildNodes == null || args.ChildNodes.Count == 0)
            {
                return;
            }

            foreach (AstNode child in args.ChildNodes)
            {
                if (child != null && !child.Term.IsSet(TermOptions.IsPunctuation))
                {
                    AddChild(child);
                }
            }
        }
Example #28
0
        public BranchStmtNode(AstNodeArgs args)
            : base(args)
        {
            Token command = (Token)args.ChildNodes[0];

            if (args.ChildNodes.Count == 1)
            {
                BranchType = BranchType.Return;
            }
            else
            {
                Token line = (Token)args.ChildNodes[1];

                BranchType      = (command.Text.ToLowerInvariant().Equals("goto") ? BranchType.Goto : BranchType.Gosub);
                DestinationLine = int.Parse(line.Text, CultureInfo.InvariantCulture);
            }
        }
Example #29
0
        public ScriptMObject(AstNodeArgs args)
            : base(args)
        {
            objectParts = new List <ScriptMObjectPart>();

            if (args.ChildNodes[0] is ScriptMObjectPart)
            {
                ScriptMObjectPart part = (ScriptMObjectPart)args.ChildNodes[0];
                objectParts.Add(part);
            }
            else
            {
                foreach (ScriptMObjectPart part in args.ChildNodes[0].ChildNodes)
                {
                    objectParts.Add(part);
                }
            }
        }
Example #30
0
 public ScriptTypeExpr(AstNodeArgs args)
     : base(args)
 {
     if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0)
     {
         Identifier = ((Token)ChildNodes[0]).Text;
     }
     else
     if (ChildNodes[0] is ScriptTypeExpr)
     {
         TypeExpr        = ChildNodes[0] as ScriptTypeExpr;
         Identifier      = (ChildNodes[2].ChildNodes[0] as Token).Text;
         GenericsPostfix = ChildNodes[2].ChildNodes[1] as ScriptGenericsPostfix;
     }
     else
     {
         GenericsPostfix = (ScriptGenericsPostfix)ChildNodes[1];
         Identifier      = GenericsPostfix.GetGenericTypeName(((Token)ChildNodes[0]).Text);
     }
 }
Example #31
0
        public ScriptConstExpr(AstNodeArgs args)
            : base(args)
        {
            Token cons = (Token)ChildNodes[0];

            Value = cons.Value;

            if (Value.Equals("true"))
            {
                Value = true;
            }
            if (Value.Equals("false"))
            {
                Value = false;
            }
            if (Value.Equals("null"))
            {
                Value = null;
            }
        }
Example #32
0
 protected TokenAst(AstNodeArgs args)
   : base(args)
 {
 }
Example #33
0
 public static TokenAst Create(ITerminal term, CompilerContext context, SourceLocation location, string text, object value)
 {
   int textLen = text == null ? 0 : text.Length;
   var span = new SourceSpan(location, textLen);
   var args = new AstNodeArgs(term, span, null);
   var token = new TokenAst(args) { Text = text, Value = value };
   return token;
 }