|
|
@@ -33,12 +33,12 @@ |
|
|
|
#include <cstdlib> |
|
|
|
#include <fstream> |
|
|
|
#include <iostream> |
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <string> |
|
|
|
#include <vector> |
|
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
|
#include "snf_engine.hpp" |
|
|
|
|
|
|
|
using namespace std; |
|
|
|
namespace cd = codedweller; |
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
// BEGIN IMPLEMENTATIONS ////////////////////////////////////////////////////////////////// |
|
|
@@ -65,11 +65,11 @@ void TokenMatrix::Load(const char* FileName) { |
|
|
|
} |
|
|
|
|
|
|
|
// TokenMatrix::Load(stream) |
|
|
|
|
|
|
|
const AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)");
|
|
|
|
|
|
|
|
const cd::AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)"); |
|
|
|
|
|
|
|
void TokenMatrix::Load(ifstream& F) { // Initializes the token matrix from a file. |
|
|
|
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions.
|
|
|
|
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions. |
|
|
|
|
|
|
|
MatrixSize = 0; // Clear out the old Matrix Size and array. |
|
|
|
if(Matrix) delete Matrix; // that is, if there is an array. |
|
|
@@ -218,7 +218,7 @@ void TokenMatrix::FlipEndian() { |
|
|
|
// Evaluator Implementations ////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
// 20030216 _M Optimization conversions |
|
|
|
|
|
|
|
|
|
|
|
// 20140119 _M Deprecated by jump table in evaluator |
|
|
|
// inline int Evaluator::i_lower() { return myEvaluationMatrix->i_lower; } |
|
|
|
// inline bool Evaluator::i_isDigit() { return myEvaluationMatrix->i_isDigit; } |
|
|
@@ -228,17 +228,17 @@ void TokenMatrix::FlipEndian() { |
|
|
|
|
|
|
|
// Evaluator::Evaluator(position,evalmatrix) Constructor |
|
|
|
|
|
|
|
Evaluator::Evaluator(unsigned int s, EvaluationMatrix* m)
|
|
|
|
: myEvaluationMatrix(m),
|
|
|
|
JumpPoint(0),
|
|
|
|
Condition(DOING_OK),
|
|
|
|
NextEvaluator(NULL),
|
|
|
|
StreamStartPosition(s),
|
|
|
|
CurrentPosition(0),
|
|
|
|
Evaluator::Evaluator(unsigned int s, EvaluationMatrix* m) |
|
|
|
: myEvaluationMatrix(m), |
|
|
|
JumpPoint(0), |
|
|
|
Condition(DOING_OK), |
|
|
|
NextEvaluator(NULL), |
|
|
|
StreamStartPosition(s), |
|
|
|
CurrentPosition(0), |
|
|
|
WildRunLength(0) { // Constructor... |
|
|
|
|
|
|
|
Matrix = myEvaluationMatrix->getTokens(); // Capture the token matrix I walk in. |
|
|
|
MatrixSize = myEvaluationMatrix->getMatrixSize(); // And get it's size.
|
|
|
|
MatrixSize = myEvaluationMatrix->getMatrixSize(); // And get it's size. |
|
|
|
PositionLimit = MatrixSize - 256; |
|
|
|
} |
|
|
|
|
|
|
@@ -252,13 +252,13 @@ Evaluator::Evaluator(unsigned int s, EvaluationMatrix* m) |
|
|
|
int Evaluator::xAnyInline() { return (JumpPoint + WILD_INLINE); } // Match Any byte but new line. |
|
|
|
int Evaluator::xAnything() { return (JumpPoint + WILD_ANYTHING); } // Match Any character at all. |
|
|
|
int Evaluator::xRunGateway() { return (JumpPoint + RUN_GATEWAY); } // Match the run-loop gateway. |
|
|
|
|
|
|
|
// void Evaluator::doFollowOrMakeBuddy()
|
|
|
|
|
|
|
|
void Evaluator::doFollowOrMakeBuddy(int xKey) {
|
|
|
|
|
|
|
|
bool shouldFollow = (FALLEN_OFF == Condition); // What should we do?
|
|
|
|
|
|
|
|
|
|
|
|
// void Evaluator::doFollowOrMakeBuddy() |
|
|
|
|
|
|
|
void Evaluator::doFollowOrMakeBuddy(int xKey) { |
|
|
|
|
|
|
|
bool shouldFollow = (FALLEN_OFF == Condition); // What should we do? |
|
|
|
|
|
|
|
if(shouldFollow) { // This is how we follow |
|
|
|
Condition = DOING_OK; |
|
|
|
CurrentPosition = xKey + |
|
|
@@ -269,204 +269,204 @@ void Evaluator::doFollowOrMakeBuddy(int xKey) { |
|
|
|
myEvaluationMatrix-> |
|
|
|
AddEvaluator(StreamStartPosition,Matrix[xKey].Vector+xKey); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingPrecisePath(unsigned short int i) {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingPrecisePath(unsigned short int i) { |
|
|
|
int xPrecise = JumpPoint + i; // Match Precise Character |
|
|
|
if(Matrix[xPrecise].Character() == i) { // If we've matched our path
|
|
|
|
if(Matrix[xPrecise].Character() == i) { // If we've matched our path |
|
|
|
doFollowOrMakeBuddy(xPrecise); |
|
|
|
}
|
|
|
|
} |
|
|
|
if(DOING_OK == Condition) WildRunLength = 0; |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingNoCasePath(unsigned short int i) {
|
|
|
|
i = tolower(i);
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingNoCasePath(unsigned short int i) { |
|
|
|
i = tolower(i); |
|
|
|
int xNoCase = JumpPoint + i; // Match caps to lower (case insensitive) |
|
|
|
if(Matrix[xNoCase].Character()==i){ |
|
|
|
doFollowOrMakeBuddy(xNoCase); |
|
|
|
} |
|
|
|
if(DOING_OK == Condition) WildRunLength = 0; |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildAlphaPath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildAlphaPath() { |
|
|
|
if(Matrix[xLetter()].Character()==WILD_LETTER){ |
|
|
|
doFollowOrMakeBuddy(xLetter()); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildDigitPath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildDigitPath() { |
|
|
|
if(Matrix[xDigit()].Character()==WILD_DIGIT){ |
|
|
|
doFollowOrMakeBuddy(xDigit()); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildNonWhitePath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildNonWhitePath() { |
|
|
|
if(Matrix[xNonWhite()].Character()==WILD_NONWHITE){ |
|
|
|
doFollowOrMakeBuddy(xNonWhite()); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildWhitePath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildWhitePath() { |
|
|
|
if(Matrix[xWhiteSpace()].Character()==WILD_WHITESPACE){ |
|
|
|
doFollowOrMakeBuddy(xWhiteSpace()); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildInlinePath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildInlinePath() { |
|
|
|
if(Matrix[xAnyInline()].Character()==WILD_INLINE){ |
|
|
|
doFollowOrMakeBuddy(xAnyInline()); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildAnythingPath() {
|
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::tryFollowingWildAnythingPath() { |
|
|
|
if(Matrix[xAnything()].Character()==WILD_ANYTHING){ |
|
|
|
doFollowOrMakeBuddy(xAnything()); |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Evaluator::doFollowerJumpTable(unsigned short int i) {
|
|
|
|
// tryFollowingPrecisePath(i);
|
|
|
|
// tryFollowingUppercasePath(); 0x41 - 0x5A
|
|
|
|
// tryFollowingWildAlphaPath(); 0x61 - 0x7A
|
|
|
|
// tryFollowingWildDigitPath(); 0x30 - 0x39
|
|
|
|
// tryFollowingWildWhitePath(); 0x09 - 0x0D, 0x20
|
|
|
|
// tryFollowingWildNonWhitePath(); > 0x20
|
|
|
|
// tryFollowingWildInlinePath(); Not 0x0A, or 0x0D
|
|
|
|
|
|
|
|
switch(i) {
|
|
|
|
|
|
|
|
// These nnly match WildAnything because they conflict with special check values...
|
|
|
|
// NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, TAB, LF, VT, FF, CR, SO, SI
|
|
|
|
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
|
|
|
|
case 0x08: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tab
|
|
|
|
case 0x09: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LF, VT, FF, CR, SO, SI
|
|
|
|
case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F:
|
|
|
|
|
|
|
|
// DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US
|
|
|
|
case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
|
|
|
|
case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildWhitePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the final fronteer
|
|
|
|
case 0x20: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ! " # $ % & ' ( ) * + , - . /
|
|
|
|
case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
|
|
|
|
case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: case 0x2F: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0 - 9
|
|
|
|
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
|
|
|
|
case 0x38: case 0x39: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildDigitPath();
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// : ; < = > ? @
|
|
|
|
case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F:
|
|
|
|
case 0x40: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A - Z
|
|
|
|
case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:
|
|
|
|
case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4E: case 0x4F:
|
|
|
|
case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
|
|
|
|
case 0x58: case 0x59: case 0x5A: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingNoCasePath(i);
|
|
|
|
tryFollowingWildAlphaPath();
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [ \ ] ^ _ `
|
|
|
|
case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F:
|
|
|
|
case 0x60: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// a - z
|
|
|
|
case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67:
|
|
|
|
case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F:
|
|
|
|
case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77:
|
|
|
|
case 0x78: case 0x79: case 0x7A: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildAlphaPath();
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// { | } ~
|
|
|
|
case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// high ascii
|
|
|
|
case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
|
|
|
|
case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F:
|
|
|
|
case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
|
|
|
|
case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F:
|
|
|
|
case 0xA0: case 0xA1: case 0xA2: case 0xA3: case 0xA4: case 0xA5: case 0xA6: case 0xA7:
|
|
|
|
case 0xA8: case 0xA9: case 0xAA: case 0xAB: case 0xAC: case 0xAD: case 0xAE: case 0xAF:
|
|
|
|
case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7:
|
|
|
|
case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF:
|
|
|
|
case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7:
|
|
|
|
case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF:
|
|
|
|
case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7:
|
|
|
|
case 0xD8: case 0xD9: case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: case 0xDF:
|
|
|
|
case 0xE0: case 0xE1: case 0xE2: case 0xE3: case 0xE4: case 0xE5: case 0xE6: case 0xE7:
|
|
|
|
case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEE: case 0xEF:
|
|
|
|
case 0xF0: case 0xF1: case 0xF2: case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7:
|
|
|
|
case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: case 0xFD: case 0xFE: case 0xFF: {
|
|
|
|
tryFollowingPrecisePath(i);
|
|
|
|
tryFollowingWildNonWhitePath();
|
|
|
|
tryFollowingWildInlinePath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tryFollowingWildAnythingPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Evaluator::doFollowerJumpTable(unsigned short int i) { |
|
|
|
// tryFollowingPrecisePath(i); |
|
|
|
// tryFollowingUppercasePath(); 0x41 - 0x5A |
|
|
|
// tryFollowingWildAlphaPath(); 0x61 - 0x7A |
|
|
|
// tryFollowingWildDigitPath(); 0x30 - 0x39 |
|
|
|
// tryFollowingWildWhitePath(); 0x09 - 0x0D, 0x20 |
|
|
|
// tryFollowingWildNonWhitePath(); > 0x20 |
|
|
|
// tryFollowingWildInlinePath(); Not 0x0A, or 0x0D |
|
|
|
|
|
|
|
switch(i) { |
|
|
|
|
|
|
|
// These nnly match WildAnything because they conflict with special check values... |
|
|
|
// NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, TAB, LF, VT, FF, CR, SO, SI |
|
|
|
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: |
|
|
|
case 0x08: { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// tab |
|
|
|
case 0x09: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// LF, VT, FF, CR, SO, SI |
|
|
|
case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F: |
|
|
|
|
|
|
|
// DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US |
|
|
|
case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
|
|
|
case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildWhitePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// the final fronteer |
|
|
|
case 0x20: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// ! " # $ % & ' ( ) * + , - . / |
|
|
|
case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
|
|
|
case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: case 0x2F: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// 0 - 9 |
|
|
|
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: |
|
|
|
case 0x38: case 0x39: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildDigitPath(); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// : ; < = > ? @ |
|
|
|
case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F: |
|
|
|
case 0x40: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// A - Z |
|
|
|
case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: |
|
|
|
case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4E: case 0x4F: |
|
|
|
case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: |
|
|
|
case 0x58: case 0x59: case 0x5A: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingNoCasePath(i); |
|
|
|
tryFollowingWildAlphaPath(); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// [ \ ] ^ _ ` |
|
|
|
case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F: |
|
|
|
case 0x60: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// a - z |
|
|
|
case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: |
|
|
|
case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F: |
|
|
|
case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: |
|
|
|
case 0x78: case 0x79: case 0x7A: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildAlphaPath(); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// { | } ~ |
|
|
|
case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
} |
|
|
|
|
|
|
|
// high ascii |
|
|
|
case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: |
|
|
|
case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F: |
|
|
|
case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: |
|
|
|
case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F: |
|
|
|
case 0xA0: case 0xA1: case 0xA2: case 0xA3: case 0xA4: case 0xA5: case 0xA6: case 0xA7: |
|
|
|
case 0xA8: case 0xA9: case 0xAA: case 0xAB: case 0xAC: case 0xAD: case 0xAE: case 0xAF: |
|
|
|
case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7: |
|
|
|
case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF: |
|
|
|
case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7: |
|
|
|
case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: |
|
|
|
case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7: |
|
|
|
case 0xD8: case 0xD9: case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: case 0xDF: |
|
|
|
case 0xE0: case 0xE1: case 0xE2: case 0xE3: case 0xE4: case 0xE5: case 0xE6: case 0xE7: |
|
|
|
case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEE: case 0xEF: |
|
|
|
case 0xF0: case 0xF1: case 0xF2: case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7: |
|
|
|
case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: case 0xFD: case 0xFE: case 0xFF: { |
|
|
|
tryFollowingPrecisePath(i); |
|
|
|
tryFollowingWildNonWhitePath(); |
|
|
|
tryFollowingWildInlinePath(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tryFollowingWildAnythingPath(); |
|
|
|
} |
|
|
|
|
|
|
|
// Evaluator::EvaluateThis() |
|
|
|
|
|
|
|
|
|
|
|
Evaluator::States Evaluator::EvaluateThis(unsigned short int i) { // Follow the this byte. |
|
|
|
|
|
|
|
// First upgrade will be to DOING_OK, after that we launch buddies. |
|
|
@@ -481,9 +481,9 @@ Evaluator::States Evaluator::EvaluateThis(unsigned short int i) { |
|
|
|
// explored. New evaluators are always added at the TOP of the list so we are always |
|
|
|
// guaranteed not to overdrive an evaluator and end up in a recursive race condition. |
|
|
|
|
|
|
|
// 20140121_M The previous optimization with binary flags has been replaced with
|
|
|
|
// a jump table implementation. Now, each byte only excites behaviors that are
|
|
|
|
// possible for the current byte so only those paths will be tested.
|
|
|
|
// 20140121_M The previous optimization with binary flags has been replaced with |
|
|
|
// a jump table implementation. Now, each byte only excites behaviors that are |
|
|
|
// possible for the current byte so only those paths will be tested. |
|
|
|
|
|
|
|
if(CurrentPosition >= PositionLimit) return Condition = OUT_OF_RANGE; |
|
|
|
|
|
|
@@ -503,14 +503,14 @@ Evaluator::States Evaluator::EvaluateThis(unsigned short int i) { |
|
|
|
// Evaluation order, most-to-least specific with what is possible for that byte. |
|
|
|
|
|
|
|
JumpPoint = CurrentPosition; |
|
|
|
doFollowerJumpTable(i); // Excite followers based on this byte.
|
|
|
|
|
|
|
|
{ // Precise matches reset the wild run counter.
|
|
|
|
doFollowerJumpTable(i); // Excite followers based on this byte. |
|
|
|
|
|
|
|
{ // Precise matches reset the wild run counter. |
|
|
|
++WildRunLength; // Count up the run length. |
|
|
|
if(WildRunLength >= MaxWildRunLength) // If we exceed the max then |
|
|
|
return Condition = FALLEN_OFF; // we've fallen off the path |
|
|
|
} // and we do it immediately.
|
|
|
|
|
|
|
|
} // and we do it immediately. |
|
|
|
|
|
|
|
// 20021112 _M |
|
|
|
// Beginning with version 2 of Message Sniffer we've implemented a new construct |
|
|
|
// for run-loops that prevents any interference between rules where run-loops might |
|
|
@@ -674,31 +674,31 @@ void EvaluationMatrix::DropEvaluator() { // Drops the current evaluator from the |
|
|
|
--CountOfEvaluators; // Reduce our evaluator count. |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Evaluator* findEvaluatorListTail(Evaluator* head) {
|
|
|
|
Evaluator* next = head;
|
|
|
|
while(NULL != (next->NextEvaluator)) next = next->NextEvaluator;
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EvaluationMatrix::dropAllEvaluators() {
|
|
|
|
bool haveActiveEvaluators = (NULL != EvaluatorList);
|
|
|
|
if(haveActiveEvaluators) {
|
|
|
|
Evaluator* tail = findEvaluatorListTail(EvaluatorList);
|
|
|
|
tail->NextEvaluator = EvaluatorCache;
|
|
|
|
EvaluatorCache = EvaluatorList;
|
|
|
|
}
|
|
|
|
PreviousEvaluator = NULL;
|
|
|
|
CurrentEvaluator = NULL;
|
|
|
|
EvaluatorList = NULL;
|
|
|
|
CountOfEvaluators = 0;
|
|
|
|
|
|
|
|
Evaluator* findEvaluatorListTail(Evaluator* head) { |
|
|
|
Evaluator* next = head; |
|
|
|
while(NULL != (next->NextEvaluator)) next = next->NextEvaluator; |
|
|
|
return next; |
|
|
|
} |
|
|
|
|
|
|
|
void EvaluationMatrix::restartEngineAt(int newCharacterCount) {
|
|
|
|
dropAllEvaluators();
|
|
|
|
CountOfCharacters = newCharacterCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EvaluationMatrix::dropAllEvaluators() { |
|
|
|
bool haveActiveEvaluators = (NULL != EvaluatorList); |
|
|
|
if(haveActiveEvaluators) { |
|
|
|
Evaluator* tail = findEvaluatorListTail(EvaluatorList); |
|
|
|
tail->NextEvaluator = EvaluatorCache; |
|
|
|
EvaluatorCache = EvaluatorList; |
|
|
|
} |
|
|
|
PreviousEvaluator = NULL; |
|
|
|
CurrentEvaluator = NULL; |
|
|
|
EvaluatorList = NULL; |
|
|
|
CountOfEvaluators = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void EvaluationMatrix::restartEngineAt(int newCharacterCount) { |
|
|
|
dropAllEvaluators(); |
|
|
|
CountOfCharacters = newCharacterCount; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// EvaluationMatrix::EvaluateThis() |
|
|
|
// |
|
|
@@ -728,7 +728,7 @@ int EvaluationMatrix::EvaluateThis(unsigned short int i) { |
|
|
|
// Next do some basic conversions and evaluations so they don't need to be done |
|
|
|
// again within the evaluators. From now on the evaluators will look here for basic |
|
|
|
// conversions and boolean check values rather than performing the checks themselves. |
|
|
|
|
|
|
|
|
|
|
|
// 20140119 _M deprecated by jump table in evaluator |
|
|
|
// i_lower = tolower(i); // Convert i to lower case. |
|
|
|
// i_isDigit = isdigit(i); // Check for a digit. |
|
|
@@ -799,9 +799,9 @@ int EvaluationMatrix::EvaluateThis(unsigned short int i) { |
|
|
|
|
|
|
|
return PassResult; // When we're finished, return the last known result. |
|
|
|
} |
|
|
|
|
|
|
|
void EvaluationMatrix::evaluateSegment(vector<unsigned char>& data, unsigned int start, unsigned int finish) {
|
|
|
|
restartEngineAt(start);
|
|
|
|
finish = (finish < data.size()) ? finish : data.size();
|
|
|
|
for(unsigned int a = start; a < finish; a++) EvaluateThis(data[a]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EvaluationMatrix::evaluateSegment(vector<unsigned char>& data, unsigned int start, unsigned int finish) { |
|
|
|
restartEngineAt(start); |
|
|
|
finish = (finish < data.size()) ? finish : data.size(); |
|
|
|
for(unsigned int a = start; a < finish; a++) EvaluateThis(data[a]); |
|
|
|
} |