コード例 #1
0
        public override int VisitStart([NotNull] CBluntParser.StartContext context)
        {
#if DEBUG
            Console.WriteLine("Beginning semantic checking");
            Console.WriteLine("VisitStart");
#endif

            // Determine whether the entry point exists
            var mainMethodProperties = GetMethodProperties("Main");

            if (mainMethodProperties == null)
            {
                Console.WriteLine("Syntax error! There must exists a method with following properties: void Main() { }");
                return(1);
            }

            if (mainMethodProperties.Type != "void")
            {
                Console.WriteLine("Syntax error! There must exists a method with following properties: void Main() { }");
                return(1);
            }

#if DEBUG
            Console.WriteLine("Finished semantic checking");
#endif

            return(base.VisitStart(context));
        }
コード例 #2
0
        public override int VisitStart([NotNull] CBluntParser.StartContext context)
        {
#if DEBUG
            Console.WriteLine("Beginning symbol table generation");
            Console.WriteLine("VisitStart");
#endif
            // Create API methods first
            CreateAPIMethods();

            // Only visit functions as that is required of symboltable so far
            for (int i = 0; i < context.function().Count(); ++i)
            {
                Visit(context.function(i));
            }

#if DEBUG
            Console.WriteLine("Finished symbol table generation");
#endif
            return(0);
        }
コード例 #3
0
ファイル: CodeGenerator.cs プロジェクト: sw417f19/CBlunt
        public override int VisitStart([NotNull] CBluntParser.StartContext context)
        {
#if DEBUG
            Console.WriteLine("Beginning code generation");
            Console.WriteLine("VisitStart");
#endif
            this.imports.Add("using System;\n");
            this.AddText("namespace CBCode { \n class Program { \n");

            //We visit all children to initiate their translations
            for (int count = 0; count < context.ChildCount; ++count)
            {
                Visit(context.GetChild(count));
                if (context.GetChild(count).GetText() == ";")
                {
                    this.AddSemicolon();
                }
            }
            this.AddText("\n}");
            this.AddText("\n}");

            string collectedimports = "";
            for (int counter = 0; counter < this.imports.Count(); ++counter)
            {
                collectedimports += this.imports[counter] + "\n";
            }
            this.filecontent = collectedimports + this.filecontent;

            //After translation is done, the contents are saved to a file
            using (StreamWriter stream = File.CreateText(this.filepath))
            {
                stream.WriteLine(this.filecontent);
            }
#if DEBUG
            Console.WriteLine("Finished code generation");
#endif
            return(0);
        }
コード例 #4
0
ファイル: CBluntBaseVisitor.cs プロジェクト: sw417f19/CBlunt
 /// <summary>
 /// Visit a parse tree produced by <see cref="CBluntParser.start"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitStart([NotNull] CBluntParser.StartContext context)
 {
     return(VisitChildren(context));
 }