Irony.Compiler.LanguageCompiler.Parse C# (CSharp) Method

Parse() public method

public Parse ( Irony.Compiler.CompilerContext context, SourceFile source ) : AstNode
context Irony.Compiler.CompilerContext
source SourceFile
return AstNode
        public AstNode Parse(CompilerContext context, SourceFile source)
        {
            _context = context;
              int start = Environment.TickCount;
              Scanner.Prepare(context, source);
              IEnumerable<Token> tokenStream = Scanner.BeginScan();
              //chain all token filters
              foreach (TokenFilter filter in Grammar.TokenFilters) {
            tokenStream = filter.BeginFiltering(context, tokenStream);
              }
              //finally, parser takes token stream and produces root Ast node
              AstNode rootNode = Parser.Parse(context, tokenStream);
              _compileTime = Environment.TickCount - start;
              return rootNode;
        }

Same methods

LanguageCompiler::Parse ( string source ) : AstNode

Usage Example

        public static decimal? Compile(string sourceCode)
        {
            // create a compiler from the grammar
            FlGrammar grammar = new FlGrammar();
            LanguageCompiler compiler = new LanguageCompiler(grammar);

            // Attempt to compile into an Abstract Syntax Tree. Because FLGrammar
            // defines the root node as ProgramNode, that is what will be returned.
            // This happens to implement IJavaScriptGenerator, which is what we need.
            IExpressionGenerator program = (IExpressionGenerator)compiler.Parse(sourceCode);
            if (program == null || compiler.Context.Errors.Count > 0)
            {
                // Didn't compile.  Generate an error message.
                SyntaxError error = compiler.Context.Errors[0];
                string location = string.Empty;
                if (error.Location.Line > 0 && error.Location.Column > 0)
                {
                    location = "Line " + (error.Location.Line + 1) + ", column " + (error.Location.Column + 1);
                }
                string message = location + ": " + error.Message + ":" + Environment.NewLine;
                message += sourceCode.Split('\n')[error.Location.Line];

                throw new CompilationException(message);
            }

            // now just instruct the compilation of to javascript
            //StringBuilder js = new StringBuilder();

            var expression = program.GenerateExpression(null);
            return ((Expression<Func<decimal?>>)expression).Compile()();
        }
All Usage Examples Of Irony.Compiler.LanguageCompiler::Parse