antlrworks

How to throw meaningful error on syntax or parsing error [duplicate]

家住魔仙堡 提交于 2020-03-28 07:06:50
问题 This question already has answers here : Is there a way to easily adapt the error messages of ANTLR4? (2 answers) Closed 10 days ago . I have a grammar for parsing jcl The jcl looks like below /*comment line //PR1290@ JOB (10),'ISPW COB SN900E' lexer and parser is working perfectly fine. Suppose instead of // if jcl starts from / currently lexer is throwing 1:0 token recognition error at: '/P' Parser will throw no viable alternative input R1290@ JOB I am looking for throwing error similar to

C example of using AntLR

匆匆过客 提交于 2020-01-15 05:45:09
问题 I am wondering where I can find C tutorial/example of using AntLR. All I found is using Java language. I am focusing to find a main function which use the parser and lexer generated by AntLR. 回答1: Take a look at this document And here is an example: // Example of a grammar for parsing C sources, // Adapted from Java equivalent example, by Terence Parr // Author: Jim Idle - April 2007 // Permission is granted to use this example code in any way you want, so long as // all the original authors

AntlrWorks & language grammar errors

放肆的年华 提交于 2020-01-05 07:50:12
问题 Working on a game project that involves a scripting language that I want to interpret into a virtual machine code that can be executed directly. I've included the grammar below. All the lexer rules are displaying properly in the syntax diagram, but when I click on the bodies of any of the parser rules, I get "Cannot display rule "X" because start state is not found" for a given parser rule X. I'm not really sure why ANTLR is complaining about not having a start state. The grammar should

ANTLRWorks 1.4.3 can't properly read extended-ASCII characters

与世无争的帅哥 提交于 2020-01-04 04:11:08
问题 I'm working on a fairly standard compiler project for which I picked ANTLR as the parser-generator. While updating an existing grammar from v2 to v3 I noticed that ANTLRWorks, the official IDE for ANTLR, wasn't displaying any of the extended-ASCII characters in the file properly. Even after using Notepad++ to convert the file to UTF8 from ASCII did it still display those characters as squares. In Notepad++ they display fine. Since this glitch means that ANTLRWorks mauls the file when I save

ANTLR and Eclipse (or any decent IDE)

故事扮演 提交于 2020-01-01 04:51:04
问题 I have been using ANTLR with Eclipse for some time using the ANTLRv3IDE plugin. While it is not perfect, and a bit outdated, it does its job reasonably well. Now I am looking to switch to ANTLRv4 for another DSL that I am creating. However, Eclipse support seems to be extremely thin. I decided to try out ANTLRWorks, which is a NetBeans plugin, but I could not get it to install (it seems to be locked to specific dated versions (201302132200 while I have something newer, still 7.3 as docs say)

ANTLR parsing MismatchedTokenException

拜拜、爱过 提交于 2019-12-31 04:37:07
问题 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 :

Antlrworks - extraneous input

送分小仙女□ 提交于 2019-12-24 01:37:21
问题 I am new in this stuff, and for that reason I will need your help.. I am trying to parse the Wikipedia Dump, and my first step is to map each rule defined by them into ANTLR, unfortunally I got my first barrier: line 1:8 extraneous input ''''' expecting '\'\'' I am not understanding what is going on, please lend me your help. My code: grammar Test; options { language = Java; } parse : term+ EOF ; term : IDENT | '[[' term ']]' | '\'\'' term '\'\'' | '\'\'\'' term '\'\'\'' ; IDENT : ('a'..'z' |

ANTLR java test file can't create object of tree grammar

爷,独闯天下 提交于 2019-12-23 04:34:45
问题 I am creating a parser using ANTLR 3.x that targets java. I have written both parser grammar (for creating Abstract Syntax Tree, AST) and Tree Grammar (for performing operations on AST). Finally, to test both grammar files, I have written a test file in Java. Have a look at the below code, protocol grammar grammar protocol; options { language = Java; output = AST; } tokens{ //imaginary tokens PROT; INITIALP; PROC; TRANSITIONS; } @header { import twoprocess.Configuration; package com.javadude

ANTLR java test file can't create object of tree grammar

你离开我真会死。 提交于 2019-12-23 04:34:10
问题 I am creating a parser using ANTLR 3.x that targets java. I have written both parser grammar (for creating Abstract Syntax Tree, AST) and Tree Grammar (for performing operations on AST). Finally, to test both grammar files, I have written a test file in Java. Have a look at the below code, protocol grammar grammar protocol; options { language = Java; output = AST; } tokens{ //imaginary tokens PROT; INITIALP; PROC; TRANSITIONS; } @header { import twoprocess.Configuration; package com.javadude

ANTLR lexer rule consumes characters even if not matched?

痴心易碎 提交于 2019-12-22 06:09:21
问题 I've got a strange side effect of an antlr lexer rule and I've created an (almost) minimal working example to demonstrate it. In this example I want to match the String [0..1] for example. But when I debug the grammar the token stream that reaches the parser only contains [..1] . The first integer, no matter how many digits it contains is always consumed and I've got no clue as to how that happens. If I remove the FLOAT rule everything is fine so I guess the mistake lies somewhere in that