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; } }
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; }
/// <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; }
public NodeRet(Token ret, NodeExpr value) { this.ret = ret; this.value = value; }
public NodeId(Token token) { spToken = token; }
public NodeIndex(NodeExpr target, Token spDot, NodeId index) { this.target = target; this.spDot = spDot; this.index = index; }
public NodeSuffix(NodeExpr target, Token op) { this.target = target; this.op = op; }
public NodeEnclosed(Token lparen, Token rparen, NodeExpr expr) { this.lparen = lparen; this.rparen = rparen; this.expr = expr; }
public Token SetCurrent(Token token) { var result = Current; tokens[index] = token; return result; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
public NodeInfix(NodeExpr left, NodeExpr right, Token op) { this.left = left; this.right = right; this.op = op; }
public NodeInt(Token spToken) { this.spToken = spToken; Value = spToken.IntegerValue; }
/// <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; }
public NodeBool(Token token) { spToken = token; Value = Token.Image == "true"; }
public NodeTuple(Token spLParen, Token spRParen, List<NodeExpr> values) { this.spLParen = spLParen; this.spRParen = spRParen; this.values = values; }