コード例 #1
0
        public override List <GBase> ToGObjectList()
        {
            List <GBase> baseList = new List <GBase>();

            GIf gif = GIf;

            List <GBase> childList = ChildConnectHole?.StatementBlock?.ToGObjectList();

            if (childList != null)
            {
                foreach (GBase child in childList)
                {
                    gif.Append((GStatement)child);
                }
            }

            baseList.Add(gif);

            List <GBase> nextList = NextConnectHole?.StatementBlock?.ToGObjectList();

            if (nextList != null)
            {
                baseList.AddRange(nextList);
            }

            return(baseList);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: silvermix/GSharp
        static void Main(string[] args)
        {
            // 코드 생성
            GEntry entry = new GEntry();

            GVariable var = new GVariable("valueA");
            GDefine   def = new GDefine(var);

            entry.Append(def);

            GEvent main     = new GEvent(new GCommand("this", "Loaded", typeof(void), GCommand.CommandType.Event));
            GSet   setValue = new GSet(var, new GNumberConst(5));

            main.Append(setValue);

            GIf ifCheck = new GIf(new GCompare(var, GCompare.ConditionType.GREATER_THEN, new GNumberConst(3)));

            ifCheck.Append(
                new GVoidCall(
                    new GCommand("Console", "WriteLine", typeof(void), GCommand.CommandType.Call),
                    new GObject[] { new GStringCat(new GStringConst("A"), new GConvertNumberToString(new GNumberConst(5))) }
                    )
                );

            main.Append(ifCheck);
            entry.Append(main);

            // 생성된 코드 컴파일
            string source     = entry.ToSource();
            string resultFile = Path.GetTempFileName();

            GCompiler        compile = new GCompiler(source);
            GCompilerResults result  = compile.Build(resultFile);

            Console.WriteLine(result.Source);

            // 코드 컴파일 결과 분석
            if (result.IsSuccess)
            {
                // 컴파일 성공
                // 컴파일된 시나리오 실행
                Console.WriteLine("컴파일 성공");
            }
            else
            {
                // 컴파일 실패
                // 컴파일 오류 출력
                foreach (CompilerError error in result.Results.Errors)
                {
                    Console.WriteLine("컴파일 오류 : " + error.Line + " - " + error.ErrorNumber + ":" + error.ErrorText);
                }
            }

            Console.ReadLine();
        }