program() public méthode

public program ( ) : ES3Parser.program_return
Résultat ES3Parser.program_return
Exemple #1
0
        public JavaScriptAst Create()
        {
            CreateTokenStream();
            var parser = new ES3Parser(tokenStream);

            programReturn = parser.program();
            return(new JavaScriptAst(tokenStream, programReturn.Tree as CommonTree));
        }
Exemple #2
0
        public static IList <JsStatement> ParseProgram(string source)
        {
            var lex = new ES3Lexer(new ANTLRStringStream(source));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            var parser = new ES3Parser(tokens);

            var r    = parser.program();
            var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree));

            return(tree.program());
        }
        public static Program Compile(string source, bool debugInformation) {
            Program program = null;
            if (!string.IsNullOrEmpty(source)) {
                var lexer = new ES3Lexer(new ANTLRStringStream(source));
                var parser = new ES3Parser(new CommonTokenStream(lexer)) { DebugMode = debugInformation };

                program = parser.program().value;

                if (parser.Errors != null && parser.Errors.Count > 0) {
                    throw new JintException(String.Join(Environment.NewLine, parser.Errors.ToArray()));
                }
            }

            return program;
        }
Exemple #4
0
        public static Program Compile(string source, bool debugInformation)
        {
            Program program = (Program)null;

            if (!string.IsNullOrEmpty(source))
            {
                ES3Parser es3Parser = new ES3Parser((ITokenStream) new CommonTokenStream((ITokenSource) new ES3Lexer((ICharStream) new ANTLRStringStream(source))))
                {
                    DebugMode = debugInformation
                };
                program = es3Parser.program().value;
                if (es3Parser.Errors != null && es3Parser.Errors.Count > 0)
                {
                    throw new JintException(string.Join(Environment.NewLine, es3Parser.Errors.ToArray()));
                }
            }
            return(program);
        }
Exemple #5
0
        internal void Analyze(List<string> Codes)
        {
            RawLines.Clear();
            StringBuilder CodeBuilder = new StringBuilder();
            foreach (string C in Codes)
            {
                RawLines.AddRange(C.Split(new string[] { "\r\n" }, StringSplitOptions.None));
                CodeBuilder.Append(C);
            }
            string Code = CodeBuilder.ToString();
            if (Code.Length == 0) return;
            JintEngine Eng = new JintEngine(Options.Ecmascript3);

            ES3Lexer Lexer = new ES3Lexer(new ANTLRStringStream(Code));
            ES3Parser Parser = new ES3Parser(new CommonTokenStream(Lexer)) { DebugMode = true };
            Jint.Expressions.Program Prog = Parser.program().value;
            JintStack.Clear();
            Analyze(Prog.Statements);
        }
Exemple #6
0
        internal static LinkedList<Statement> GetStatementsFromCode(List<string> Codes, bool IgnoreErrors)
        {
            StringBuilder CodeBuilder = new StringBuilder();
            foreach (string C in Codes)
            {
                CodeBuilder.Append(C);
                if (!C.EndsWith("\n"))
                {
                    CodeBuilder.Append("\r\n");
                }
            }
            string Code = CodeBuilder.ToString();
            if (Code.Length == 0) return new LinkedList<Statement>();
            JintEngine Eng = new JintEngine(Options.Ecmascript3);

            ES3Lexer Lexer = new ES3Lexer(new ANTLRStringStream(Code));
            ES3Parser Parser = new ES3Parser(new CommonTokenStream(Lexer)) { DebugMode = true };
            Jint.Expressions.Program Prog = Parser.program().value;
            if (Parser.Errors != null && Parser.Errors.Count > 0 && !IgnoreErrors)
            {
                throw new Exception("Invalid JavaScript Syntax");
            }
            return Prog.Statements;
        }