LemonJS/example/parser.y

51 lines
1009 B
Plaintext
Raw Normal View History

2019-01-29 11:04:41 +00:00
%name Parser
%token_prefix TOKEN_
%left OR.
%left AND.
%right NOT.
%include {
// include something
}
%code {
2019-01-30 11:50:02 +00:00
&&REPLACER{test_code_environment.js}&&
2019-01-29 11:04:41 +00:00
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()) {
if(_result.error) {
return { success: false }
}
if (token.error === 0) {
console.log("PARSE", token.lexeme);
parser.parse(parser["TOKEN_" + token.lexeme], token);
lexemes.push(token);
}
}
parser.parse();
return {
success: true,
tree: _result.root_node,
lexemes: lexemes
};
};
}
%syntax_error {
_result.error = "true";
console.log("Syntax error");
}
2019-01-30 11:50:02 +00:00
&&REPLACER{rules.y}&&