antlr

Two basic ANTLR questions

走远了吗. 提交于 2019-12-06 03:51:24
问题 I'm trying to use ANTLR to take a simple grammar and produce assembly output. My language of choice in ANTLR is Python. Many tutorials seem very complicated or elaborate on things that aren't relevant to me; I only really need some very simple functionality. So I have two questions: 'Returning' values from one rule to another. So let's say I have a rule like: assignment: name=IDENTIFIER ASSIGNMENT expression; I can run Python code in {}s when this rule is recognised, and I can pass args to

Antlr Array Help

南楼画角 提交于 2019-12-06 03:13:38
Hey ive started to use Antlr with java and i wanted to know how i can store some values directly into a 2d array and return this array? i cant find any tutorials on this at all, all help is apperciated. Let's say you want to parse a flat text file containing numbers separated by spaces. You'd like to parse this into a 2d array of int 's where each line is a "row" in your array. The ANTLR grammar for such a "language" could look like: grammar Number; parse : line* EOF ; line : Number+ (LineBreak | EOF) ; Number : ('0'..'9')+ ; Space : (' ' | '\t') {skip();} ; LineBreak : '\r'? '\n' | '\r' ; Now

Status of Javascript in antlr 3.4 or 3.5 [closed]

大城市里の小女人 提交于 2019-12-06 03:03:22
What is the status of the JavaScript target in ANTLR 3.4 or 3.5? I have been looking online for an answer to this question but so far I have found nothing. I know that it was broken in v3.2 and then it was fixed in v3.3, but it's not listed in the ANTLR 3.4 release notes as a target that is consistent with ANTLR 3.4. I have a project in which I need to convert the Java target ANTLR grammar which I had previously written to JavaScript and I want to make sure that the JavaScript target is supported by ANTLR 3.4 or 3.5 before I proceed. Bart Kiers ANTLR 3.1 and 3.2 had some bugs w.r.t. generating

How to deal with list return values in ANTLR

北城以北 提交于 2019-12-06 02:58:40
问题 What is the correct way to solve this problem in ANTLR: I have a simple grammar rule, say for a list with an arbitrary number of elements. list : '[]' | '[' value (COMMA value)* ']' If I wanted to assign a return value for list, and have that value be the actual list of returned values from the production, what is the proper way to do it? The alternatives I'm entertaining are: create my own stack in the global scope to keep track of these lists Try to inspect the tree nodes below me and

String Template: make all variable declaration global

十年热恋 提交于 2019-12-06 02:17:00
I am trying to implement a translator using ANTLR+StringTemplate. I have a starting language that is java like and multiple destination language. I used the example: http://www.antlr.org/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate One of my destination language needs all variables to be declared globally. I wrote a grammar that recognizes variables, but i cannot find e way in my template for making a local variable to be declared globally. Of course if I would have just one translation I would be able to do it, but I have multiple translation and some of them have local

BibTex grammar for ANTLR

廉价感情. 提交于 2019-12-06 01:12:03
问题 I'm looking for a bibtex grammar in ANTLR to use in a hobby project. I don't want to spend my time for writing ANTLR grammar (this may take some time for me because it will involve a learning curve). So I'd appreciate for any pointers. Note: I've found bibtex grammars for bison and yacc but couldn't find any for antlr. Edit: As Bart pointed the I don't need to parse the preambles and tex in the quoted strings. 回答1: Here's a (very) rudimentary BibTex grammar that emits an AST (contrary to a

VBScript Partial Parser

£可爱£侵袭症+ 提交于 2019-12-06 00:36:45
问题 I am trying to create a VBScript parser. I was wondering what is the best way to go about it. I have researched and researched. The most popular way seems to be going for something like Gold Parser or ANTLR. The feature I want to implement is to do dynamic checking of Syntax Errors in VBScript. I do not want to compile the entire VBS every time some text changes. How do I go about doing that? I tried to use Gold Parser, but i assume there is no incremental way of doing parsing through it,

Antlr Extraneous Input

混江龙づ霸主 提交于 2019-12-06 00:23:59
问题 I have a grammar file BoardFile.g4 that has (relevant parts only): grammar Board; //Tokens GADGET : 'squareBumper' | 'circleBumper' | 'triangleBumper' | 'leftFlipper' | 'rightFlipper' | 'absorber' | 'portal' ; NAME : [A-Za-z_][A-Za-z_0-9]* ; INT : [0-9]+ ; FLOAT : '-'?[0-9]+('.'[0-9]+)? ; COMMENT : '#' ~( '\r' | '\n' )*; WHITESPACE : [ \t\r\n]+ -> skip ; KEY : [a-z] | [0-9] | 'shift' | 'ctrl' | 'alt' | 'meta' | 'space' | 'left' | 'right' | 'up' | 'down' | 'minus' | 'equals' | 'backspace' |

Parsing SQL Query and pull out column name and Table name

给你一囗甜甜゛ 提交于 2019-12-06 00:09:52
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. Is there any way we can use Entity Frame Work to parsing sql query? My queries are fully dynamic and

How do I lex this input?

浪尽此生 提交于 2019-12-05 23:34:32
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 be outside the <% block. I assumed something like <% print('%>'); %> , as per Michael Mrozek's answer,