antlr

Problems building ANTLR v3.3 from source : antlr3-maven-archetype missing

若如初见. 提交于 2019-12-11 17:17:11
问题 Since the ActionScript target of ANTLR 3.3 is buggy, I tried to compile ANTLR 3.3 to fix the Actionscript runtime target as explained in BUILD.txt and here. Installed Maven, set the PATH, and followed the instructions to compile ANTLR. While I actually can make subprojects like gunit using mvn, I fail to build the ANTLR folder. I call mvn in ANTLR distribution root folder, I get this: [ERROR] Child module /Users/KKK/Desktop/Neuer Ordner 4/antlr-3 2.3/antlr3-maven-archetype of /Users/KKK

Why is antlr4 parsing my sentence into two statements?

…衆ロ難τιáo~ 提交于 2019-12-11 17:14:47
问题 I am writing a little parser for expressions. At the moment I just want it to recognize binary multiplications ( myId * myId ) and C-like dereferenced pointers ( *myId ), plus some assignation statements ( myId *= myId ). The input that makes the parser throw errors is: x *= y; ... on which the parser fails with this message and parse tree: [line 1:1 mismatched input ' *' expecting {';', NEWLINE}] (sourceFile (statement (expressionStatement (expression (monoOperatedExpression

ANTLR4 ambiguous grammar

蹲街弑〆低调 提交于 2019-12-11 16:55:25
问题 I want to achieve following behavior: User:class should be parsed to Object - User; Type - class , also Us:er:class should result Object - Us:er; Type - class . I can't make second part work, as soon as I add : as a legal symbol for WORD it parses whole input as an object Object - Us:er:class . My grammar: grammar Sketch; /* * Parser Rules */ input : (object)+ EOF ; object : objectName objectType? NEWLINE ; objectType : ':' TYPE ; objectName : WORD ; /* * Lexer Rules */ fragment LOWERCASE :

ANTLR 4 extraneous input matching non lexer item

痞子三分冷 提交于 2019-12-11 16:47:20
问题 I have a grammar like this : grammar MyGrammar; field : f1 (STROKE f2 f3)? ; f1 : FIELDTEXT+ ; f2 : 'A' ; f3 : NUMBER4 ; FIELDTEXT : ~['/'] ; NUMBER4 : [0-9][0-9][0-9][0-9]; STROKE : '/' ; This works well enough, and fields f1 f2 f3 are all populated correctly. Except when there is an A to the left of the / , (regardless of the presence of the optional part) this additionally causes an error: extraneous input 'A' expecting {<EOF>, FIELDTEXT, '/'} Some sample Data: PHOEN -> OK. KLM405/A4046 ->

ANTLR parser for alpha numeric words which may have whitespace in between

隐身守侯 提交于 2019-12-11 15:25:16
问题 First I tried to identify a normal word and below works fine: grammar Test; myToken: WORD; WORD: (LOWERCASE | UPPERCASE )+ ; fragment LOWERCASE : [a-z] ; fragment UPPERCASE : [A-Z] ; fragment DIGIT: '0'..'9' ; WHITESPACE : (' ' | '\t')+; Just when I added below parser rule just beneath "myToken", even my WORD tokens weren't getting recognised with input string as "abc" ALPHA_NUMERIC_WS: ( WORD | DIGIT | WHITESPACE)+; Does anyone have any idea why is that? 回答1: This is because ANTLR's lexer

ANTLR How to differentiate input arguments of the same type

我的梦境 提交于 2019-12-11 14:44:47
问题 If I have my input message: name IS (Jon, Ted) IS NOT (Peter); I want this AST: name | |-----| IS IS NOT | | | Peter |----| Jon Ted But I'm receiving: name | |-----------------| IS IS NOT | | | | |----|-----| |----|-----| Jon Ted Peter Jon Ted Peter My Grammar file has: ... expression | NAME 'IS' OParen Identifier (Comma Identifier)* CParen 'IS NOT' OParen Identifier (Comma Identifier)* CParen -> ^(NAME ^('IS' ^(Identifier)*) ^('IS NOT' ^(Identifier)*)) ; ... NAME : 'name' ; Identifier : ('a'

how to resolve simple ambiguity

廉价感情. 提交于 2019-12-11 13:50:17
问题 I just started using Antlr and am stuck. I have the below grammar and am trying to resolve the ambiguity to parse input like Field:ValueString. expression : Field ':' ValueString; Field : Letter LetterOrDigit*; ValueString : ~[:]; Letter : [a-zA-Z]; LetterOrDigit : [a-zA-Z0-9]; WS: [ \t\r\n\u000C]+ -> skip; suppose a:b is passed in to the grammar, a and b are both identified as Field. How do I resolve this in Antlr4 (C#)? 回答1: You can use a semantic predicate in your lexer rules to perform

Antlr4, How to report specific syntax error

自古美人都是妖i 提交于 2019-12-11 13:36:41
问题 I am trying to use antlr4 to write some error checking for my simple grammar. The grammar itself is constructed by functions. ie FUNCTION hello (n){ ...... } FUNCTION main (n) { ...... } I am not sure how it suppose to catch specific errors such as missing function name , or missing main function Here is what my ErrorListener looks like import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.tree.*; public class SimpleErrorListener extends BaseErrorListener { @Override public void

Parsing MathML Operators using ANTLR

空扰寡人 提交于 2019-12-11 12:46:27
问题 I'm trying to parse Presentation MathML and build an AST using ANTLR. I have most of the tags supported and I can build nodes for specific constructs. I'm having trouble with the operators. On this page; http://www.w3.org/TR/MathML3/appendixc.html There is a list of the operators, the form they appear in by default (prefix, infix or postifx) and a priority value, which gives the precedence of the operator. I could take each operator code and add it to my lexer and then write rules for unary,

How can I stop NetBeans 8 from deleting generated code at startup?

跟風遠走 提交于 2019-12-11 12:44:35
问题 I have java code generated by Antlr in my NetBeans project. Every time I start NetBeans, it deletes the generated code and forces me to rebuild the project before it can be run. This happens if I do nothing except start NetBeans and then close it after the project finishes loading. How can I tell NetBeans not to delete the generated code at startup? Obviously, I still need to have it regenerate the java code when the Antlr files change that generated it in the first place. 回答1: I discovered