antlr

Ignore some part of input when parsing with ANTLR

泪湿孤枕 提交于 2019-12-12 09:02:27
问题 I'm trying to parse a language by ANTLR (ANTLRWorks-3.5.2). The goal is to enter complete input but Antlr gives a parse tree of defined parts in grammar and ignore the rest of inputs, for example this is my grammar : grammar asap; project : '/begin PROJECT' name module+ '/end PROJECT'; module : '/begin MODULE'name '/end MODULE'; name : IDENT ; IDENT : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|':'|'-')*; Given input: /begin PROJECT HybridSailboat_2 /begin MODULE engine /begin A2ML

How can I get Lexer and Parser with ANTLR for C#?

随声附和 提交于 2019-12-12 08:55:23
问题 Seems ANTLR support C# language but I dont know how I can generate related class. I searched and saw exists an Extention for Visual Studio but I does not support 2015 so How I can generate Lexer and Parser for C# with ANTLR manually ? 回答1: No need for integration with visual studio. Download the jar file here: http://www.antlr.org/download/antlr-runtime-4.5.1.jar Save it to C:\Test Add the jar to your classpath: Using System Properties dialog > Environment variables > Create or append to

antlr4: how to know which alternative is chosen given a context

微笑、不失礼 提交于 2019-12-12 08:49:57
问题 Assume there is a rule about 'type'. It is either a predefined type (referred by IDENTIFIER) or a typeDescriptor. type : IDENTIFIER | typeDescriptor ; In my program, I have got an instance of typeContext 'ctx'. How do I know if the path IDENTIFIER is chosen, or typeDescriptor is chosen. I recognise one way which is to test ctx.IDENTIFIER() == null and ctx.typeDescriptor() == null . But it seems not working very well when there are a lot more alternatives. Is there a way to return an index to

antlr global rule scope declaration vs @members declaration

人走茶凉 提交于 2019-12-12 08:34:30
问题 Which one would you prefer to declare a variable in which case, global scope or @members declaration? It seems to me that they can serve for same purpose? UPDATE here is a grammar to explain what i mean. grammar GlobalVsScope; scope global{ int i; } @lexer::header{package org.inanme.antlr;} @parser::header{package org.inanme.antlr;} @parser::members { int j; } start scope global; @init{ System.out.println($global::i); System.out.println(j); }:R EOF; R:'which one'; 回答1: Note that besides

Unparse AST < O(exp(n))?

落爺英雄遲暮 提交于 2019-12-12 08:23:50
问题 Abstract problem description: The way I see it, unparsing means to create a token stream from an AST, which when parsed again produces an equal AST. So parse(unparse(AST)) = AST holds. This is the equal to finding a valid parse tree which would produce the same AST. The language is described by a context free S-attributed grammar using a eBNF variant. So the unparser has to find a valid 'path' through the traversed nodes in which all grammar constraints hold. This bascially means to find a

Generate EBNF from ANTLR

早过忘川 提交于 2019-12-12 08:11:08
问题 Anybody know of a tool, that generates EBNF from ANTLR? ANTLR is already close to EBNF, but for documentation purpose I would like to have a clean EBNF description (without the Code in between). With antlrworks and this its already nice to get the syntax diagrams: java -cp antlrworks-1.1.4.jar org.antlr.works.Console -f yql.g -o output/ -sd eps but it would like to have a bare textual description, preferable text, tex, html, xml, or similar. 回答1: I have an online tool that converts foreign

EBNF grammar to ANTLR3?

这一生的挚爱 提交于 2019-12-12 05:50:01
问题 I have this EBNF grammar for the Jass scripting language. What needs to be done to convert it to work with ANTLR 3.5? Furthermore, are there any sort of tools available to aid me in doing so? //---------------------------------------------------------------------- // Global Declarations //---------------------------------------------------------------------- program ::= file+ file ::= newline? ( declr newline )* func* declr ::= typedef | globals | native_func typedef ::= 'type' id 'extends' (

Initialising my Lexer throws an error in Antlr4

醉酒当歌 提交于 2019-12-12 05:30:06
问题 Hi Team, I'm new to Antlr and I have spent 4 days trying to learn, install, run tutorials and integrate with my IDE. :( I can run this [tutorial][1] in the Terminal successfully. My goal now is to run the same tutorial in Netbeans with AntlrWorks2 I have cannibalised the Main from [Here][2]. The code compiles, but when I run I get an "java.lang.ExceptionInInitializerError" from init of the Lexer. 1: http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4 2: http://www.certpal

ANTLR recognize single character

筅森魡賤 提交于 2019-12-12 04:47:34
问题 I'm pretty sure this isn't possible, but I want to ask just in case. I have the common ID token definition: ID: LETTER (LETTER | DIG)*; The problem is that in the grammar I need to parse, there are some instructions in which you have a single character as operand, like: a + 4 but ab + 4 is not possible. So I can't write a rule like: sum: (INT | LETTER) ('+' (INT | LETTER))* Because the lexer will consider 'a' as an ID, due to the higher priority of ID. (And I can't change that priority

antlr grammar avoiding angle brackets

北城以北 提交于 2019-12-12 03:34:09
问题 In this question I asked about extracting tags from arbitrary text. The solution provided worked well, but there's one edge case I'd like to handle. To recap, I'm parsing arbitrary user-entered text and would like to have any occurrence of < or > to conform to valid tag syntax. Where an angle bracket isn't part of a valid tag, it should be escaped as < or > . The syntax I'm looking for is <foo#123> where foo is text from a fixed list of entries and 123 is a number [0-9]+ . The parser: parser