antlr

How to use the grammar files generated by ANTLR?

旧时模样 提交于 2019-12-21 14:58:23
问题 I think this is a stupid question, but I'm just starting out with ANTLR. I put together the "SimpleCalc" grammar from their tutorials, and generated it with C as the target language. I got SimpleCalcParser.c/.h and SimpleCalcLexer.c/.h as the output, and I was able to compile these and build successfuly. But now, how do I actually use the code that's generated? I'm having trouble finding anything in the docs that's helpful. Below is my main() function. This is also from the tutorial. #include

C# ANTLR grammar?

纵然是瞬间 提交于 2019-12-21 09:09:54
问题 I'm looking for turn-key ANTLR grammar for C# that generates a usable Abstract Syntax Tree (AST) and is either back-end language agnostic or targets C#, C, C++ or D. It doesn't need to support error reporting. P.S. I'm not willing to do hardly any fix-up as the alternative is not very hard. 回答1: This may be waaaay too late, but you can get a C# 4 grammar. 回答2: Here's a C# grammar link, as well as an overview of C# and ANTLR. There are others for the other languages you mentioned here. 回答3:

When do we use ANTLR

假如想象 提交于 2019-12-21 06:48:39
问题 Can anyone please guide me the purpose of using ANTLR dlls in a ASP.Net, C# project. I just noticed antlr.runtime , Antlr3.Runtime , Antlr3.Utlility assemblies being referenced in some project. Will be great if can cite some real world examples or any link to a web page will be useful. 回答1: You would need these dll's if you are parsing any text at runtime using an antlr grammar. Typically there are two steps. 1) run the java antlr parser over your .g files to generate a C# lexer, C# grammar

Is it advisable to use tokens for the purpose of syntax highlighting?

℡╲_俬逩灬. 提交于 2019-12-21 05:57:36
问题 I'm trying to implement syntax highlighting in C# on Android, using Xamarin. I'm using the ANTLR v4 library for C# to achieve this. My code, which is currently syntax highlighting Java with this grammar, does not attempt to build a parse tree and use the visitor pattern. Instead, I simply convert the input into a list of tokens: private static IList<IToken> Tokenize(string text) { var inputStream = new AntlrInputStream(text); var lexer = new JavaLexer(inputStream); var tokenStream = new

Examples / tutorials for usage of javax.lang.model or ANTLR JavaParser to get information on Java Source Code

Deadly 提交于 2019-12-21 05:25:10
问题 I would like to create an automatic Flowchart-like visualization to simple Java Logic, for this I need to parse Java Source code, I have 2 candidates, ANTLR and javax.lang.model of Java 6. Neither are easy. I have yet to find a single working example that will be even remotely close to what I want to achieve. I want to find simple variable declarations, assignments, and flows (if, for, switch, boolean conditions etc) Is there a simple example or tutorial for either of these? I found very few

How can I modify the text of tokens in a CommonTokenStream with ANTLR?

自作多情 提交于 2019-12-21 02:00:58
问题 I'm trying to learn ANTLR and at the same time use it for a current project. I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is being broken up into the appropriate tokens. Now, I would like to be able to modify the text of certain tokens in this stream, and display the now modified source code. For example I've tried: import org.antlr.runtime.*; import java.util.*; public

Is the ANTLR parser generator best for a C++ app with constrained memory?

喜你入骨 提交于 2019-12-20 14:11:36
问题 I'm looking for a good parser generator that I can use to read a custom text-file format in our large commercial app. Currently this particular file format is read with a handmade recursive parser but the format has grown and complexified to the point where that approach has become unmanageable. It seems like the ultimate solution would be to build a proper grammar for this format and then use a real parser generator like yacc to read it, but I'm having trouble deciding which such generator

Why does not ANTLR4 match “of” as a word and “,” as punctuation?

自闭症网瘾萝莉.ら 提交于 2019-12-20 06:38:44
问题 I have a Hello.g4 grammar file with a grammar definition: definition : wordsWithPunctuation ; words : (WORD)+ ; wordsWithPunctuation : word ( word | punctuation word | word punctuation | '(' wordsWithPunctuation ')' | '"' wordsWithPunctuation '"' )* ; NUMBER : [0-9]+ ; word : WORD ; WORD : [A-Za-z-]+ ; punctuation : PUNCTUATION ; PUNCTUATION : (','|'!'|'?'|'\''|':'|'.') ; WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines Now, if I am trying to build a parse tree from the following

Syntactic errors on optional rules in Antlr 4 doesn't work as expected

拥有回忆 提交于 2019-12-20 06:31:01
问题 I am using Antlr 4.7.2. I am trying to implement an "if else" statement: Main problem is that optional rule is not being included on ParseTree, for this reason I think I am not getting the syntax's errors on that optional rule. Ones of my current grammar definition are: prog : stat+ ; stat : func_declaration #rFuncDeclStat | if_stat #rIfStat | while_stat #rWhileStat | for_stat #rForStat | 'return' expr? STAT_END #rReturnStat | LET ID ('=' expr)? STAT_END #rVarDeclStat | var_reference '=' expr

ANTLR get and split lexer content

和自甴很熟 提交于 2019-12-20 05:32:08
问题 first, sorry about my english, i still learning. I writing Python module for my framework, which parsing CSS files. I try regex, ply (python lexer and parser), but i found myself in ANTLR. First try, i need to parse comments from CSS file. This is my CSS string to parse: /*test*/ /* test1 /* /*test2/*nested*/comment/* I know that CSS doesn't allow nested comments, but i need it in my framework. I wrote simple ANTLR grammar: grammar CSS; options { language = Python; } styleSheet : comments EOF