56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using System;
|
|
namespace lexer.buffer
|
|
{
|
|
public class DefinitionReader
|
|
{
|
|
public const int OP_INTERVAL = 0x00010000;
|
|
public const int OP_EOB = 0x10000000;
|
|
|
|
char[] definition;
|
|
int position;
|
|
|
|
int currentChar = -1;
|
|
|
|
public DefinitionReader(char[] definition)
|
|
{
|
|
this.definition = definition;
|
|
this.position = 0;
|
|
MoveNext();
|
|
}
|
|
|
|
public int Current {
|
|
get { return this.currentChar; }
|
|
}
|
|
|
|
public int MoveNext() {
|
|
if (this.position >= this.definition.Length){
|
|
currentChar = OP_EOB;
|
|
} else {
|
|
currentChar = this.definition[this.position++];
|
|
if (currentChar == '\\')
|
|
{
|
|
currentChar = this.definition[this.position++];
|
|
if ((currentChar == '0') && (this.definition[this.position] == 'x')){
|
|
char[] hexvalue = new char[4];
|
|
this.position++;
|
|
for (int n = 0; n < 4;n++){
|
|
hexvalue[n] = this.definition[this.position++];
|
|
}
|
|
currentChar = (char)int.Parse(new String(hexvalue), System.Globalization.NumberStyles.HexNumber);
|
|
}
|
|
} else if (currentChar == '.'){
|
|
if ((this.position < this.definition.Length) && (this.definition[this.position] == '.'))
|
|
{
|
|
this.position++;
|
|
currentChar = OP_INTERVAL;
|
|
}
|
|
}
|
|
}
|
|
|
|
return currentChar;
|
|
}
|
|
|
|
|
|
}
|
|
}
|