private static Number ( string expression, int &index ) : double | ||
expression | string | |
index | int | |
리턴 | double |
private static double Number(string expression, ref int index)
{
int endIndex = index;
while(endIndex < expression.Length && (char.IsDigit(expression[endIndex]) || expression[endIndex] == '.'))
{
++endIndex;
}
double result = double.Parse(expression.Substring(index, endIndex - index));
index = endIndex;
return result;
}
private Expression F() { if (lexer.Current == LexicalToken.Id) { var result = Expression.Identifier(lexer.Value); AddVariable(lexer.Value); lexer.Next(); return(result); } else if (lexer.Current == LexicalToken.Num) { var result = Expression.Number(lexer.Value); lexer.Next(); return(result); } else if (lexer.Current == LexicalToken.OpenPar) { lexer.Next(); var e = E(); lexer.Expect(LexicalToken.ClosePar); return(Expression.Parenthesis(e)); } else { throw new ApplicationException(String.Format("Parse error: Incorrent token '{0}' encountered. Expected ')'.", lexer.Value)); } }