LemonJS/example/parser.y

51 lines
1009 B
Plaintext

%name Parser
%token_prefix TOKEN_
%left OR.
%left AND.
%right NOT.
%include {
// include something
}
%code {
&&REPLACER{test_code_environment.js}&&
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");
}
&&REPLACER{rules.y}&&