antlr

How to stop ANTLR from suppressing syntax errors?

旧城冷巷雨未停 提交于 2019-12-06 09:24:18
So I'm writing a compiler in Java using ANTLR, and I'm a little puzzled by how it deals with errors. The default behavior seems to be to print an error message and then attempt, by means of token insertion and such, to recover from the error and continue parsing. I like this in principle; it means that (in the best case) if the user has committed more than one syntax error, they'll get one message per error, but it'll mention all the errors instead of forcing them to recompile to discover the next one. The default error message is fine for my purposes. The trouble comes when it's done reading

Antlr and PL/I grammar

北城以北 提交于 2019-12-06 09:17:04
Right now we would like to have the grammar of PL/I, COBOL based on Antlr4. Is there anyone provide these grammars If not, can you please share your thought/experience on developing these grammars from scratch Thanks I assume you mean IBM PL/I and COBOL. (Not many other PL/Is around, but I don't think that really changes the answer much). The obvious place to look for mature ANTLR grammars is ANTLR3 grammar library ; no PL/1 or COBOL grammars there. The Antlr V4 (a very new, radical, backwards incompatible reengineering of ANTLR3) main page talks about Java and C#; no hint of PL/1 or COBOL

Python+ANTLR4: No module named antlr4

╄→гoц情女王★ 提交于 2019-12-06 08:53:24
I would like to use ANTLR4 with Python 2.7 and for this I did the following: I installed the package antlr4-4.6-1 on Arch Linux with sudo pacman -S antlr4 . I wrote a MyGrammar.g4 file and successfully generated Lexer and Parser Code with antlr4 -Dlanguage=Python2 MyGrammar.g4 Now executing for example the generated Lexer code with python2 MyGrammarLexer.py results in the error ImportError: No module named antlr4 . What could to be the problem? FYI: I have both Python2 and Python3 installed - I don't know if that might cause any trouble. You need to install antlr4 for python through pip : sudo

ANTLR4: implicit or explicit token definition

倖福魔咒の 提交于 2019-12-06 08:04:07
问题 What are the benefits and drawbacks of using explicit token definitions in ANTLR4? I find the text in single parentheses more descriptive and easier to use than creating a separate token and using that in place of the text. E.g.: grammar SimpleTest; top: library | module ; library: 'library' library_name ';' ; library_name: IDENTIFIER; module: MODULE module_name ';' ; module_name: IDENTIFIER; MODULE: 'module' ; IDENTIFIER: [a-zA-Z0-9]+; The generated tokens are: T__0=1 T__1=2 MODULE=3

terminal/datatype/parser rules in xtext

你离开我真会死。 提交于 2019-12-06 07:06:59
问题 I'm using xtext 2.4. What I want to do is a SQL-like syntax. The things confuse me are I'm not sure which things should be treated as terminal/datatype/parser rules. So far my grammar related to MyTerm is: Model: (terms += MyTerm ';')* ; MyTerm: constant=MyConstant | variable?='?'| collection_literal=CollectionLiteral ; MyConstant : string=STRING | number=MyNumber | date=MYDATE | uuid=UUID | boolean=MYBOOLEAN | hex=BLOB ; MyNumber: int=SIGNINT | float=SIGNFLOAT ; SIGNINT returns ecore::EInt:

How can I import an ANTLR lexer grammar into another grammar using Gradle 2.10?

浪尽此生 提交于 2019-12-06 06:05:11
I've been learning about ANTLR 4 with Terence Parr's The Definitive ANTLR 4 Reference , which I've been following so far using Gradle 2.10 and its built-in ANTLR plugin. However I'm having some trouble getting some code which I adapted from Chapter 4, pp. 38-41 to work properly with my Gradle build script. (The reason I'm using Gradle, rather than ANTLR directly, is because I want to eventually integrate ANTLR into a Java web application which I'm making for my dissertation, and I'd strongly prefer to use a build tool for this so I can automate the ANTLR-to-Java code generation process and

Antlr4 language translation - separating template logic from visitor class?

微笑、不失礼 提交于 2019-12-06 05:56:23
问题 I’m looking at pragmatically translating huge amounts of relatively simple TSQL code to Groovy code. There are a number of reasons sure, but the driving reason is just to see if it can be done and in the process learn about compilers/grammers/ etc. Antlr4 seems like the ideal tool for this problem (Java is a plus). Tokenizing / parsing the TSQL (using a grammar file), and reading the tree using the generated Listener/Visitor is pretty straight forward. I know I could just create the string

ANTLR grammar for scheme R5RS

你说的曾经没有我的故事 提交于 2019-12-06 05:09:31
I'm beginner in ANTLR and I'm learning it by an example. I use C as my target language. The example is a Scheme R5RS grammar file taken from this question , with a little modification(rename the grammar name and add some options with the grammar specification untouched). antlr generated the lexer and parser, and I compile it with a test main() in which I just do some initialization and simply call the parser. When runing the test program with a piece of scheme code, the parser detect some syntax error(which should not happen!) main function in test.c #include <stdio.h> #include "r5rsLexer.h"

ANTLR syntax error unexpected token: +

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:24:14
Hi I have a small problem in my ANTLR tree grammar. I am using ANTLRWorks 1.4. In parser grammar I have the rule like this: declaration : 'variable' IDENTIFIER ( ',' IDENTIFIER)* ':' TYPE ';' -> ^('variable' IDENTIFIER TYPE)+ So I wanted one tree per each IDENTIFIER. And in the tree grammar I left only rewrite rules: declaration : ^('variable' IDENTIFIER TYPE)+ But when I check grammar I got syntax error unexpected token +. And it is this + sign at the end of the declaration rule in the tree grammar. So what I am doing wrong? Parser grammar works fine and builds AST tree as expected. I

Solving ANTLR Mutually left-recursive rules

China☆狼群 提交于 2019-12-06 03:54:38
the 'expr' rule in the ANTLR grammar below obviously mutually left-recursive. As a ANTLR newbie it's difficult to get my head around solving this. I've read "Resolving Non-LL(*) Conflicts" in the ANTLR reference book, but I still don't see the solution. Any pointers? LPAREN : ( '(' ) ; RPAREN : ( ')' ); AND : ( 'AND' | '&' | 'EN' ) ; OR : ( 'OR' | '|' | 'OF' ); NOT : ('-' | 'NOT' | 'NIET' ); WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; WORD : (~( ' ' | '\t' | '\r' | '\n' | '(' | ')' | '"' ))*; input : expr EOF; expr : (andexpr | orexpr | notexpr | atom); andexpr : expr AND expr;