Example #1
0
        //List<SkryptClass> Classes = new List<SkryptClass>();

        public SkryptEngine()
        {
            tokenizer        = new Tokenizer(this);
            statementParser  = new StatementParser(this);
            expressionParser = new ExpressionParser(this);
            generalParser    = new GeneralParser(this);
            methodParser     = new MethodParser(this);
            analizer         = new Analizer(this);
            executor         = new Executor(this);
            standardMethods  = new StandardMethods(this);

            standardMethods.AddMethodsToEngine();

            //Constants["_PI"] = new Numeric(Math.PI);
            //Constants["_E"] = new Numeric(Math.E);

            SkryptObject SystemObject = ObjectGenerator.MakeObjectFromClass(typeof(Library.Native.System));

            foreach (SkryptProperty property in SystemObject.Properties)
            {
                GlobalScope.AddVariable(property.Name, property.Value, true);
            }

            // Tokens that are found using a token rule with type defined as 'null' won't get added to the token list.
            // This means you can ignore certain characters, like whitespace in this case, that way.
            tokenizer.AddRule(
                new Regex(@"\s"),
                TokenTypes.None
                );

            tokenizer.AddRule(
                new Regex(@"\d+(\.\d+)?"),
                TokenTypes.NumericLiteral
                );

            tokenizer.AddRule(
                new Regex(@"[_a-zA-Z]+[_a-zA-Z0-9]*"),
                TokenTypes.Identifier
                );

            tokenizer.AddRule(
                new Regex(@"class|func|if|elseif|else|while"),
                TokenTypes.Keyword
                );

            tokenizer.AddRule(
                new Regex("true|false"),
                TokenTypes.BooleanLiteral
                );

            tokenizer.AddRule(
                new Regex("null"),
                TokenTypes.NullLiteral
                );

            tokenizer.AddRule(
                new Regex(@"[;]"),
                TokenTypes.EndOfExpression
                );

            tokenizer.AddRule(
                new Regex(@"(return)|(&&)|(\|\|)|(\|\|\|)|(==)|(!=)|(>=)|(<=)|(<<)|(>>)|(>>>)|(\+\+)|(--)|[~=:<>+\-*/%^&|!\[\]\(\)\.\,{}]"),
                TokenTypes.Punctuator
                );

            tokenizer.AddRule(
                new Regex(@""".*?(?<!\\)"""),
                TokenTypes.StringLiteral
                );

            // Multi line comment
            tokenizer.AddRule(
                new Regex(@"\/\*(.|\n)*\*\/"),
                TokenTypes.None
                );

            // Single line comment
            tokenizer.AddRule(
                new Regex(@"\/\/.*\n"),
                TokenTypes.None
                );
        }