added SAVE, WILDCARD

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6826]
This commit is contained in:
parrt 2010-04-30 14:21:00 -08:00
parent 7cf42fe4dd
commit 43278cf701
2 changed files with 13 additions and 3 deletions

View File

@ -46,6 +46,8 @@ public class Bytecode {
public static final short MATCH16 = 5; public static final short MATCH16 = 5;
public static final short RANGE8 = 6; public static final short RANGE8 = 6;
public static final short RANGE16 = 7; public static final short RANGE16 = 7;
public static final short WILDCARD = 8;
public static final short SAVE = 9;
/** Used for disassembly; describes instruction set */ /** Used for disassembly; describes instruction set */
public static Instruction[] instructions = new Instruction[] { public static Instruction[] instructions = new Instruction[] {
@ -56,7 +58,9 @@ public class Bytecode {
new Instruction("match8", OperandType.BYTE), new Instruction("match8", OperandType.BYTE),
new Instruction("match16", OperandType.CHAR), new Instruction("match16", OperandType.CHAR),
new Instruction("range8", OperandType.BYTE, OperandType.BYTE), new Instruction("range8", OperandType.BYTE, OperandType.BYTE),
new Instruction("range16", OperandType.CHAR, OperandType.CHAR) new Instruction("range16", OperandType.CHAR, OperandType.CHAR),
new Instruction("wildcard"),
new Instruction("save", OperandType.SHORT),
}; };
public static String disassemble(byte[] code, int start) { public static String disassemble(byte[] code, int start) {

View File

@ -185,7 +185,7 @@ workLoop:
public int execThompson(CharStream input, int ip) { public int execThompson(CharStream input, int ip) {
int c = input.LA(1); int c = input.LA(1);
if ( c==Token.EOF ) return Token.EOF; if ( c==Token.EOF ) return Token.EOF;
List<Integer> closure = new ArrayList<Integer>(); List<Integer> closure = new ArrayList<Integer>();
List<Integer> reach = new ArrayList<Integer>(); List<Integer> reach = new ArrayList<Integer>();
int prevAcceptAddr = Integer.MAX_VALUE; int prevAcceptAddr = Integer.MAX_VALUE;
@ -265,7 +265,7 @@ processOneChar:
void addToClosure(List<Integer> closure, int ip) { void addToClosure(List<Integer> closure, int ip) {
//System.out.println("add to closure "+ip+" "+closure); //System.out.println("add to closure "+ip+" "+closure);
if ( closure.contains(ip) ) return; if ( closure.contains(ip) ) return; // TODO: VERY INEFFICIENT! use int[num-states] as set test
closure.add(ip); closure.add(ip);
short opcode = code[ip]; short opcode = code[ip];
ip++; // move to next instruction or first byte of operand ip++; // move to next instruction or first byte of operand
@ -273,6 +273,12 @@ processOneChar:
case Bytecode.JMP : case Bytecode.JMP :
addToClosure(closure, getShort(code, ip)); addToClosure(closure, getShort(code, ip));
break; break;
case Bytecode.SAVE :
int labelIndex = getShort(code, ip);
ip += 2;
addToClosure(closure, ip); // do closure pass SAVE
// TODO: impl
break;
case Bytecode.SPLIT : case Bytecode.SPLIT :
int nopnds = getShort(code, ip); int nopnds = getShort(code, ip);
ip += 2; ip += 2;