Ejemplo n.º 1
0
        public SkryptEngine(string code = "")
        {
            _code = code;

            Tokenizer        = new Tokenizer(this);
            TokenProcessor   = new TokenProcessor(this);
            StatementParser  = new StatementParser(this);
            ExpressionParser = new ExpressionParser(this);
            GeneralParser    = new GeneralParser(this);
            MethodParser     = new FunctionParser(this);
            ModifierChecker  = new ModifierChecker(this);
            ClassParser      = new ClassParser(this);
            Analizer         = new Analizer(this);
            Executor         = new Executor(this);

            var systemObject = ObjectGenerator.MakeObjectFromClass(typeof(Library.Native.System), this);

            GlobalScope.SetVariable(systemObject.Name, systemObject, Modifier.Const);
            CurrentScope = GlobalScope;

            // 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+)?([eE][-+]?\d+)?"),
                TokenTypes.NumericLiteral
                );

            Tokenizer.AddRule(
                new Regex(@"0x([A-Fa-f\d])*"),
                TokenTypes.HexadecimalLiteral
                );

            Tokenizer.AddRule(
                new Regex(@"0b([01])*"),
                TokenTypes.BinaryLiteral
                );

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

            Tokenizer.AddRule(
                new Regex(@"include|const|using|public|private|strong|in|class|fn|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(
                    @"(import)|(return)|(continue)|(break)|(&&)|(\+=)|(\-=)|(\/=)|(\*=)|(\%=)|(\^=)|(\&=)|(\|=)|(\|\|\|=)|(\|\|\|)|(\|\|)|(=>)|(==)|(!=)|(>=)|(<=)|(<<)|(>>>)|(>>)|(\+\+)|(--)|[~=<>+\-*/%^&|!\[\]\(\)\.\,{}\?\:]"),
                TokenTypes.Punctuator
                );

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

            // Multi line comment
            Tokenizer.AddRule(
                new Regex(@"\/\*.*?\*\/", RegexOptions.Singleline),
                TokenTypes.None
                );

            Tokenizer.AddRule(
                new Regex(@""".*?(?<!\\)""", RegexOptions.Singleline),
                TokenTypes.StringLiteral
                );
        }
Ejemplo n.º 2
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
                );
        }