|
@ -5,8 +5,6 @@ var rep = require("./representation.js"); |
|
|
var tools = require("./tools.js"); |
|
|
var tools = require("./tools.js"); |
|
|
var operators = Object.keys(rep.OPInfo); |
|
|
var operators = Object.keys(rep.OPInfo); |
|
|
|
|
|
|
|
|
hasOp = tools.hasOperator(operators); |
|
|
|
|
|
|
|
|
|
|
|
function isDigit(a) { |
|
|
function isDigit(a) { |
|
|
if (!a) |
|
|
if (!a) |
|
|
return false; |
|
|
return false; |
|
@ -84,13 +82,17 @@ function tokenizeIdent(tokstream) { |
|
|
n++; |
|
|
n++; |
|
|
} |
|
|
} |
|
|
identifier = identifier.join(''); |
|
|
identifier = identifier.join(''); |
|
|
var op = hasOp(identifier); |
|
|
/* var op = hasOp(identifier); |
|
|
if (op) { |
|
|
if (op) { |
|
|
|
|
|
if (identifier === op) |
|
|
|
|
|
return [[tools.len(op), ["identifier", op]]]; |
|
|
var splitted = identifier.split(op); |
|
|
var splitted = identifier.split(op); |
|
|
|
|
|
console.log(splitted); |
|
|
var newIdent = splitted[0]; |
|
|
var newIdent = splitted[0]; |
|
|
tokstream = splitted[1]+tokstream; |
|
|
tokstream = splitted[1]+tokstream; |
|
|
return [[n-(tools.len(op)), ["identifier", newIdent]], [tools.len(op), ["identifier", op]]]; |
|
|
return [[n-(tools.len(op)), ["identifier", newIdent]], [tools.len(op), ["identifier", op]]]; |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
return [[n, ["identifier", identifier]]]; |
|
|
return [[n, ["identifier", identifier]]]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -278,10 +280,10 @@ function tokenize(tokstream) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
var result = tokenizeIdent(tokstream); |
|
|
var result = tokenizeIdent(tokstream); |
|
|
var i = result[0]; |
|
|
result.map(function(x) { |
|
|
var ident = result[1]; |
|
|
tokens.push(x[1]); |
|
|
tokens.push(ident); |
|
|
tokstream = tokstream.substr(x[0]); |
|
|
tokstream = tokstream.substr(i); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return tokens; |
|
|
return tokens; |
|
@ -290,8 +292,10 @@ function tokenize(tokstream) { |
|
|
module.exports = {tokenize : tokenize}; |
|
|
module.exports = {tokenize : tokenize}; |
|
|
|
|
|
|
|
|
//var tokstream = fs.readFileSync("/dev/stdin").toString();
|
|
|
//var tokstream = fs.readFileSync("/dev/stdin").toString();
|
|
|
//console.log(isIdentifier(')'));
|
|
|
|
|
|
//console.log(tokenize(tokstream));
|
|
|
//console.log(tokenize(tokstream));
|
|
|
|
|
|
console.log(tools.buildTrie('', operators)[1][6]); |
|
|
|
|
|
//console.log(isIdentifier(')'));
|
|
|
//console.log(tools.maxBy(tools.len, operators.filter(function (x) { return "#".indexOf(x) != -1;})));
|
|
|
//console.log(tools.maxBy(tools.len, operators.filter(function (x) { return "#".indexOf(x) != -1;})));
|
|
|
console.log(tokenizeIdent("abc%%3")); |
|
|
//console.log(tokenizeIdent("abc%%3"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|