antlr

Verify LL(1) grammar with ANTLR

不想你离开。 提交于 2019-12-10 22:13:56
问题 I understand that ANTLR can accept an LL(*) grammar. But, is there any way to check a grammar whether it is an LL(1) or not using ANTLR? 回答1: options { k = 1; } It will give a warning if your grammer is not in LL(1). 回答2: For a grammer/language to be LL(1) we know that at any given position in the input there is only one production we can take to consume token(s) of the input. So, in order to determine if a grammar is LL(1), we need to: 1) check the FIRST set of all nonterminals and if there

Recognize multiple line comments within a single line with ANTLR4

北城余情 提交于 2019-12-10 21:52:04
问题 I want to parse PostScript code with ANTLR4. I finished with the grammar, but one particular language extension (which was introduced by someone else) makes trouble being reconized. A short example: 1: % This is a line comment 2: % The next line just pushes the value 10 onto the stack 3: 10 4: 5: %?description This is the special line-comment in question 6: /procedure { 7: /var1 30 def %This just creates a variable 8: /var2 10 def %?description A description associated with var2 %?default 20

How to get rid of the following multiple alternatives warnings in my ANTLR3 grammar?

天大地大妈咪最大 提交于 2019-12-10 21:21:26
问题 [11:45:19] warning(200): mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input [11:45:19] warning(200): C:\Users\Jarrod Roberson\mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input I want to be able to nest functions inside other functions. myfunction(x) -> sqr(a) -> a * a, y -> sqr(x). here is the

ANTLR2 vs ANTLR3

和自甴很熟 提交于 2019-12-10 17:54:52
问题 Have you used either of these or both? Which do you prefer, and for what reason? For example, I learned v2 recently and am probably going to stick with it because of the high performance implementation provided by the netbeans team (yeah, I'm stuck with java). In this case would there be any compelling reason to switch? 回答1: To find what's changed between v2 and v3 check out this link: http://www.antlr.org/wiki/pages/viewpage.action?pageId=719 I should note that we still use 2.7.6 with C++

How to preserve whitespace when we use text attribute in Antlr4

ε祈祈猫儿з 提交于 2019-12-10 17:30:06
问题 I want to keep white space when I call text attribute of token, is there any way to do it? Here is the situation: We have the following code IF L > 40 THEN; ELSE IF A = 20 THEN PUT "HELLO"; In this case, I want to transform it into: if (!(L>40){ if (A=20) put "hello"; } The rule in Antlr is that: stmt_if_block: IF expr THEN x=stmt (ELSE y=stmt)? { if ($x.text.equalsIgnoreCase(";")) { WriteLn("if(!(" + $expr.text +")){"); WriteLn($stmt.text); Writeln("}"); } } But the result looks like: if(!(L

Controlling false IntelliJ code editor error in Scala plugin

徘徊边缘 提交于 2019-12-10 17:26:06
问题 I have Java code generated from ANTLR4. Scala is using the Java code by extending some of the methods. The issue is that IntelliJ's scala plugin does not seem to know the relationship between Java base class and Scala subclass to show a false positive error message; it reports "Method ... overrides nothing" when Scala overrides Java method. How to control the error level in IntelliJ to suppress this error message? 回答1: Most of the false-negatives produced by Scala plugin are caused by type

What happened to options in rules in ANTLR 4?

我的未来我决定 提交于 2019-12-10 16:14:54
问题 This does not compile in ANTLR 4: Number options { backtrack=true; } : (IntegerLiteral Range)=> IntegerLiteral { $type = IntegerLiteral; } | (FloatLiteral)=> FloatLiteral { $type = FloatLiteral; } | IntegerLiteral { $type = IntegerLiteral; } ; because of backtrace= true... What happened to it? WHat should I use in ANTLR 4 instread of it? 回答1: At the moment, there are no rule-level options in ANTLR v4. Note that backtrack=true is no longer needed since the new parsing algorithm has no need for

Token recognition error: antlr

强颜欢笑 提交于 2019-12-10 15:25:39
问题 I have an ANTLR 4 grammar: grammar Test; start : NonZeroDigit '.' Digit Digit? EOF ; DOT : '.' ; PLUS : '+' ; MINUS : '-' ; COLON : ':' ; COMMA : ',' ; QUOTE : '\"' ; EQUALS : '=' ; SEMICOLON : ';' ; UNDERLINE : '_' ; BACKSLASH : '\\' ; SINGLEQUOTE : '\'' ; RESULT_TYPE_NONE : 'NONE' ; RESULT_TYPE_RESULT : 'RESULT' ; RESULT_TYPE_RESULT_SET : 'RESULT_SET' ; TYPE_INT : 'Int' ; TYPE_LONG : 'Long' ; TYPE_BOOL : 'Bool' ; TYPE_DATE : 'Date' ; TYPE_DOUBLE : 'Double' ; TYPE_STRING : 'String' ; TYPE

ANTLR mismatched input '<EOF>'

这一生的挚爱 提交于 2019-12-10 14:40:37
问题 Given the following ANTLR 4.1 grammar, with one line intentionally commented out ... grammar Foobar; //whyDoesThisRuleHelp : expression ; expression : operand | binaryOperation ; binaryOperation : operand WS BINARY_OPERATOR WS expression ; operand : LETTER ; BINARY_OPERATOR : 'EQ' ; LETTER : [a-z] ; WS : [ \n]+ ; .. why does echo -n "a EQ b" | grun Foobar expression produce line 1:6 mismatched input '<EOF>' expecting WS .. but if we uncomment the block : expression ; line above then grun

Writing parser rules sensitive to whitespace while skipping WS from the lexer

本秂侑毒 提交于 2019-12-10 14:14:38
问题 I am having some troubles in handling whitespace. In the following excerpt of a grammar, I set up the lexer so that the parser skips whitespace: ENTITY_VAR : 'user' | 'resource' ; INT : DIGIT+ | '-' DIGIT+ ; ID : LETTER (LETTER | DIGIT | SPECIAL)* ; ENTITY_ID : '__' ENTITY_VAR ('_w_' ID)?; NEWLINE : '\r'? '\n'; WS : [ \t\r\n]+ -> skip; // skip spaces, tabs, newlines fragment LETTER : [a-zA-Z]; fragment DIGIT : [0-9]; fragment SPECIAL : ('_' | '#' ); The problem is, I would like to match