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;
     }
 }
Beispiel #2
0
 public NodeStr(Token spToken)
 {
     this.spToken = spToken;
     Value = spToken.Image;
     Verbatim = spToken.StrVerbatim;
     CStr = spToken.StrC;
 }
 private bool CheckEOF(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.EOF:
             return true;
         default:
             return false;
     }
 }
 private bool CheckOp(Token t)
 {
     switch (t.Kind)
     {
         case TokenKind.Plus:
         case TokenKind.Minus:
             return E(Next());
         default:
             return false;
     }
 }
 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;
     }
 }
        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;
        }
Beispiel #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;
 }
Beispiel #8
0
 public NodeRet(Token ret, NodeExpr value)
 {
     this.ret = ret;
     this.value = value;
 }
Beispiel #9
0
 public NodeId(Token token)
 {
     spToken = token;
 }
Beispiel #10
0
 public NodeIndex(NodeExpr target, Token spDot, NodeId index)
 {
     this.target = target;
     this.spDot = spDot;
     this.index = index;
 }
Beispiel #11
0
 public NodeSuffix(NodeExpr target, Token op)
 {
     this.target = target;
     this.op = op;
 }
Beispiel #12
0
 public NodeEnclosed(Token lparen, Token rparen, NodeExpr expr)
 {
     this.lparen = lparen;
     this.rparen = rparen;
     this.expr = expr;
 }
Beispiel #13
0
 public Token SetCurrent(Token token)
 {
     var result = Current;
     tokens[index] = token;
     return result;
 }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #18
0
 public NodeInfix(NodeExpr left, NodeExpr right, Token op)
 {
     this.left = left;
     this.right = right;
     this.op = op;
 }
Beispiel #19
0
 public NodeInt(Token spToken)
 {
     this.spToken = spToken;
     Value = spToken.IntegerValue;
 }
Beispiel #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;
 }
Beispiel #21
0
 public NodeBool(Token token)
 {
     spToken = token;
     Value = Token.Image == "true";
 }
Beispiel #22
0
 public NodeTuple(Token spLParen, Token spRParen, List<NodeExpr> values)
 {
     this.spLParen = spLParen;
     this.spRParen = spRParen;
     this.values = values;
 }