Skip to content

Commit

Permalink
ok, i think this rewrite concept sucks...not sure where to go with it
Browse files Browse the repository at this point in the history
  • Loading branch information
Cullen King committed Jan 9, 2009
1 parent 5e4658c commit bcaa8e9
Showing 1 changed file with 24 additions and 49 deletions.
73 changes: 24 additions & 49 deletions Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ private void skipWhiteSpace() throws ParseException {
throwBack(c); //broke outta loop, toss back last char.
}

private void skipComment() throws ParseException {
int c = currentChar();
if((char)c == '{') {
while((char)c != '}') {
if(c == -1) //we have an unterminated comment
throw new ParseException(1);
c = currentChar(); //skip comments
}
skipWhiteSpace();
} else {
throwBack(c);
}
}

private int currentChar() throws ParseException {
int cc;

Expand All @@ -65,67 +79,28 @@ public void nextLex() throws ParseException {
int c;
token = "";
skipWhiteSpace(); //get rid of any preceding whitespaces
skipComment(); //get rid of any comments maybe lying around

c = currentChar();

if((char)c == '{') {
while((char)c != '}') {
if(c == -1) //we have an unterminated comment
throw new ParseException(1);
c = currentChar(); //skip comments
}
c = currentChar();
skipWhiteSpace();
}

if(Character.isLetter((char) c)) {
while(Character.isLetterOrDigit((char) c) && !Character.isWhitespace((char)c)) {
token = token + (char)c;
c = currentChar();
}

if(!Character.isWhitespace((char)c)) {
throwBack(c);
}
} else if(Character.isDigit((char)c)) {
token = token += (char)c;
c = currentChar();
int num_points = 0;
while(Character.isDigit((char)c) || (char)c == '.') {
if((char)c == '.')
num_points += 1;
token += (char)c;
c = currentChar();
}
if(num_points == 0)
tokenType = intToken;
else if(num_points == 1)
tokenType = realToken;
else
throw new ParseException(46);
throwBack(c);
} else if((char)c == '"') { //TODO: check no comments within comments
if((char)c == '"') { //TODO: check no comments within comments
c = currentChar();
while((char)c != '"') {
if(c == -1) //unterminated string
throw new ParseException(2);
token = token + (char)c;
c = currentChar();
}
tokenType = stringToken;
} else if((char)c == '<') {
token = token + (char)c;
c = currentChar(); //eat up the close quote
} else if(c != -1) {
token += (char)c;
c = currentChar();
if((char)c == '<' || (char)c == '=') {
while(Pattern.matches("[^*<>!=\\&\\^%/+-.\"{}\\s]", Character.toString((char)c))) {
token = token + (char)c;
} else {
throwBack(c);
c = currentChar();
}
tokenType = 6;
} else {
token += (char)c;
tokenType = 6;
}

throwBack(c);

if(c == -1) { //end of input, toss to 7 so we can exit
tokenType = 7;
} else if(Pattern.matches(IDENT_REGEX, token)) {
Expand Down

0 comments on commit bcaa8e9

Please sign in to comment.