antlr

How do I lex this input?

六月ゝ 毕业季﹏ 提交于 2019-12-22 10:44:21
问题 I currently have a working, simple language implemented in Java using ANTLR. What I want to do is embed it in plain text, in a similar fashion to PHP. For example: Lorem ipsum dolor sit amet <% print('consectetur adipiscing elit'); %> Phasellus volutpat dignissim sapien. I anticipate that the resulting token stream would look something like: CDATA OPEN PRINT OPAREN APOS STRING APOS CPAREN SEMI CLOSE CDATA How can I achieve this, or is there a better way? There is no restriction on what might

Parsing SQL Query and pull out column name and Table name

橙三吉。 提交于 2019-12-22 10:18:59
问题 I have a Query Script like this: SELECT View1.OrderDate,View1.Email,SUM(View1.TotalPayments) FROM dbo.View1 WHERE (View1.OrderStatus = 'Completed') GROUP BY View1.OrderDate,View1.Email HAVING (SUM(View1.TotalPayments) > 75); Is there any approach that we can pull some key information out from SQL query? such as table name and column name ,I have 2 question: I did search I found some parser such as ANTLR , but I could not find documentation that explain the using of this parser in C# language.

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

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

ANTLR JavaScript Target

北城余情 提交于 2019-12-22 03:56:28
问题 I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it in my web browser. However, I have not been able to locate any good documentation on how to go about doing this. I am using eclipse with ANTLR IDE, and when i specify the language as JavaScript, I get the following errors. Multiple markers at this line (10): internal error: group JavaScript does not satisfy interface

What is wrong with this grammar? (ANTLRWorks 1.4)

感情迁移 提交于 2019-12-21 22:15:06
问题 I have the following code written in ANTLRWorks 1.4 grammar hmm; s : (put_a_in_b)|(put_out_a)|(drop_kick)|(drop_a)|(put_on_a); put_a_in_b : (PUT_SYN)(ID)(IN_SYN)(ID); put_out_a : (PUT2_SYN)(OUT_SYN)(ID) | (E1)(ID); drop_kick : ('drop')('kick')(ID); drop_a : (DROP_SYN)(ID); put_on_a : (E2)(ID); PUT_SYN : 'put' | 'place' | 'drop'; PUT2_SYN : 'put' | 'douse'; IN_SYN : 'in' | 'into' | 'inside' | 'within'; OUT_SYN : 'out'; E1 : 'extinguish'|'douse'; DROP_SYN : 'drop' | 'throw' | 'relinquish'; WS :

Interpreting custom language

戏子无情 提交于 2019-12-21 20:17:20
问题 I need to develop an application that will read and understand text file in which I'll find a custom language that describe a list of operations (ie cooking recipe). This language has not been defined yet, but it will probably take one of the following shape : C++ like code (This code is randomly generated, just for example purpose) : begin repeat(10) { bar(toto, 10, 1999, xxx); } result = foo(xxxx, 10); if(foo == ok) { ... } else { ... } end XML code (This code is randomly generated, just

How to parse a parenthesized hierarchy root?

a 夏天 提交于 2019-12-21 19:48:04
问题 I'm trying to parse values with ANTLR. Here's the relevant part of my grammar: root : IDENTIFIER | SELF | literal | constructor | call | indexer; hierarchy : root (SUB^ (IDENTIFIER | call | indexer))*; factor : hierarchy ((MULT^ | DIV^ | MODULO^) hierarchy)*; sum : factor ((PLUS^ | MINUS^) factor)*; comparison : sum (comparison_operator^ sum)*; value : comparison | '(' value ')'; I won't describe each token or rule since their name is quite explanatory of their role. This grammar works well

Converting Antlr syntax tree into useful objects

半腔热情 提交于 2019-12-21 17:52:23
问题 I'm currently pondering how best to take an AST generated using Antlr and convert it into useful objects which I can use in my program. The purpose of my grammar (apart from learning) is to create an executable (runtime interpretted) language. For example, how would I take an attribute sub-tree and have a specific Attribute class instanciated. E.g. The following code in my language: Print(message:"Hello stackoverflow") would product the following AST: My current line of thinking is that a

Parsing with incomplete grammars

点点圈 提交于 2019-12-21 17:14:43
问题 Are there any common solutions how to use incomplete grammars? In my case I just want to detect methods in Delphi (Pascal)-files, that means procedures and functions . The following first attempt is working methods : ( procedure | function | . )+ ; but is that a solution at all? Are there any better solutions? Is it possible to stop parsing with an action (e. g. after detecting implementation ). Does it make sense to use a preprocessor? And when yes - how? 回答1: If you're only looking for