antlr

ANTLR parsing MismatchedTokenException

♀尐吖头ヾ 提交于 2019-12-02 06:42:45
I'm trying to write a simple parser for an even simpler language that I'm writing. It's composed of postfix expressions. As of now, I'm having issues with the parser. When I run it on the input 2 2 * test >> I get a MismatchedTokenException. Also, how would I go about implementing a recursive postfix parser? Here's my code: grammar star; options { language=Python; output=AST; ASTLabelType=CommonTree; } tokens {DECL;} //start // : decl ; //decl // : type ID -> ^(DECL type ID) // ; program : (body)+ ; body : (nested WS)* | (var WS)* | (get WS)* ; var : nested ID '>>' ; get : ID '<<' ; /

ANTLR get and split lexer content

て烟熏妆下的殇ゞ 提交于 2019-12-02 06:13:55
first, sorry about my english, i still learning. I writing Python module for my framework, which parsing CSS files. I try regex, ply (python lexer and parser), but i found myself in ANTLR. First try, i need to parse comments from CSS file. This is my CSS string to parse: /*test*/ /* test1 /* /*test2/*nested*/comment/* I know that CSS doesn't allow nested comments, but i need it in my framework. I wrote simple ANTLR grammar: grammar CSS; options { language = Python; } styleSheet : comments EOF ; comments : NESTED_ML_COMMENT* ; NESTED_ML_COMMENT : '/*' (options {greedy=false;} : (NESTED_ML

How to force ANTLR to parse all input CharStream

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 02:44:50
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 file. TransitionLexer.g4 lexer grammar TransitionLexer; BOOLEAN: 'true' | 'false'; IF: 'if'; THEN: 'then';

Parsing Java code with ANTLR “need concept”

给你一囗甜甜゛ 提交于 2019-12-02 02:20:38
问题 I'm trying to make a compilation of programs using ANTLR and I use the Java programming language as the target and the core of the issue is developing the Intent Regornizer to correct errors and improve the source code if the source code is not in accordance with the Grammar. on tutorials and books on ANTLR I see how to compile a simple code with the assumption that the lexer and parser I've made and the source code like this: int main(){ int a,b; c=20; } how a program can detect errors that

ANTLRInputStream and ANTLRFileStream are deprecated, what are the alternatives?

▼魔方 西西 提交于 2019-12-01 19:48:23
If I use ANTLRFileStream antlrFileStream = new ANTLRFileStream("myfile.testlang"); or ANTLRInputStream input = new ANTLRInputStream( new FileInputStream("myfile.testlang") ); Compiler shows deprecation error for both the classes what is alternative? Ameer Tamboli You can use the CharStreams class instead of the deprecated classes as below. CharStream codePointCharStream = CharStreams.fromFileName("myfile.testlang"); TESTLANGLexer lexer = new TESTLANGLexer(codePointCharStream); TESTLANGParser parser = new TESTLANGParser(new CommonTokenStream(lexer)); parser.addParseListener(new

How to analyze Java source files with Clojure

为君一笑 提交于 2019-12-01 19:43:54
问题 I'm trying to analyze Java source files with Clojure but I couldn't find a way to do that. First, I thought using Eclipse AST plugin(by copying necessary JAR's to my Clojure project) but I gave up after seeing Eclipse AST's API(visitor based walker). Then I've tried creating a Java parser with ANTLR. I can only find one Java 1.6 grammar for ANTLR( http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g ) and it doesn't compile with latest ANTLR(here's the errors I'm getting ). Now

ANTLRInputStream and ANTLRFileStream are deprecated, what are the alternatives?

人走茶凉 提交于 2019-12-01 18:52:36
问题 If I use ANTLRFileStream antlrFileStream = new ANTLRFileStream("myfile.testlang"); or ANTLRInputStream input = new ANTLRInputStream( new FileInputStream("myfile.testlang") ); Compiler shows deprecation error for both the classes what is alternative? 回答1: You can use the CharStreams class instead of the deprecated classes as below. CharStream codePointCharStream = CharStreams.fromFileName("myfile.testlang"); TESTLANGLexer lexer = new TESTLANGLexer(codePointCharStream); TESTLANGParser parser =

What is the equivalent for epsilon in ANTLR BNF grammar notation?

只愿长相守 提交于 2019-12-01 17:22:06
During taking advantage of ANTLR 3.3, I'm changing the current grammar to support inputs without parenthesis too. Here's the first version of my grammar : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ; IMPLIES : '->' ; SYMBOLS : ('a'..'z') | '~' ; OP : '(' ; CP : ')' ; prog : formula EOF ; formula : NOT formula | OP formula( AND formula CP | OR formula CP | IMPLIES formula CP) | SYMBOLS ; WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; Then I changed it this way to support the appropriate features : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ;

What is the equivalent for epsilon in ANTLR BNF grammar notation?

倖福魔咒の 提交于 2019-12-01 17:06:59
问题 During taking advantage of ANTLR 3.3, I'm changing the current grammar to support inputs without parenthesis too. Here's the first version of my grammar : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ; IMPLIES : '->' ; SYMBOLS : ('a'..'z') | '~' ; OP : '(' ; CP : ')' ; prog : formula EOF ; formula : NOT formula | OP formula( AND formula CP | OR formula CP | IMPLIES formula CP) | SYMBOLS ; WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; Then I changed it

ANTLR - mismatched input error

徘徊边缘 提交于 2019-12-01 13:19:46
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: COMMENTBEGIN ~[\r\n]*; DDWORD: 'DD'; JCLBEGIN: '//' ; COMMENTBEGIN: '//*' ; INLINESTMTEND: '/*' ; NAME : [A-Z#]