public Statement GetStatement() { var typeInfo = semanticModel.GetTypeInfo(literalExpressionSyntax); var constantStatement = new ConstantStatement(literalExpressionSyntax.Token.Value); if (literalExpressionSyntax.Token.Value != null) { constantStatement.Type = typeInfo.GetClassType(); } return(constantStatement); }
/// <summary> /// Parses a statement. /// </summary> public static bool AcceptStatement(string Text, int Start, out Statement Statement, out int LastChar) { // Constant assignment string varname; if (AcceptString(Text, Start, "const", out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { if (AcceptWord(Text, LastChar, out varname, out LastChar) && ValidVariable(varname)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { if (AcceptString(Text, LastChar, "=", out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { Expression value; if (AcceptExpression(Text, LastChar, out value, out LastChar)) { AcceptWhitespace(Text, LastChar, out LastChar); if (AcceptString(Text, LastChar, ";", out LastChar)) { Statement = new ConstantStatement(varname, value); return true; } } } } } } } } // Define Expression type; if (AcceptTightExpression(Text, Start, out type, out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { if (AcceptWord(Text, LastChar, out varname, out LastChar) && ValidVariable(varname)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { if (AcceptString(Text, LastChar, "=", out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { Expression value; if (AcceptExpression(Text, LastChar, out value, out LastChar)) { AcceptWhitespace(Text, LastChar, out LastChar); if (AcceptString(Text, LastChar, ";", out LastChar)) { Statement = new DefineStatement(type, varname, value); return true; } } } } } } } } // Assign if (AcceptWord(Text, Start, out varname, out LastChar) && ValidVariable(varname)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { if (AcceptString(Text, LastChar, "=", out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { Expression value; if (AcceptExpression(Text, LastChar, out value, out LastChar)) { AcceptWhitespace(Text, LastChar, out LastChar); if (AcceptString(Text, LastChar, ";", out LastChar)) { Statement = new AssignStatement(varname, value); return true; } } } } } } // Return if (AcceptString(Text, Start, "return", out LastChar)) { if (AcceptWhitespace(Text, LastChar, out LastChar) > 0) { Expression returnvalue; if (AcceptExpression(Text, LastChar, out returnvalue, out LastChar)) { AcceptWhitespace(Text, LastChar, out LastChar); if (AcceptString(Text, LastChar, ";", out LastChar)) { Statement = new ReturnStatement(returnvalue); return true; } } } } Statement = null; return false; }
public ConstantExpressionInterpreter(ConstantStatement statement) { this.statement = statement; }