2019-01-29 11:25:40 +00:00
|
|
|
%name Parser
|
|
|
|
|
|
|
|
%token_prefix TOKEN_
|
|
|
|
|
|
|
|
%left OR.
|
|
|
|
%left AND.
|
|
|
|
%right NOT.
|
|
|
|
|
|
|
|
%include {
|
|
|
|
// include something
|
|
|
|
}
|
|
|
|
|
|
|
|
%code {
|
|
|
|
var _result = {
|
|
|
|
error: false
|
|
|
|
};
|
|
|
|
var LemonJS = function(_input) {
|
|
|
|
_result = Object.create(null);
|
|
|
|
var parser = new Parser();
|
|
|
|
var lexer = new Lexer(_input);
|
|
|
|
var token;
|
|
|
|
var lexemes = [];
|
|
|
|
while (token = lexer.next()) {
|
2019-01-30 10:13:05 +00:00
|
|
|
switch(token.error){
|
|
|
|
case 0:
|
|
|
|
console.log("PARSE", token.lexeme);
|
|
|
|
parser.parse(parser["TOKEN_" + token.lexeme], token);
|
|
|
|
lexemes.push(token);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: "Found unknown symbol on position",
|
|
|
|
error: 1,
|
|
|
|
token: token
|
|
|
|
};
|
|
|
|
case 2:
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: "Not found close quote",
|
|
|
|
error: 2,
|
|
|
|
token: token
|
|
|
|
};
|
|
|
|
case 3:
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: "Unexpected symbol in oid structure",
|
|
|
|
error: 3,
|
|
|
|
token: token
|
|
|
|
};
|
|
|
|
case 4:
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: "Not found close bracket for Oid",
|
|
|
|
error: 3,
|
|
|
|
token: token
|
|
|
|
};
|
2019-01-29 11:25:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 10:13:05 +00:00
|
|
|
if(_result.error) {
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: "Syntax error",
|
|
|
|
error: 0
|
|
|
|
}
|
2019-01-29 11:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
parser.parse();
|
2019-01-30 10:13:05 +00:00
|
|
|
if (_result.root_node !== undefined) {
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
tree: _result.root_node,
|
|
|
|
lexemes: lexemes
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return { success: false }
|
|
|
|
}
|
2019-01-29 11:25:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
%syntax_error {
|
|
|
|
_result.error = "true";
|
|
|
|
console.log("Syntax error");
|
|
|
|
}
|
|
|
|
|
|
|
|
&&REPLACER{output/rules.y}&&
|