예제 #1
0
 private bool E(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.Number:
             m_types.Push(Types.Number);
             return E(Next());
         case TokenKind.Word:
             m_types.Push(Types.Word);
             return E(Next());
         case TokenKind.Plus:
         case TokenKind.Minus:
             Types type = CheckOp(t);
             if (type != Types.Invalid)
             {
                 m_types.Push(type);
                 return E(Next());
             }
             else
             {
                 return false;
             }
         case TokenKind.EOF:
             return true;
         default:
             return false;
     }
 }
예제 #2
0
 public NodeStr(Token spToken)
 {
     this.spToken = spToken;
     Value = spToken.Image;
     Verbatim = spToken.StrVerbatim;
     CStr = spToken.StrC;
 }
예제 #3
0
 private bool CheckEOF(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.EOF:
             return true;
         default:
             return false;
     }
 }
예제 #4
0
 private bool CheckOp(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.Plus:
         case TokenKind.Minus:
             return E(Next());
         default:
             return false;
     }
 }
예제 #5
0
 private bool E(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.Number:
         case TokenKind.Word:
             Token next = Next();
             return CheckEOF(next) || CheckOp(next);
         default:
             return false;
     }
 }
예제 #6
0
        private Types CheckOp(Token t)
        {
            if (rules.ContainsKey(t.Kind))
            {
                Dictionary<Types[], Types> stub = rules[t.Kind];
                Types[] parameters = new Types[] { m_types.Pop(), m_types.Pop() };

                if (stub.ContainsKey(parameters))
                {
                    return stub[parameters];
                }
            }

            return Types.Invalid;
        }
예제 #7
0
 /// <summary>
 /// Returns a new token for an integer literal.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="image"></param>
 /// <param name="suffix"></param>
 /// <returns></returns>
 internal static Token NewInteger(Span span, ulong value, string image, string suffix)
 {
     var res = new Token(INT, span, image, tok => tok.Image + tok.NumericSuffix);
     res.IntegerValue = value;
     res.NumericSuffix = suffix;
     return res;
 }
예제 #8
0
 public NodeRet(Token ret, NodeExpr value)
 {
     this.ret = ret;
     this.value = value;
 }
예제 #9
0
 public NodeId(Token token)
 {
     spToken = token;
 }
예제 #10
0
 public NodeIndex(NodeExpr target, Token spDot, NodeId index)
 {
     this.target = target;
     this.spDot = spDot;
     this.index = index;
 }
예제 #11
0
 public NodeSuffix(NodeExpr target, Token op)
 {
     this.target = target;
     this.op = op;
 }
예제 #12
0
 public NodeEnclosed(Token lparen, Token rparen, NodeExpr expr)
 {
     this.lparen = lparen;
     this.rparen = rparen;
     this.expr = expr;
 }
예제 #13
0
 public Token SetCurrent(Token token)
 {
     var result = Current;
     tokens[index] = token;
     return result;
 }
예제 #14
0
 /// <summary>
 /// Returns a new token for a character literal.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 internal static Token NewChar(Span span, uint value)
 {
     var res = new Token(CHAR, span, char.ConvertFromUtf32((int)value), tok =>
         string.Format("'{0}'", tok.Image));
     res.CharValue = value;
     return res;
 }
예제 #15
0
 /// <summary>
 /// Returns a new token for an identifier operator.
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 internal static Token NewIdentifierOperator(Span span, string image)
 {
     var result = new Token(OP, span, image, tok => "`" + tok.Image);
     result.IsOp = true;
     return result;
 }
예제 #16
0
 /// <summary>
 /// Returns a new token for a specific reserved operator.
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 internal static Token NewOperator(TokenType type, Span span, string image)
 {
     var result = new Token(type, span, image);
     result.IsOp = true;
     return result;
 }
예제 #17
0
 /// <summary>
 /// Returns a new token for a string literal.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="verbatim"></param>
 /// <param name="cstr"></param>
 /// <returns></returns>
 internal static Token NewString(Span span, string value, bool verbatim, bool cstr)
 {
     var res = new Token(STR, span, value, tok =>
         string.Format("{0}{1}\"{2}\"", tok.StrVerbatim ? "v" : "", tok.StrC ? "c" : "", value));
     res.StrVerbatim = verbatim;
     res.StrC = cstr;
     return res;
 }
예제 #18
0
 public NodeInfix(NodeExpr left, NodeExpr right, Token op)
 {
     this.left = left;
     this.right = right;
     this.op = op;
 }
예제 #19
0
 public NodeInt(Token spToken)
 {
     this.spToken = spToken;
     Value = spToken.IntegerValue;
 }
예제 #20
0
 /// <summary>
 /// Returns a new token for a float literal.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="image"></param>
 /// <param name="suffix"></param>
 /// <returns></returns>
 internal static Token NewFloat(Span span, double value, string image, string suffix)
 {
     var res = new Token(FLOAT, span, image, tok => tok.Image + tok.NumericSuffix);
     res.FloatValue = value;
     res.NumericSuffix = suffix;
     return res;
 }
예제 #21
0
 public NodeBool(Token token)
 {
     spToken = token;
     Value = Token.Image == "true";
 }
예제 #22
0
 public NodeTuple(Token spLParen, Token spRParen, List<NodeExpr> values)
 {
     this.spLParen = spLParen;
     this.spRParen = spRParen;
     this.values = values;
 }