antlr

Why are antlr3 c# parser methods private?

我的梦境 提交于 2019-12-17 19:33:48
问题 I'm building a parser in antlr which compiles to a working java target. When I retarget for c#2 it produces a parser in which all of the parse methods are private but marked with a [GrammarRule("rulename")] attribute. What is the approved means to actually invoke the parser? I am using ANTLR 3.3 Nov 30, 2010 12:45:30 Thanks, Andy 回答1: Make at least one parser rule "public" like this: grammar T; options { language=CSharp2; } public parse : privateRule+ EOF ; privateRule : Token+ ; // ... You

Advantages of Antlr (versus say, lex/yacc/bison) [closed]

泄露秘密 提交于 2019-12-17 17:23:44
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I've used lex and yacc (more usually bison) in the past for various projects, usually translators (such as a subset of EDIF streamed into an EDA app). Additionally, I've had to support code based on lex/yacc grammars dating back decades. So I know my way around the tools,

Which Java oriented lexer parser for simple project (ANTLR, DIY, etc)

孤街醉人 提交于 2019-12-17 16:37:52
问题 I am working on a small text editor project and want to add basic syntax highlighting for a couple of languages (Java, XML..just to name a few). As a learning experience I wanted to add one of the popular or non popular Java lexer parser. What project do you recommend. Antlr is probably the most well known, but it seems pretty complex and heavy. Here are the option that I know of. Antlr Ragel (yes, it can generate Java source for processing input) Do it yourself (I guess I could write a

Can I add Antlr tokens at runtime?

痞子三分冷 提交于 2019-12-17 16:31:15
问题 I have a situation where my language contains some words that aren't known at build time but will be known at run time causing the need to constantly rebuild / redeploy the program to take into account new words. I was wandering if it was possible in Antlr generate some of the tokens from a config file? e.g In a simplified example if I have a rule rule : WORDS+; WORDS : 'abc'; And my language comes across 'bcd' at runntime, I would like to be able to modify a config file to define bcd as a

Antlr IDE in Eclipse doesn't work

时光怂恿深爱的人放手 提交于 2019-12-17 16:21:06
问题 I'm using Antlr v3 and java for a project and all goes well in AntlrWorks, but when I switch to Antlr IDE, the plugin for eclipse, the interpreter cannot match the sentence that I wrote, telling me mismatch. And it seems to me that it cannot recognize the list of words to skip that I've specified in on lexer. However it is the same that works perfectly in AntlrWorks. Any suggestions? I've set up the antlr buider in eclipse: Antlr Parser Generator v3.4 回答1: This may be a configuration issue. I

Why is .NET exception not caught by try/catch block?

自作多情 提交于 2019-12-17 15:42:09
问题 I'm working on a project using the ANTLR parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception

Semantic predicates in ANTLR4?

倖福魔咒の 提交于 2019-12-17 11:02:14
问题 How would you translate this portion of code written in ANTLR 3 into ANTLR 4? expr: (Identifier '.')=> (refIdentifier) | (Identifier '!')=> (refIdentifier) | (Identifier '=>')=> (lambdaExpression); I mean this kind of semantic predicate does not seem to exist now. What could I use Instead? 回答1: In ANTLR v4, there are no longer gated semantic predicates , { ... }?=> , and there are also no longer syntactic predicates , ( ... )=> , because the parsing algorithm used in v4 can resolve the

Build symbol table from grammar [closed]

依然范特西╮ 提交于 2019-12-17 07:54:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I am trying to build a symbol table from my grammar (done with antlr) by using eclipse. However I don't know by what to begin. I think I read somewhere that you would need the parser and lexer generated by antlr to do that. Does someone know an easy example so that I can

ANTR3 set the number of accepted characters for a token

五迷三道 提交于 2019-12-14 04:20:51
问题 I have to create a Lexer which will accept for example an integer only if it has a maximum of 8 digits. Is here an alternative to do it rather than just writing it like this? INTEGER : (DIG | DIG DIG | DIG DIG DIG | ...) 回答1: This can be done using a Gated Semantic Predicates like this: INTEGER @init{int n = 1;} : ({n <= 8}?=> DIGIT {n++;})+ ; fragment DIGIT : '0'..'9'; Details about this kind of predicate, see: What is a 'semantic predicate' in ANTLR? 来源: https://stackoverflow.com/questions

Traversal of tokens using ParserRuleContext in listener - ANTLR4

独自空忆成欢 提交于 2019-12-14 03:48:57
问题 While iterating over the tokens using a Listener, I would like to know how to use the ParserRuleContext to peek at the next token or the next few tokens in the token stream? In the code below I am trying to peek at all the tokens after the current token till the EOF: @Override public void enterSemicolon(JavaParser.SemicolonContext ctx) { Token tok, semiColon = ctx.getStart(); int currentIndex = semiColon.getStartIndex(); int reqInd = currentIndex+1; TokenSource tokSrc= semiColon