本文整理汇总了C#中Position.MoveIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Position.MoveIndex方法的具体用法?C# Position.MoveIndex怎么用?C# Position.MoveIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.MoveIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseStringConstant
private string ParseStringConstant(string code, Position position, List<Index> indices)
{
string result = "";
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
while ((code.Length > position.CurrentIndex) && (code[position.CurrentIndex] != '"'))
{
result += code[position.CurrentIndex];
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
}
if (code.Length > position.CurrentIndex) // record last (")
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
}
return result;
}
示例2: ParseNumricConstant
private string ParseNumricConstant(string code, Position position, List<Index> indices)
{
double mantissa = 0;
double fraction = 0;
// Look for the integral part
while ((code.Length > position.CurrentIndex) && (Char.IsDigit(code[position.CurrentIndex])))
{
mantissa = (mantissa * 10.0) + (code[position.CurrentIndex] - '0');
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
}
// Now look for the fractional part
if ((code.Length > position.CurrentIndex) && (code[position.CurrentIndex] == '.'))
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
double t = .1;
while ((code.Length > position.CurrentIndex) && (Char.IsDigit(code[position.CurrentIndex])))
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
fraction = fraction + (t * (code[position.CurrentIndex] - '0'));
position.MoveIndex();
t = t / 10.0;
}
}
mantissa = (mantissa + fraction);
return mantissa.ToString();
}
示例3: GenerateList
private void GenerateList(string code, int startLine, int startPosition)
{
var position = new Position(code, startLine, startPosition);
while (true)
{
// completed?
if (position.CurrentIndex > code.Length - 1)
break;
// new indices
List<Index> indices = new List<Index>();
// parse comments
ParseComments(code, position, true);
// add tokens
if (code.Length > position.CurrentIndex)
switch (code[position.CurrentIndex])
{
case '+':
case '-':
case '*':
case '/':
case '\\':
case '%':
case '^':
case '<':
case '>':
case '&':
case '|':
case '!':
case '?':
case '=':
indices.Add(new Index(position.LineNumber, position.CharNumber));
tokens.Add(new Token(TokenType.OPERATOR, code[position.CurrentIndex].ToString(), indices));
position.MoveIndex();
break;
case '(':
case ')':
case ';':
case '{':
case '}':
case '[':
case ']':
case '\'':
case '`':
case '_':
case ',':
case '.':
case ':':
case '$':
case '#':
case '@':
case '~':
indices.Add(new Index(position.LineNumber, position.CharNumber));
tokens.Add(new Token(TokenType.SYMBOL, code[position.CurrentIndex].ToString(), indices));
position.MoveIndex();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
string num = ParseNumricConstant(code, position, indices);
tokens.Add(new Token(TokenType.NUMBER, num, indices));
break;
case '"':
string str = ParseStringConstant(code, position, indices);
tokens.Add(new Token(TokenType.STRING, str, indices));
break;
default:
// must be identifier
if (!Char.IsLetter(code[position.CurrentIndex]))
throw new EngineException(EngineException.ExceptionType.BadInput, "bad/unexpected input of Value '" + code[position.CurrentIndex] + "'", new Token(TokenType.SYMBOL, code[position.CurrentIndex].ToString(), indices));
string identifier = string.Empty;
while ((code.Length > position.CurrentIndex) && (Char.IsLetterOrDigit(code[position.CurrentIndex])))
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
identifier += code[position.CurrentIndex];
position.MoveIndex();
}
if (IsKeyword(identifier))
tokens.Add(new Token(TokenType.KEYWORD, identifier, indices));
else
tokens.Add(new Token(TokenType.IDENTIFIER, identifier, indices));
break;
//.........这里部分代码省略.........
示例4: ParseComments
private int ParseComments(string code, Position position, bool recurse)
{
List<Index> indices = new List<Index>();
if ((code.Length > position.CurrentIndex + 1) && (code[position.CurrentIndex] == '/'))
{
if (code[position.CurrentIndex + 1] == '/')
{
while ((code.Length > position.CurrentIndex) && (code[position.CurrentIndex] != '\n'))
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
position.MoveIndex();
}
position.MoveIndex();
}
else if (code[position.CurrentIndex + 1] == '*')
{
while (code.Length > position.CurrentIndex)
{
if (code.Length > position.CurrentIndex + 1 && code[position.CurrentIndex] == '*' && code[position.CurrentIndex + 1] == '/')
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
indices.Add(new Index(position.LineNumber, position.CharNumber + 1));
position.MoveIndex();
position.MoveIndex();
break;
}
if (code.Length > position.CurrentIndex && code[position.CurrentIndex] != '\n')
{
indices.Add(new Index(position.LineNumber, position.CharNumber));
}
position.MoveIndex();
}
}
}
EatWhitespace(code, position);
// add token only if comments were found
if (indices.Count > 0)
{
tokens.Add(new Token(TokenType.COMMENT, "", indices));
}
// check if next is another comment...
if (recurse)
{
int oldPosition = position.CurrentIndex;
if (ParseComments(code, position, false) != oldPosition)
return ParseComments(code, position, true);
}
return position.CurrentIndex;
}
示例5: EatWhitespace
private void EatWhitespace(string code, Position position)
{
// eat whitespace
while ((code.Length > position.CurrentIndex) && (Char.IsWhiteSpace(code[position.CurrentIndex])))
{
position.MoveIndex();
}
}