antlr4

Webpack Error - configuration.node has an unknown property 'fs'

白昼怎懂夜的黑 提交于 2021-02-07 11:51:46
问题 I have encountered an error when using the latest version of Webpack (5.1.0). It looks like the configuration is throwing an error because the validation schema is too restrictive. Here is my webpack configuration file in a gist, and the error message I am seeing. Webpack.config.js https://gist.github.com/adarshbhat/3ec5950b66b78102da0cf46e51a3d633 Error [webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema. -

ANTLR4 for Java. How to display errors in lexical analysis

青春壹個敷衍的年華 提交于 2021-02-05 09:45:47
问题 How can you display a list of errors (if any) during lexical analysis. I tried the following method, but my output is [org.antlr.v4.runtime.ConsoleErrorListener@1026c84c]. The code I wrote: private static String errorsOutput(String code) { Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(code)); CommonTokenStream tokens = new CommonTokenStream(lexer); Java8Parser parser = new Java8Parser(tokens); return ""+lexer.getErrorListeners(); } Main class: String code = "public class Main {public

ANTLR4 for Java. How to display errors in lexical analysis

房东的猫 提交于 2021-02-05 09:41:40
问题 How can you display a list of errors (if any) during lexical analysis. I tried the following method, but my output is [org.antlr.v4.runtime.ConsoleErrorListener@1026c84c]. The code I wrote: private static String errorsOutput(String code) { Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(code)); CommonTokenStream tokens = new CommonTokenStream(lexer); Java8Parser parser = new Java8Parser(tokens); return ""+lexer.getErrorListeners(); } Main class: String code = "public class Main {public

ANTLR island grammars and a non-greedy rule that consumes too much

懵懂的女人 提交于 2021-01-29 05:20:30
问题 I'm having a problem with an island grammar and a non-greedy rule used to consume "everything except what I want". Desired outcome: My input file is a C header file, containing function declarations along with typedefs, structs, comments, and preprocessor definitions. My desired output is parsing and subsequent transformation of function declarations ONLY. I would like to ignore everything else. Setup and what I've tried: The header file I'm attempting to lex and parse is very uniform and

Can left recursion be eliminated in all cases in ANTLR?

女生的网名这么多〃 提交于 2021-01-28 22:07:14
问题 say I have the following Grammar #1 expr: expr AND expr | expr OR expr | primary ; and is turned into this. Grammar #2 expr: andExpr | primary ; andExpr: orExpr AND orExpr; orExpr: ... OR ...; but I still don't see how this would solve the problem? In Grammar #1 I can express true and false and true and true or false true or false and true I can keep chaining like this with Grammar #1. But I am not seeing how to achieve this using grammar #2? 回答1: You could write it like this: grammar Test;

antlr4 - parsing function invocations

╄→гoц情女王★ 提交于 2021-01-28 11:45:33
问题 I have the following rules: functionInv : NAME paramInvList #functionInvStmt ; paramInvList : BRO BRC | BRO expression (',' expression )* BRC ; and an corresponding Ast class: public class FunctionInvocationExpr implements Ast { private final String target; private final List<Ast> arguments; public FunctionInvocationExpr(String target, List<Ast> arguments) { this.target = target; this.arguments = arguments; } @Override public <T> T accept(AstVisitor<T> visitor) { return visitor

antlr4 - parsing function invocations

北城以北 提交于 2021-01-28 11:42:12
问题 I have the following rules: functionInv : NAME paramInvList #functionInvStmt ; paramInvList : BRO BRC | BRO expression (',' expression )* BRC ; and an corresponding Ast class: public class FunctionInvocationExpr implements Ast { private final String target; private final List<Ast> arguments; public FunctionInvocationExpr(String target, List<Ast> arguments) { this.target = target; this.arguments = arguments; } @Override public <T> T accept(AstVisitor<T> visitor) { return visitor

ANTLR grammar to recognize DIGIT keys and INTEGERS too

女生的网名这么多〃 提交于 2021-01-28 07:48:43
问题 I'm trying to create an ANTLR grammar to parse sequences of keys that optionally have a repeat count. For example, (a b c r5) means "repeat keys a, b, and c five times." I have the grammar working for KEYS : ('a'..'z'|'A'..'Z') . But when I try to add digit keys KEYS : ('a'..'z'|'A'..'Z'|'0'..'9') with an input expression like (a 5 r5) , the parse fails on the middle 5 because it can't tell if the 5 is an INTEGER or a KEY. (Or so I think; the error messages are difficult to interpret

How to fix the “multi-character literals are not allowed” error in antlr4 lexer rule?

佐手、 提交于 2021-01-28 06:04:34
问题 The rule I am trying to write is: Character : '\u0000'..'\u10FFF'; But when trying to run antlr tool against the lexer file where it is defined I get the following error: multi-character literals are not allowed in lexer sets: '\u10FFF' How to resolve this problem? 回答1: Try wrapping the multi-char literal with { and } , and use the v4 style character set [...] : Character : [\u0000-\u{10FFF}]; From https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements: [...] Match

Serialization of ANTLR ParseTree

允我心安 提交于 2021-01-28 05:41:17
问题 I have a generated grammar that does two things: Check the syntax of a domain specific language Evaluate input against that domain specific language These two functions are separate, lets call them validate() and evaluate(). The validate() function builds the tree from a String input while ensuring it meets the requirements of the BNF for the language. The evaluate() function plugs in values to that tree to get a result (usually true or false). What the code is currently doing is running