예제 #1
0
        public object Execute(ILiquidContext context)
        {
            var result = (bool)_conditionExpr.Evaluate(context);

            return(result ? _ifBranchStatements.Execute(context) :
                   _elseBranchStatements != null?_elseBranchStatements.Execute(context) : null);
        }
예제 #2
0
        static void Main(string[] args)
        {
            FileStream file = null;
            Scanner scn = null;
            Parser parser = null;
            StatementList program = null;

            try
            {
                file = new FileStream("GCD_Example.ss", FileMode.Open);
                scn = new Scanner(file);
                parser = new Parser(scn);
                parser.Parse();
                program = parser.program;

                if (program != null)
                {
                    program.Execute();
                    Console.WriteLine();
                }
            }
            finally
            {
                file.Close();
            }
            
            
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length < 0)
            {
                Console.WriteLine("Usage: SimpleScript.exe <Sourcefile.ss>");
                return;
            }

            FileStream    file    = null;
            Scanner       scn     = null;
            Parser        parser  = null;
            StatementList program = null;

            try
            {
                //file = new FileStream(args[0], FileMode.Open);
                file   = new FileStream("Script4.ss", FileMode.Open);
                scn    = new Scanner(file);
                parser = new Parser(scn);
                parser.Parse();
                program = parser.program;

                if (program != null)
                {
                    program.Execute();
                    Console.WriteLine();
                }
            }
            finally
            {
                file.Close();
            }
        }
예제 #4
0
        public object Execute(ILiquidContext context)
        {
            if (_attributes != null && _attributes.Count != 0)
            {
                throw new NotImplementedException(); // todo: implement loop attributes
            }
            if (!(_value is LookupExpression))
            {
                // TODO: implement FOR... in range
                throw new NotImplementedException();

                /*long initVal = (long)initExpr.Evaluate();
                 * long endVal = (long)endExpr.Evaluate();
                 * for (ielem.Value = initVal; ielem.Value <= endVal; ielem.Value++)
                 * {
                 *  statements.Execute();
                 * }*/
            }

            // FOR ... in collection
            var collection = _value.Evaluate(context) as IEnumerable <object>;

            if (collection != null)
            {
                var result =
                    collection.Select(item =>
                {
                    context[_var] = item;
                    return(_statements.Execute(context));
                }
                                      ).Where(res => res != null);
                return(result.Any() ? result.ToList() : null);
            }

            throw new NotImplementedException("not collection or range!");
        }
예제 #5
0
        public object Execute(ILiquidContext context)
        {
            var result = (bool)_conditionExpr.Evaluate(context);

            return(!result?_unlessBranchStatements.Execute(context) : _elseBranchStatements.Execute(context));
        }