antlr4

IlegalStateException when I type unfinished code into a JEditorPane with syntax highlighting support

北战南征 提交于 2019-12-23 05:10:39
问题 Using ANTLR4 and the Netbeans Platform I have created a grammar for which I have implemented syntax highlighting in my Netbeans Platform application. Everything works fine up to the point when I try to alter my code. grammar MyRule; my_rule : '(' my_rule ')' | binary | binary_hyst | my_rule (AND my_rule)+ | my_rule (OR my_rule)+ ; binary : '(' binary ')' | unary (EQ | NE) unary ; binary_hyst : '(' binary_hyst ')' | unary hyst? ( GT | LT | GTE | LTE ) unary hyst? ; hyst : (HYST '(' unary ')');

ANTLR4 Semantic Predicate Called Before @init

一笑奈何 提交于 2019-12-23 04:12:24
问题 I have grammar with a semantic predicate in a subrule which requires initialization to be done in the invoking rule in order to execute properly e.g.. decl_specifier_seq @init { //some initialization required by a semantic predicate } : decl_specifier+ ; decl_specifier : storage_class_specifier //auto, register, static, extern, mutable | {/*semantic predicate requiring the initialization*/}? type_specifier | function_specifier //inline, virtual, explicit ; But some tests show that the

ANTLR4 Lexer error reporting (length of offending characters)

一曲冷凌霜 提交于 2019-12-23 03:24:12
问题 I'm developing a small IDE for some language using ANTLR4 and need to underline erroneous characters when the lexer fails to match them. The built in org.antlr.v4.runtime.ANTLRErrorListener implementation outputs a message to stderr in such cases, similar to this: line 35:25 token recognition error at: 'foo\n' I have no problem understanding how information about line and column of the error is obtained (passed as arguments to syntaxError callback), but how do I get the 'foo\n' string inside

ANTLR4 - How do I get the token TYPE as the token text in ANTLR?

你离开我真会死。 提交于 2019-12-23 02:44:08
问题 Say I have a grammar that has tokens like this: AND : 'AND' | 'and' | '&&' | '&'; OR : 'OR' | 'or' | '||' | '|' ; NOT : 'NOT' | 'not' | '~' | '!'; When I visualize the ParseTree using TreeViewer or print the tree using tree.toStringTree(), each node's text is the same as what was matched. So if I parse "A and B or C", the two binary operators will be "and" / "or". If I parse "A && B || C", they'll be "&&" / "||". What I would LIKE is for them to always be "AND" / "OR / "NOT", regardless of

Switching to island mode on multi-character token

陌路散爱 提交于 2019-12-23 02:04:11
问题 I am working on a grammar that is basically an island grammar. Let's say the "island" is everything between braces, the "sea" is everything that is not. Like this: { (island content) } Then this simple grammar works: IslandStart : '{' -> pushMode(Island) ; Fluff : ~[\{\}]+ ; .... But I'm having trouble to come up with a similar solution to a case where I want the complex (multi-character) opening for my "island" block, like this: {# (island content) } In this case I don't know how to make a

Modify expressions, generated by Antlr?

依然范特西╮ 提交于 2019-12-23 01:41:32
问题 I would like to read expressions with Antlr4 and the perform some modifications on them. For example, if grammar is arithmetic, I would modify expression, representing 2 * (3 + 1) with 2 * 4 and then with 8 This is "calculation" or "simplification". To perform this thing I would create some tree structure and the first idea is to use the very same trees, created by Antlr. Unfortunately, I don't see any setters for children. How to accomplish? Should I really duplicate Antlr trees with my own

Antlr and PL/I grammar

元气小坏坏 提交于 2019-12-22 12:51:12
问题 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 回答1: 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,

Antlr and PL/I grammar

爱⌒轻易说出口 提交于 2019-12-22 12:51:01
问题 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 回答1: 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,

Import ANTLR4 lexer grammar which uses different modes

旧城冷巷雨未停 提交于 2019-12-22 10:48:56
问题 I am trying to import a lexer grammar into another lexer grammar. The imported grammar uses differen modes (in the XMLLexer example modes INSIDE and PROC_INSTR). lexer grammar HTMLLexer; import XMLLexer; When compiling, I get an error that an variable which correspond to the mode name is not defined. As an concrete example I am defining an HTMLLexer on top of the XMLLexer (from the antlr4 book) and get the following Error: C:\Users\<user>\AppData\Local\Temp\TestRigTask-1360839400637\HTMLLexer

How to implement the visitor pattern for nested function

折月煮酒 提交于 2019-12-22 04:03:06
问题 I am a newbie to Antlr and I wanted the below implementation to be done using Antlr4. I am having the below-written functions. 1. FUNCTION.add(Integer a,Integer b) 2. FUNCTION.concat(String a,String b) 3. FUNCTION.mul(Integer a,Integer b) And I am storing the functions metadata like this. Map<String,String> map=new HashMap<>(); map.put("FUNCTION.add","Integer:Integer,Integer"); map.put("FUNCTION.concat","String:String,String"); map.put("FUNCTION.mul","Integer:Integer,Integer"); Where, Integer