Esempio n. 1
0
        private Lexer(string text, TextReader reader, LexerBehavior behavior, LexerSettings settings)
        {
            if (settings == null)
            {
                settings = LexerSettings.Default;
            }
            else
            {
                settings = settings.Clone();
            }

            this.text     = text;
            this.reader   = reader;
            this.behavior = behavior;
            this.settings = settings;

            if (settings.Symbols != null)
            {
                foreach (KeyValuePair <string, int> entry in settings.Symbols)
                {
                    int len = entry.Key.Length;
                    if (len > maxSymLen)
                    {
                        maxSymLen = len;
                    }
                }
            }

            Reset();
        }
Esempio n. 2
0
File: Parser.cs Progetto: sbarisic/V
        public Parser()
        {
            LB         = LexerBehavior.SkipComments | LexerBehavior.SkipWhiteSpaces | LexerBehavior.Default;
            LS         = LexerSettings.Default;
            LS.Options = LexerOptions.StringDoubleQuote | LexerOptions.StringEscaping;

            LS.Keywords = new Dictionary <string, int>();
            string[] KeywordNames = Enum.GetNames(typeof(Keyword));
            for (int i = 0; i < KeywordNames.Length; i++)
            {
                if (KeywordNames[i].StartsWith("_"))
                {
                    continue;
                }
                LS.Keywords.Add(KeywordNames[i].ToLower(), (int)(Keyword)Enum.Parse(typeof(Keyword), KeywordNames[i]));
            }

            LS.Symbols = new Dictionary <string, int>();
            LS.Symbols.Add("(", (int)Symbol.LParen);
            LS.Symbols.Add(")", (int)Symbol.RParen);
            LS.Symbols.Add("{", (int)Symbol.LCurvy);
            LS.Symbols.Add("}", (int)Symbol.RCurvy);
            LS.Symbols.Add(",", (int)Symbol.Comma);
            LS.Symbols.Add(";", (int)Symbol.Semicolon);
            LS.Symbols.Add("=", (int)Symbol.Assign);
        }
Esempio n. 3
0
        public Token PeekNextToken(LexerBehavior behavior)
        {
            LexerBehavior saveBehavior = this.behavior;

            this.behavior = behavior;
            try {
                return(PeekNextToken());
            } finally {
                this.behavior = saveBehavior;
            }
        }
Esempio n. 4
0
 public Lexer(string text, LexerBehavior behavior)
     : this(text, null, behavior, null)
 {
 }
Esempio n. 5
0
 public Lexer(string text, LexerBehavior behavior, LexerSettings settings)
     : this(text, null, behavior, settings)
 {
 }
Esempio n. 6
0
 public Lexer(TextReader reader, LexerBehavior behavior)
     : this(null, reader, behavior, null)
 {
 }
Esempio n. 7
0
 public Lexer(TextReader reader, LexerBehavior behavior, LexerSettings settings)
     : this(null, reader, behavior, settings)
 {
 }