antlr

Adding a new language with “ace” library

房东的猫 提交于 2019-12-23 22:52:47
问题 I'm new to Ace, and I want to add a new language. I created the file named new_highlight_rules , the problem is I have to add tokens and corresponding regex in this file, and my new language is very complicated, so I have a lot of regex and rules to add. My question is: if I have the grammar of my language written for ANTLR, is there a practical way to add regexes and tokens? and is there any other way without using ANTLR? Please I'm new and any guidance, even very basic, can help me. 回答1: If

Antlr3 matching tokens without whitespace

元气小坏坏 提交于 2019-12-23 21:06:13
问题 Given the input "term >1" , the number(1) and comparison operator(>) should generate seperate nodes in an AST. How can this be achieved? In my tests matching only occured if "c" and "1" where seperated with a space like so " term < 1 ". Current grammar: startExpression : orEx; expressionLevel4 : LPARENTHESIS! orEx RPARENTHESIS! | atomicExpression; expressionLevel3 : (fieldExpression) | expressionLevel4 ; expressionLevel2 : (nearExpression) | expressionLevel3 ; expressionLevel1 :

Decompose expression in base operation: ANTLR + StringTemplate

流过昼夜 提交于 2019-12-23 17:30:32
问题 I am trying to write a translator for a Java like language to multiple languages. Right now I am facing 2 problems: First is to decompose complex expression in a sequence of basic operation and then translating them to destination language. For example my starting language can be: var a = (ln(b) + avg(c))*2 I'd like to traslate it like: var x1 = log_N(b); var x2 = average(c); var x3 = sum(x1, x2); var a = multiply(x3, 2); I think i have to use a Tree parser, nut I am not sure how to integrate

Antlr grammar generating invalid C# code

こ雲淡風輕ζ 提交于 2019-12-23 16:12:39
问题 I am trying to develop a c# code generator using ANTLR and the StringTemplate library. AntlrWorks can generate the c# parser and lexer files without reporting any errors. However, the c# parser code is not valid and cannot be compiled in visual studio. Can anyone see what is wrong with the following grammar? grammar StrucadShape; options { language=CSharp3 ; output=template; } @header {using System;} @lexer::header {using System;} @lexer::members {const int HIDDEN = Hidden;} /*---------------

ANTLR NoViableAltException with JAVA

北慕城南 提交于 2019-12-23 12:43:08
问题 In my grammar with antlrworks, I can get noviablealtexception for rules like if, while which need corresponding right and left brackets. However, in java, i cannot get noviablealtexception. loop_statement: (WHILE LPAREN expr RPAREN statement) | (DO statement WHILE LPAREN expr RPAREN); condition_statement : IF LPAREN expr RPAREN statement (options {greedy=true;}: ELSE statement)? In statement rule I have a block rule which is, statement_blocks : (LBRACE statement* RBRACE) ; And statement rule

ANTLR how to detect rubbish data at end of input

拟墨画扇 提交于 2019-12-23 12:34:50
问题 When using grammars written in ANTLR, the parser correctly recognizes data from an input stream, but if I have some rubbish text at the end of the input (which is not supposed to be parsed by the grammar) the parser does not complain. I guess this behavior is all right (I mean the parser did its job and parsed whatever I said it should parse), but is there any trick to detect when there is any data left in the input after the parser has done its job? Thanks. 回答1: As Scott already answered on

boolean and arithmetic expression grammar in ANTLR

夙愿已清 提交于 2019-12-23 11:11:47
问题 I'm trying to write a grammar for arithmetic and boolean expressions. I don't understand what I'm doing wrong. For my grammar, ANTLR says: [fatal] rule logic_atom has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option. But I can't do a left-factoring. And I don't want to touch arith_expr , because for this I have a code. Error in logic_atom : LBR logic_expr RBR | cmp_expr ; My

The selected wizard could not be started in eclipse for Anltr 4 .How to solve?

人盡茶涼 提交于 2019-12-23 10:49:13
问题 The selected wizard could not be started. Failed to create injector for com.github.jknack.antlr4ide.Antlr4 ExtensionFactory: com.github.jknack.antlr4ide.ui.Antlr4ExecutableExtensionFactory Failed to create injector for com.github.jknack.antlr4ide.Antlr4 How do I solve this problem? 回答1: I have solved the problem by installing xtext 2.7.3: Download In Eclipse > Help > Install New Software... Add... > Archive > Select downloaded .zip file Check Xtext from the list > Continue installing Restart

antlr 4.2.2 output to console warning (157)

坚强是说给别人听的谎言 提交于 2019-12-23 09:58:19
问题 I downloaded latest release of ANTLR - 4.2.2 (antlr-4.2.2-complete.jar) When I use it to generate parsers for grammar file Java.g4 it prints me some warnings like: "Java.g4:525:16: rule 'expression' contains an 'assoc' terminal option in an unrecognized location" Files was generated but didn't compile Previous version works fine. Whats wrong? 回答1: The <assoc> should now be moved left of the "expression". It must be placed always right to the surrounding | : Look here: https://theantlrguy

Range quantifier syntax in ANTLR Regex

烂漫一生 提交于 2019-12-23 08:02:02
问题 This should be fairly simple. I'm working on a lexer grammar using ANTLR, and want to limit the maximum length of variable identifiers to 30 characters. I attempted to accomplish this with this line(following normal regex - except for the '' thing - syntax): ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'){0,29} {System.out.println("IDENTIFIER FOUND.");} ; No errors in code generation, but compilation failed due to a line in the generated code that was simply: 0,29 Obviously antlr is