简体   繁体   中英

javascript grammar in antlr4

I have used the following link for JavaScript grammar.

https://github.com/ftomassetti/antlr-web-example

However, when I use JavaScript's grammar(JavaScriptLexer.g4 and JavaScriptParser.g4) rather than grammar(todo.g4), it shows a error when defined.

ATNDeserializer.js:171 Uncaught AADB8D7E-AEEF-4415-AD2B-8204D6CF042E

在此处输入图像描述

What is this error for?

What do I do to use antlr and JavaScript grammar to create an intermediate code?

My grammar files:

  • JavaScriptLexer.g4
  • JavaScriptParser.g4

https://github.com/antlr/grammars-v4/tree/master/javascript/javascript

This is my code: index.html

<!DOCTYPE html>
<html>
<head>
    <title>ANTLR on the Web</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script type="text/javascript" src="lib/require.js"></script> 
</head>
<body>
<div id="inputs">
<textarea id="code">
* play with antlr4
* write a tutorial
</textarea>
<br/>
<button id="parse">Parse</button>
</div>
<script type="text/javascript">

var antlr4 = require('antlr4/index');
var JavaScriptParser = require('./generated-parser/JavaScriptParser');
console.log("start");
document.getElementById("parse").addEventListener("click", function(){
    // var JavaScriptLexer = require('generated-parser/JavaScriptLexer');
    // var input = document.getElementById("code").value;
    // var chars = new antlr4.InputStream(input);
    // var lexer = new JavaScriptLexer.JavaScriptLexer(chars);
    // var tokens  = new antlr4.CommonTokenStream(lexer);
    // var parser = new JavaScriptParser.JavaScriptParser(tokens);
    // parser.buildParseTrees = true;
    // var tree = parser.program();
    // console.log("Parsed: "+ tree);
    // updateTree(tree, parser.ruleNames);
});
</script>
<div id="tree">
</div> 
</body>
</html>

@kaby76 essentially described the problem. You are using an old runtime. The error shows the UUID for the "lexer action" feature . The ANTLR4 tool you used to generate your parser is newer than the runtime. Make sure the runtime matches the tool version (or is newer).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM