antlr4

variation in code generation, using ANTLR4 parse tree visitors

扶醉桌前 提交于 2021-02-16 14:56:12
问题 I am writing transpiler ( myLang -> JS) using ANTLR (javascript target with visitor). Focus is on target code generation part, from the parse tree. As in, how to deal with language source codes variations. To make question clearer, consider two variations below - source#1: PRINT 'hello there' source#2: varGreeting = 'hey!' PRINT varGreeting In case 1, I deal with string. While in case 2, it's a variable. JS target code then needs to be different (below). case 1 with quotes, case 2 without.

ANTLR best practice for finding and catching parse errors

若如初见. 提交于 2021-02-11 15:05:38
问题 This question concerns how to get error messages out of an ANTLR4 parser in C# in Visual Studio. I feed the ANTLR parser a known bad input string, but I am not seeing any errors or parse exceptions thrown during the (bad) parse. Thus, my exception handler does not get a chance to create and store any error messages during the parse. I am working with an ANTLR4 grammar that I know to be correct because I can see correct parse operation outputs in graphical form with an ANTLR extension to

AttributeError: 'MuParser' object has no attribute 'startRule'

我们两清 提交于 2021-02-11 06:44:54
问题 So I copied this code from an SO answer: grammar Mu; parse : block EOF ; block : stat* ; stat : assignment | if_stat | while_stat | log | OTHER {System.err.println("unknown char: " + $OTHER.text);} ; assignment : ID ASSIGN expr SCOL ; if_stat : IF condition_block (ELSE IF condition_block)* (ELSE stat_block)? ; condition_block : expr stat_block ; stat_block : OBRACE block CBRACE | stat ; while_stat : WHILE expr stat_block ; log : LOG expr SCOL ; expr : expr POW<assoc=right> expr #powExpr |

AttributeError: 'MuParser' object has no attribute 'startRule'

断了今生、忘了曾经 提交于 2021-02-11 06:44:08
问题 So I copied this code from an SO answer: grammar Mu; parse : block EOF ; block : stat* ; stat : assignment | if_stat | while_stat | log | OTHER {System.err.println("unknown char: " + $OTHER.text);} ; assignment : ID ASSIGN expr SCOL ; if_stat : IF condition_block (ELSE IF condition_block)* (ELSE stat_block)? ; condition_block : expr stat_block ; stat_block : OBRACE block CBRACE | stat ; while_stat : WHILE expr stat_block ; log : LOG expr SCOL ; expr : expr POW<assoc=right> expr #powExpr |

ANTLR4 Parser issues

十年热恋 提交于 2021-02-10 14:57:30
问题 I'm trying to write parser for c++ style header file and failing to properly configure the parser. Lexer: lexer grammar HeaderLexer; SectionLineComment : LINE_COMMENT_SIGN Section CharacterSequence ; Pragma : POUND 'pragma' ; Section : AT_SIGN 'section' ; Define : POUND 'define' | LINE_COMMENT_SIGN POUND 'define' ; Booleanliteral : False | True ; QuotedCharacterSequence : '"' .*? '"' ; ArraySequence : '{' .*? '}' | '[' .*? ']' ; IntNumber : Digit+ ; DoubleNumber : Digit+ POINT Digit+ | ZERO

ANTLR4 Parser issues

跟風遠走 提交于 2021-02-10 14:55:13
问题 I'm trying to write parser for c++ style header file and failing to properly configure the parser. Lexer: lexer grammar HeaderLexer; SectionLineComment : LINE_COMMENT_SIGN Section CharacterSequence ; Pragma : POUND 'pragma' ; Section : AT_SIGN 'section' ; Define : POUND 'define' | LINE_COMMENT_SIGN POUND 'define' ; Booleanliteral : False | True ; QuotedCharacterSequence : '"' .*? '"' ; ArraySequence : '{' .*? '}' | '[' .*? ']' ; IntNumber : Digit+ ; DoubleNumber : Digit+ POINT Digit+ | ZERO

Parse arbitrary delimiter character using Antlr4

 ̄綄美尐妖づ 提交于 2021-02-09 15:16:44
问题 I try to create a grammar in Antlr4 that accepts regular expressions delimited by an arbitrary character (similar as in Perl). How can I achieve this? To be clear: My problem is not the regular expression itself (which I actually do not handle in Antlr, but in the visitor), but the delimiter characters. I can easily define the following rules to the lexer: REGEXP: '/' (ESC_SEQ | ~('\\' | '/'))+ '/' ; fragment ESC_SEQ: '\\' . ; This will use the forward slash as the delimiter (like it is

Parse arbitrary delimiter character using Antlr4

a 夏天 提交于 2021-02-09 15:09:46
问题 I try to create a grammar in Antlr4 that accepts regular expressions delimited by an arbitrary character (similar as in Perl). How can I achieve this? To be clear: My problem is not the regular expression itself (which I actually do not handle in Antlr, but in the visitor), but the delimiter characters. I can easily define the following rules to the lexer: REGEXP: '/' (ESC_SEQ | ~('\\' | '/'))+ '/' ; fragment ESC_SEQ: '\\' . ; This will use the forward slash as the delimiter (like it is

IntelliJ IDEA Gradle project not recognizing/locating Antlr generated sources

﹥>﹥吖頭↗ 提交于 2021-02-08 12:21:46
问题 I'm using Antlr in a simple Kotlin/Gradle project, and while my Gradle build is generating Antlr sources, they are not available for importing into the project. As you can see (on the left), the classes (Lexer/Parser, etc.) are being generated. I have also configured this generated-src/antlr/main directory as a Source Root . Most questions I see list this as a solution, but I've already done it. The issue persists after multiple rebuilds (both in IDEA and on the CLI), and following all the

ANTLR4 skips empty line only

冷暖自知 提交于 2021-02-08 03:33:17
问题 I am using antlr4 parsing a text file and I am new to it. Here is the part of the file: abcdef //emptyline abcdef In file stream string it will be looked like this: abcdef\r\n\r\nabcdef\r\n In terms of ANTLR4, it offers the "skip" method to skip something like white-space, TAB, and new line symbol by regular expression while parsing. i.e. WS : [\t\s\r\n]+ -> skip ; // skip spaces, tabs, newlines My problem is that I want to skip the empty line only. I don't want to skip every single "\r\n".