public override Token Match(Lexer lexer)
        {
            var rem = lexer.RemainingInput;
            if (lexer.CanRead) {
                string value = null;
                var match = singleCharRe.Match(rem);
                if (match.Success) {
                    value = match.Value;
                } else if ((match = escapeCharRe.Match(rem)).Success) {
                    value = match.Value;
                } else if ((match = hexEscapeRe.Match(rem)).Success) {
                    value = match.Value;
                } else if ((match = unicEscapeRe.Match(rem)).Success) {
                    value = match.Value;
                }

                if (null != value) {
                    var tok = new Token() { Line = lexer.Line, Col = lexer.Col };
                    tok.Sym = Sym.CharLiteral;
                    tok.Value = value.Substring(1, value.Length - 2); ;
                    lexer.Advance(value.Length);

                    return tok;
                }
            }

            return null;
        }
Ejemplo n.º 2
0
        public override Token Match(Lexer lexer)
        {
            bool isKeyword = false;
            string word = string.Empty;
            using (var la = new LookaheadFrame(lexer)) {
                var c = lexer.NextChar();
                if (IsIdentifierStartChar(c)) {
                    var tok = new Token() { Line = lexer.Line, Col = lexer.Col, Sym = Sym.Id };
                    var sb = new StringBuilder();
                    sb.Append(c);
                    while (IsIdentifierPartChar(lexer.Peek())) {
                        sb.Append(lexer.NextChar());
                    }

                    //Since the id rule tries to match before any
                    //reserved-word ones, we need to make sure this id isn't
                    //actually a keyword
                    word = sb.ToString();
                    isKeyword = lexer.KeywordTable.ContainsKey(word);
                    if (!isKeyword) {
                        la.Commit();
                        tok.Value = word;
                        return tok;
                    }
                }
            }

            //If it is a kw, invoke that rule instead
            if (isKeyword) {
                return lexer.KeywordTable[word].Match(lexer);
            }

            return null;
        }
        //TODO: 'Verbatim' string handling (e.g. @"...")
        public override Token Match(Lexer lexer)
        {
            if (lexer.CanRead) {
                var match = simpleLit.Match(lexer.RemainingInput);
                if (match.Success) {
                    var tok = new Token() { Line = lexer.Line, Col = lexer.Col };
                    tok.Sym = Sym.StringLiteral;
                    tok.Value = match.Value.Substring(1, match.Value.Length - 2);
                    lexer.Advance(match.Value.Length);
                    return tok;
                }
            }

            return null;
        }
        public override Token Match(Lexer lexer)
        {
            var tok = new Token() { Line = lexer.Line, Col = lexer.Col };
            string rem = lexer.RemainingInput;
            bool isMatch = false;

            Match match = hexIntLit.Match(rem);
            if (match.Success) {
                tok.Value = match.Value;
                tok.Sym = Sym.HexIntLiteral;
                isMatch = true;
            }

            foreach (var re in realRes) {
                match = re.Match(rem);
                if (match.Success) {
                    tok.Value = match.Value;
                    tok.Sym = Sym.RealLiteral;
                    isMatch = true;
                    break;
                }
            }

            if (!isMatch) {
                match = decIntLit.Match(rem);
                if (match.Success) {
                    tok.Value = match.Value;
                    tok.Sym = Sym.IntLiteral;
                    isMatch = true;
                }
            }

            if (isMatch) {
                lexer.Advance(tok.Value.Length);
                return tok;
            }

            return null;
        }
Ejemplo n.º 5
0
 public ExpList(Token start)
     : base(start)
 {
     this.Exps = new List<Exp>();
 }
Ejemplo n.º 6
0
 public BaseIndexerAccessExp(Token start, Exp es)
     : base(start)
 {
     var elist = es as ExpList;
     if (null != elist)
         this.IndexerExps = elist;
     else this.IndexerExps = new ExpList(es.StartToken) { Exps = new List<Exp>() { es } };
 }
Ejemplo n.º 7
0
 protected Exp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 8
0
 protected LiteralExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 9
0
 public MemberInitializerExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 10
0
 public InclusiveOrExp(Token start)
     : base(start, Op.InclusiveOr)
 {
 }
Ejemplo n.º 11
0
 public InvocationExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 12
0
 public CheckedExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 13
0
 public ConditionalAndExp(Token start)
     : base(start, Op.BooleanAnd)
 {
 }
Ejemplo n.º 14
0
 public CastExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 15
0
 public CharLiteralExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 16
0
 public BooleanLiteralExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 17
0
 public BitwiseAndExp(Token start)
     : base(start, Op.BitwiseAnd)
 {
 }
Ejemplo n.º 18
0
 protected BinaryExp(Token start, Op op)
     : base(start)
 {
     this.Op = op;
 }
Ejemplo n.º 19
0
 public IdExp(Token spelling)
     : base(spelling)
 {
     this.Spelling = spelling;
 }
Ejemplo n.º 20
0
 public ConditionalExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 21
0
 public ImplicitAnonFunctionSig(Token start)
     : base(start)
 {
 }
Ejemplo n.º 22
0
 public ConditionalOrExp(Token start)
     : base(start, Op.BooleanOr)
 {
 }
Ejemplo n.º 23
0
 public IntLiteralExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 24
0
 public AttrSection(Token start)
     : base(start)
 {
 }
Ejemplo n.º 25
0
 public AdditiveExp(Token start, Op op)
     : base(start, op)
 {
 }
Ejemplo n.º 26
0
 public EqualityExp(Token start, Op eqOp)
     : base(start, eqOp)
 {
 }
Ejemplo n.º 27
0
 public MemberAccessExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 28
0
 public ExclusiveOrExp(Token start)
     : base(start, Op.ExclusiveOr)
 {
 }
Ejemplo n.º 29
0
 public DefaultValueExp(Token start)
     : base(start)
 {
 }
Ejemplo n.º 30
0
 protected BaseAccessExp(Token start)
     : base(start)
 {
 }