51 lines
1.0 KiB
Plaintext
51 lines
1.0 KiB
Plaintext
%name Parser
|
|
|
|
%token_prefix TOKEN_
|
|
|
|
%left OR.
|
|
%left AND.
|
|
%right NOT.
|
|
|
|
%include {
|
|
// include something
|
|
}
|
|
|
|
%code {
|
|
&&REPLACER{example/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{example/rules.y}&& |