antlr

ANTLR on a noisy data stream

对着背影说爱祢 提交于 2019-12-20 03:35:13
问题 I'm very new in the ANTLR world and I'm trying to figure out how can I use this parsing tool to interpret a set of "noisy" string. What I would like to achieve is the following. let's take for example this phrase : It's 10PM and the Lazy CAT is currently SLEEPING heavily on the SOFA in front of the TV What I would like to extract is CAT , SLEEPING and SOFA and have a grammar that match easily the following pattern : SUBJECT - VERB - INDIRECT OBJECT... where I could define VERB : 'SLEEPING' |

How to force ANTLR to parse all input CharStream

↘锁芯ラ 提交于 2019-12-20 03:03:27
问题 I'm using ANTLR4 to parse a syntax file. When I use BaseErrorListener to detect errors, I got a problem. When faced with an illegal input string, ANTLR automatically matches the appropriate branch and then ignores the subsequent stream of characters even if it contains errors. And I want to detect that error. Here are my g4 file and java file. TransitionLexer is my lexer file and TransitionCondition is my parser file. ErrorDialogListener.java is my errorListener and Test.java id main java

Float literal and range parameter in ANTLR

陌路散爱 提交于 2019-12-20 01:15:06
问题 I'm working on a parser for the language D and I ran in to trouble when I tried to add the "slice" operator rule. You can find the ANTLR grammar for it here. Basically the problem is that if the lexer encounters a string like this: "1..2" it gets completely lost, and it ends up being as a single float value and therefore the postfixExpression rule for a string like "a[10..11]" ends up being a ExpArrIndex object with a ExpLiteralReal argument. Can somebody explain what is exactly wrong with

ANTLR - mismatched input error

瘦欲@ 提交于 2019-12-19 11:40:37
问题 I have a grammar which looks like this consisting of comment and control statements of a particular language: Grammar: grammar DD; ddlist: (ddstmt| jclcomment)+; ddstmt: dd1 | dd2 | dd3 | dd4 ; dd1: JCLBEGIN ddname DDWORD 'DUMMY'; dd2: JCLBEGIN ddname DDWORD 'DYNAM'; dd3: JCLBEGIN ddname DDWORD NAME'=' ('*'|NAME); dd4: JCLBEGIN ddname DDWORD '*' inlinerec INLINESTMTEND?; inlinerec: (INLINEDATA )+ ; fragment INLINEDATA: (~[\r\n])*; ddname: NAME; jclcomment: JCLCOMMENT+; JCLCOMMENT:

ANTLR PCRE Grammar to JS Target

二次信任 提交于 2019-12-19 11:04:26
问题 I'm trying to build Bart Kiers' ANTLR PCRE grammar (see: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html) to a JS target. The only way I get get it to build is with global backtracking and memoization and it's generating code that is invalid here is the grammar: grammar PCRE; options { language=JavaScript; backtrack=true; memoize=true; } parse : regexAtom* EOF ; ... and the rest of the grammar as seen: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html The lexer is generating code that

ANTLR4 parse tree simplification

孤者浪人 提交于 2019-12-19 04:12:12
问题 Is there any means to get ANTLR4 to automatically remove redundant nodes in generated parse trees? More specifically, I've been experimenting with a grammar for GLSL and you end up with long linear sequences of "expressions" in the parse tree due to the rule forwarding needed to give the automatic handling of operator precedence. Most of the generated tree nodes are simply "forward to the next level of precedence", so don't provide any useful syntactic information - you only really need the

Extend ANTLR3 AST's

余生颓废 提交于 2019-12-19 04:05:48
问题 With ANTLR2, you could define something like this in grammar definition file: options { language = "CSharp"; namespace = "Extended.Tokens"; } tokens { TOKEN<AST=Extended.Tokens.TokenNode>; } And then, you could create a class: public class TokenNode: antlr.BaseAST { ... } Any ideea if something like this can be used (delegate class creation to AST factory instead of me doing the tree replication manually)? It's not working just by simple grammar definition copy from old to new format, and I

Is there a list of reserved words in ANTLR grammars?

纵然是瞬间 提交于 2019-12-19 03:46:10
问题 I recently created an ANTLR3 parser rule options : foo bar; which didn't compile and it took me some time to discover that options was a reserved word (AntlrWorks indicated an error but not why). Is there a list of reserved words in ANTLR and are there best practices in naming rules (which might help avoid this)? 回答1: The reserved words of ANTLR v3 are: Keyword | Description ---------+-------------------------------------------------------- scope | Dynamically-scoped attribute fragment |

Parse comment line

十年热恋 提交于 2019-12-18 21:18:22
问题 Given the following basic grammar I want to understand how I can handle comment lines. Missing is the handling of the <CR><LF> which usually terminates the comment line - the only exception is a last comment line before the EOF, e. g.: # comment abcd := 12 ; # comment eof without <CR><LF> grammar CommentLine1a; //========================================================== // Options //========================================================== //=================================================

How to use plsql-parser (ANTLR)

我的未来我决定 提交于 2019-12-18 13:38:45
问题 I'd like to check PL/SQL query syntax in automated tests, and it looks like https://github.com/porcelli/plsql-parser might be useful for that. I am not easily finding out how I would install and use it though. Note that this is for a Ruby project, but I'm reasonably competent in Java. I'm hoping there's some way I can run the checking via console, pass in the SQL, and get back any error info, including line/column. Thanks. 回答1: Download the ANTLR tool ver 3.5.1 Download the source codes from