示例#1
0
        static void Main(string[] args)
        {
            var session = new Session();

            session.PrimitiveBool = session.CreatePrimitiveStruct(Name.FromPath("Bool"));
            session.PrimitiveInt  = session.CreatePrimitiveStruct(Name.FromPath("Int"));
            session.PrimitiveUInt = session.CreatePrimitiveStruct(Name.FromPath("UInt"));

            var input        = TextInput.MakeFromFile("../../test.tr");
            var tokens       = Tokenizer.Tokenize(session, input);
            var topLevelNode = ASTParser.Parse(session, tokens);

            if (topLevelNode != null)
            {
                //topLevelNode.PrintDebugRecursive("");

                var resolver = new DeclResolver(session);
                resolver.ResolveTopLevelDeclGroup(topLevelNode);
                resolver.ResolveStructFields();
                if (!StructRecursionChecker.Check(session))
                {
                    resolver.ResolveFunctHeaders();
                    resolver.ResolveFunctBodies();
                    session.PrintDeclsToConsole(true);

                    Console.WriteLine("==== CODEGEN ====");
                    Console.WriteLine(Codegen.CGenerator.Generate(session));
                }
            }

            session.PrintMessagesToConsole();
            Console.ReadKey();
        }
示例#2
0
文件: Sql.cs 项目: ithanshui/Vasily
 public static SqlCP GetCP(string script)
 {
     if (Cache.ContainsKey(script))
     {
         return(Cache[script].Clone());
     }
     else
     {
         ASTParser <T> parser = new ASTParser <T>();
         SqlCP         cp     = new object().Condition(parser.GetCondition(script));
         Cache[script] = cp;
         return(cp);
     }
 }
        public static ASTParser Build(Lexer lexer)
        {
            var astParser = new ASTParser(lexer);

            var numberDescription = new LiteralExpressionDescription(TokenType.Number, 0);

            astParser.AddExpression(numberDescription);

            astParser.AddExpression(new UnaryExpressionDescription(TokenType.Minus, 5));

            astParser.AddExpression(new BinaryExpressionDescription(numberDescription, TokenType.Plus, numberDescription, 1));
            astParser.AddExpression(new BinaryExpressionDescription(numberDescription, TokenType.Minus, numberDescription, 1));

            astParser.AddExpression(new BinaryExpressionDescription(numberDescription, TokenType.Star, numberDescription, 2));
            astParser.AddExpression(new BinaryExpressionDescription(numberDescription, TokenType.Slash, numberDescription, 2));

            astParser.AddExpression(new BlockExpressionDescription(TokenType.OpenParenthesis, TokenType.CloseParenthesis, 4));

            astParser.AddExpression(new LiteralExpressionDescription(TokenType.EOF, -1));

            return(astParser);
        }
示例#4
0
 static void DisplayAST(ASTParser astParser, string line)
 {
     astParser.Parse(line);
     Console.Write(astParser.LastExpression);
 }
        public bool Run(
            string projectAssembly,
            string sourceDirectory,
            IList <string> sourceFiles,
            IList <string> generationList,
            IWriter writer,
            TextFormatter textFormatter,
            IDictionary <string, string> typeOverrideMap,
            ASTParserType parserType = ASTParserType.Sdcb
            )
        {
            var overallStopwatch = Stopwatch.StartNew();
            var stopwatch        = Stopwatch.StartNew();

            GlobalLogger.Info($"=== Consolidate Source Files");
            var sourceFilesAsText = GetSourceFilesAsSingleTextString(
                sourceDirectory,
                sourceFiles
                );

            GlobalLogger.Info($"=== Consolidated Source Files | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generated AST - {parserType}");
            var ast = ASTParser.ParseText(
                sourceFilesAsText,
                new ASTParserOptions
            {
                ParserType = parserType,
            }
                );

            GlobalLogger.Info($"=== Generated AST | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");
            var notGeneratedClassNames = new List <string>();

            var generatedStatements = new List <GeneratedStatement>();

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Cached Entity Object");
            var cachedEntityObject = GenerateCachedEntityObject.GenerateClassStatement();

            generatedStatements.Add(
                new GeneratedStatement(
                    cachedEntityObject,
                    GenerateCachedEntityObject.GenerateString()
                    )
                );
            GlobalLogger.Info($"=== Generated Cached Entity Object | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Class Statements");
            var generatedClassStatements = GenerateClassFromList(
                ast,
                projectAssembly,
                generationList,
                notGeneratedClassNames,
                typeOverrideMap,
                new List <ClassStatement> {
                cachedEntityObject
            }
                );

            generatedClassStatements.Remove(cachedEntityObject);
            GlobalLogger.Info($"=== Generated Class Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Statements");
            foreach (var generatedStatement in generatedClassStatements)
            {
                generatedStatements.Add(
                    new GeneratedStatement(
                        generatedStatement,
                        GenerateClassStatementString.Generate(
                            generatedStatement,
                            textFormatter
                            )
                        )
                    );
            }
            GlobalLogger.Info($"=== Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generating Shimmed Classes");
            foreach (var notGeneratedInterfaceName in notGeneratedClassNames)
            {
                if (!JavaScriptProvidedApiIdentifier.Identify(notGeneratedInterfaceName, out _))
                {
                    var classShim = GenerateClassShim.GenerateClassStatement(
                        notGeneratedInterfaceName
                        );
                    generatedStatements.Add(
                        new GeneratedStatement(
                            classShim,
                            textFormatter.Format(
                                GenerateClassShim.GenerateString(
                                    classShim
                                    )
                                )
                            )
                        );
                    GlobalLogger.Info($"=== Generated Shimmed Class: {notGeneratedInterfaceName}");
                }
            }
            GlobalLogger.Info($"=== Generated Shimmed Classes | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            // Write Generated Statements to Passed in Writer
            stopwatch.Restart();
            GlobalLogger.Info($"=== Writing Generated Statements");
            writer.Write(
                generatedStatements
                );
            GlobalLogger.Info($"=== Finished Writing Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            GlobalLogger.Success($"=== Finished Run | ElapsedTime: {overallStopwatch.ElapsedMilliseconds}ms");

            return(true);
        }