Partial Parser



NOTE: This version implements commands which take more than one number as input and it allows you to enter more than one command at a time. The new commands include PC (pencolor) and SZ (setxy). The ability to take in several commands in a single line makes this version ALMOST useable.

The most difficult part of parsing in this version of the applet is separating commands and numbers. The basic functions responsible for this work are as follows:

public char getNextChar(){ char out = command.charAt(cnt); cnt++; return out; } public String getCommand(){ String cmd = ""; char ch = ' '; do{ ch = getNextChar(); if(ch != ' ') cmd += ch; }while(ch != ' ' && cnt < command.length() ); return cmd; } public int getNumber(){ String number = ""; boolean negFlag=false; char ch = ' '; do{ ch = getNextChar(); if(ch == '-') negFlag=true; if(Character.isDigit(ch)) number+=ch; }while( ch != ' ' && cnt < command.length() ); int n=0; try{ n = Integer.parseInt(number); }catch(NumberFormatException nfe) { } if(negFlag) n*=-1; return n; }