antlr

ANTLRWorks 1.4.3 can't properly read extended-ASCII characters

与世无争的帅哥 提交于 2020-01-04 04:11:08
问题 I'm working on a fairly standard compiler project for which I picked ANTLR as the parser-generator. While updating an existing grammar from v2 to v3 I noticed that ANTLRWorks, the official IDE for ANTLR, wasn't displaying any of the extended-ASCII characters in the file properly. Even after using Notepad++ to convert the file to UTF8 from ASCII did it still display those characters as squares. In Notepad++ they display fine. Since this glitch means that ANTLRWorks mauls the file when I save

Partial grammar for counting class count

社会主义新天地 提交于 2020-01-04 02:27:18
问题 I need to count the number of classes in correct C# source file. I wrote the following grammar: grammar CSharpClassGrammar; options { language=CSharp2; } @parser::namespace { CSharpClassGrammar.Generated } @lexer::namespace { CSharpClassGrammar.Generated } @header { using System; using System.Collections.Generic; } @members { private List<string> _classCollector = new List<string>(); public List<string> ClassCollector { get { return _classCollector; } } } /*-----------------------------------

C++ Code insertion using antlr and the line directive

拥有回忆 提交于 2020-01-03 17:16:13
问题 I am using antlr to translate a custom language to C++ code. In this language, user can embed C++ code snippets between $code...$endcode directives, that gets inserted into the translated C++code as-is. I have the following problem: When there is an error in the code snippet I would like the compiler to point to the source file rather than the translated C++ code. I tried using line directives as follows, but it didn't work: "foo.custom_laguage" 1 $code 2 ...some c++ code... 3 $endcode gets

C++ Code insertion using antlr and the line directive

倾然丶 夕夏残阳落幕 提交于 2020-01-03 17:16:02
问题 I am using antlr to translate a custom language to C++ code. In this language, user can embed C++ code snippets between $code...$endcode directives, that gets inserted into the translated C++code as-is. I have the following problem: When there is an error in the code snippet I would like the compiler to point to the source file rather than the translated C++ code. I tried using line directives as follows, but it didn't work: "foo.custom_laguage" 1 $code 2 ...some c++ code... 3 $endcode gets

Antlr: Simplest way to recognize dates and numbers?

本秂侑毒 提交于 2020-01-03 11:59:10
问题 What is the simplest (shortest, fewest rules, and no warnings) way to parse both valid dates and numbers in the same grammar? My problem is that a lexer rule to match a valid month (1-12) will match any occurrence of 1-12. So if I just want to match a number, I need a parse rule like: number: (MONTH|INT); It only gets more complex when I add lexer rules for day and year. I want a parse rule for date like this: date: month '/' day ( '/' year )? -> ^('DATE' year month day); I don't care if

How to profile an Antlr grammar

China☆狼群 提交于 2020-01-03 08:29:13
问题 I have an Antlr grammar that is currently about 1200 lines. It parses the language that I want, but for at least one construct it is prohibitively slow even for smaller input files. The execution time seems to be growing exponentially for each added element of the construct. I want to know if there are any good guidelines for debugging/profiling such performance problems. I have already tried with VisualVM and that gave be the name of the two methods closureCheckingStopState and closure_, but

What's the relationshiop between Xtext and ANTLR?

拥有回忆 提交于 2020-01-03 08:09:05
问题 I heard that Xtext ultimately uses ANTLR but their grammar specification files have somewhat different formats. So what's the relationship between the two? 回答1: Xtext relies on the Antlr parser generator for the parsing of input files. On top of that the framework provides lot's of added value such as strongly typed ASTs, abstractions for linking and static analysis as well as IDE integration for Eclipse. For that purpose, Xtext generates two Antlr grammars. One for the production parsing

ANTLR API issue ; example + workaround provided ; explanation required

喜夏-厌秋 提交于 2020-01-02 07:06:39
问题 I created the following Lexer using ANTLRWorks. ( See also http://bkiers.blogspot.com/2011/03/2-introduction-to-antlr.html#intro ) // CSVLexer.g lexer grammar CSVLexer; @lexer::header { package graphica.parsers; } Comma : ',' ; LineBreak : '\r'? '\n' | '\r' ; SimpleValue : ~(',' | '\r' | '\n' | '"')+ ; QuotedValue : '"' ('""' | ~'"')* '"' ; I used the following Java class to test the Lexer. /** * * @author Nilo */ import org.antlr.runtime.*; public class CSVLexerTest { public static void main

'IDENTIFIER' rule also consumes keyword in ANTLR Lexer grammar

扶醉桌前 提交于 2020-01-02 05:24:07
问题 While working on Antlr 3.5 grammar for Java parsing noticed that ' IDENTIFIER ' rule consumes few Keywords in ANTLR Lexer grammar. The Lexer grammar is lexer grammar JavaLexer; options { //k=8; language=Java; filter=true; //backtrack=true; } @lexer::header { package java; } @lexer::members { public ArrayList<String> keywordsList = new ArrayList<String>(); } V_DECLARATION : ( ((MODIFIERS)=>tok1=MODIFIERS WS+)? tok2=TYPE WS+ var=V_DECLARATOR WS* ) {...}; fragment V_DECLARATOR : ( tok=IDENTIFIER

ANTLR parser hanging at proxy.handshake call

元气小坏坏 提交于 2020-01-02 05:14:18
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new