_Core/Lang/Parser/Parser.cs

(开头部分) 50KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ComLib.Lang.Helpers;

namespace ComLib.Lang
{
    /// <summary>
    /// Uses the Lexer to parse script in terms of sequences of Statements and Expressions;
    /// Each statement and expression is a sequence of Tokens( see Lexer )
    /// Main method is Parse(script) and ParseStatement();
    /// 
    /// 1. var name = "kishore";
    /// 2. if ( name == "kishore" ) print("true");
    /// 
    /// Statements:
    /// 
    /// VALUE:         TYPE:
    /// 1. AssignStmt ( "var name = "kishore"; )
    /// 2. IfStmt ( "if (name == "kishore" ) { print ("true"); }
    /// </summary>
    public class Parser : ParserBase, ILangParser
    {
        /// <summary>
        /// Initialize the context.
        /// </summary>
        /// <param name="context"></param>
        public Parser(Context context) : base(context)
        {
        }


        #region Public API
        /*
            TODO:
            - fluent call - 4 parts
            - order by for linq
            - scanner performance improvements
            - lexer line tracking
        */
        /// <summary>
        /// Parses the script into statements and expressions.
        /// </summary>
        /// <param name="script">Script text</param>
        /// <param name="memory">Memory scope object</param>
        public List<Stmt> Parse(string script, Memory memory = null)
        {
            // 1. Initalize data members
            Init(script, memory);

            // 2. Convert script to sequence of tokens.
            Tokenize();

            // 3. Initialize the combinators.
            _context.Plugins.RegisterSystem();
            _context.Plugins.ForEach<IStmtPlugin>(plugin =>  plugin.Init(this, _tokenIt));
            _context.Plugins.ForEach<IExprPlugin>(plugin =>  plugin.Init(this, _tokenIt));
            _context.Plugins.ForEach<ITokenPlugin>(plugin => plugin.Init(this, _tokenIt));
后面还有 1223 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。