merged == and != into COMPARE

This commit is contained in:
satyr
2010-10-24 03:24:30 +09:00
parent fc332bcfbd
commit ebdcfb5227
5 changed files with 41 additions and 55 deletions

View File

@@ -575,10 +575,6 @@
return new Op('+', $1, $3); return new Op('+', $1, $3);
}), o('Expression - Expression', function() { }), o('Expression - Expression', function() {
return new Op('-', $1, $3); return new Op('-', $1, $3);
}), o('Expression == Expression', function() {
return new Op('==', $1, $3);
}), o('Expression != Expression', function() {
return new Op('!=', $1, $3);
}), o('Expression MATH Expression', function() { }), o('Expression MATH Expression', function() {
return new Op($2, $1, $3); return new Op($2, $1, $3);
}), o('Expression SHIFT Expression', function() { }), o('Expression SHIFT Expression', function() {
@@ -596,7 +592,7 @@
}) })
] ]
}; };
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", '==', '!=', 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']]; operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
tokens = []; tokens = [];
for (name in grammar) { for (name in grammar) {
alternatives = grammar[name]; alternatives = grammar[name];

View File

@@ -90,16 +90,9 @@
} }
if (!forcedIdentifier) { if (!forcedIdentifier) {
if (COFFEE_ALIASES.hasOwnProperty(id)) { if (COFFEE_ALIASES.hasOwnProperty(id)) {
tag = id = COFFEE_ALIASES[id]; id = COFFEE_ALIASES[id];
}
if (id === '!') {
tag = 'UNARY';
} else if (__indexOf.call(LOGIC, id) >= 0) {
tag = 'LOGIC';
} else if (__indexOf.call(BOOL, tag) >= 0) {
id = tag.toLowerCase();
tag = 'BOOL';
} }
tag = id === '!' ? 'UNARY' : id === '==' || id === '!=' ? 'COMPARE' : id === '&&' || id === '||' ? 'LOGIC' : id === 'true' || id === 'false' || id === 'null' ? 'BOOL' : tag;
} }
this.token(tag, id); this.token(tag, id);
if (colon) { if (colon) {
@@ -600,10 +593,10 @@
is: '==', is: '==',
isnt: '!=', isnt: '!=',
not: '!', not: '!',
yes: 'TRUE', yes: 'true',
no: 'FALSE', no: 'false',
on: 'TRUE', on: 'true',
off: 'FALSE' off: 'false'
}) { }) {
COFFEE_KEYWORDS.push(op); COFFEE_KEYWORDS.push(op);
} }
@@ -632,9 +625,9 @@
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/; NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=']; COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE']; UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
LOGIC = ['&', '|', '^', '&&', '||']; LOGIC = ['&&', '||', '&', '|', '^'];
SHIFT = ['<<', '>>', '>>>']; SHIFT = ['<<', '>>', '>>>'];
COMPARE = ['<=', '<', '>', '>=']; COMPARE = ['==', '!=', '<', '>', '<=', '>='];
MATH = ['*', '/', '%']; MATH = ['*', '/', '%'];
RELATION = ['IN', 'OF', 'INSTANCEOF']; RELATION = ['IN', 'OF', 'INSTANCEOF'];
BOOL = ['TRUE', 'FALSE', 'NULL']; BOOL = ['TRUE', 'FALSE', 'NULL'];

File diff suppressed because one or more lines are too long

View File

@@ -518,8 +518,6 @@ grammar =
o 'Expression + Expression', -> new Op '+' , $1, $3 o 'Expression + Expression', -> new Op '+' , $1, $3
o 'Expression - Expression', -> new Op '-' , $1, $3 o 'Expression - Expression', -> new Op '-' , $1, $3
o 'Expression == Expression', -> new Op '==', $1, $3
o 'Expression != Expression', -> new Op '!=', $1, $3
o 'Expression MATH Expression', -> new Op $2, $1, $3 o 'Expression MATH Expression', -> new Op $2, $1, $3
o 'Expression SHIFT Expression', -> new Op $2, $1, $3 o 'Expression SHIFT Expression', -> new Op $2, $1, $3
@@ -556,7 +554,7 @@ operators = [
["left", '+', '-'] ["left", '+', '-']
["left", 'SHIFT'] ["left", 'SHIFT']
["left", 'RELATION'] ["left", 'RELATION']
["left", '==', '!=', 'COMPARE'] ["left", 'COMPARE']
["left", 'LOGIC'] ["left", 'LOGIC']
["left", '.'] ["left", '.']
["nonassoc", 'INDENT', 'OUTDENT'] ["nonassoc", 'INDENT', 'OUTDENT']
@@ -586,7 +584,7 @@ for all name, alternatives of grammar
# precedence from low to high, and we have it high to low # precedence from low to high, and we have it high to low
# (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)). # (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
exports.parser = new Parser exports.parser = new Parser
tokens: tokens.join ' ' tokens : tokens.join ' '
bnf: grammar bnf : grammar
operators: operators.reverse() operators : operators.reverse()
startSymbol: 'Root' startSymbol : 'Root'

View File

@@ -114,14 +114,17 @@ exports.Lexer = class Lexer
else if id in RESERVED else if id in RESERVED
@identifierError id @identifierError id
unless forcedIdentifier unless forcedIdentifier
tag = id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
if id is '!' tag = if id is '!'
tag = 'UNARY' 'UNARY'
else if id in LOGIC else if id in ['==', '!=']
tag = 'LOGIC' 'COMPARE'
else if tag in BOOL else if id in ['&&', '||']
id = tag.toLowerCase() 'LOGIC'
tag = 'BOOL' else if id in ['true', 'false', 'null']
'BOOL'
else
tag
@token tag, id @token tag, id
@token ':', ':' if colon @token ':', ':' if colon
input.length input.length
@@ -523,10 +526,10 @@ COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
is : '==' is : '=='
isnt : '!=' isnt : '!='
not : '!' not : '!'
yes : 'TRUE' yes : 'true'
no : 'FALSE' no : 'false'
on : 'TRUE' on : 'true'
off : 'FALSE' off : 'false'
# The list of keywords that are reserved by JavaScript, but not used, or are # The list of keywords that are reserved by JavaScript, but not used, or are
# used by CoffeeScript internally. We throw an error when these are encountered, # used by CoffeeScript internally. We throw an error when these are encountered,
@@ -597,13 +600,13 @@ COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'] UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE']
# Logical tokens. # Logical tokens.
LOGIC = ['&', '|', '^', '&&', '||'] LOGIC = ['&&', '||', '&', '|', '^']
# Bit-shifting tokens. # Bit-shifting tokens.
SHIFT = ['<<', '>>', '>>>'] SHIFT = ['<<', '>>', '>>>']
# Comparison tokens. # Comparison tokens.
COMPARE = ['<=', '<', '>', '>='] COMPARE = ['==', '!=', '<', '>', '<=', '>=']
# Mathmatical tokens. # Mathmatical tokens.
MATH = ['*', '/', '%'] MATH = ['*', '/', '%']