Esempio n. 1
0
        // 컴파일
        public string GetSource()
        {
            try
            {
                GEntry       entry = new GEntry();
                List <GBase> list  = new List <GBase>();

                foreach (VariableBlock variableBlock in GetGlobalVariableBlockList())
                {
                    entry.Append(new GDefine(variableBlock.GVariable));
                }

                foreach (var block in Master.Children)
                {
                    if (block is ScopeBlock)
                    {
                        ScopeBlock scopeBlock = block as ScopeBlock;
                        entry.Append(scopeBlock.GScope);
                    }
                }

                return(entry.ToSource().TrimStart());
            }
            catch (ToObjectException e)
            {
                return(e.Message);
            }
        }
Esempio n. 2
0
        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();
        }