Examples of LL(1), LR(1), LR(0), LALR(1) grammars?

Is there a good resource online with a collection of grammars for some of the major parsing algorithms (LL(1), LR(1), LR(0), LALR(1))? I’ve found many individual grammars that fall into these families, but I know of no good resource where someone has written up a large set of example grammars. Does anyone know of such … Read more

If/else statements in ANTLR using listeners

I’m creating a simple programming language for a school project. I’m using ANTLR 4 to generate a lexer and a parser from my grammar. Until now, I have been using ANTLRs listener pattern to apply the actual functionality of the programming language. Now I would like to implement if/else statements but I’m not sure that … Read more

Using ANTLR 3.3?

I’m trying to get started with ANTLR and C# but I’m finding it extraordinarily difficult due to the lack of documentation/tutorials. I’ve found a couple half-hearted tutorials for older versions, but it seems there have been some major changes to the API since. Can anyone give me a simple example of how to create a … Read more

How to create AST with ANTLR4?

I’ve been searching A LOT about this and I couldn’t find anything useful that REALLY helps me build an AST. I already know that ANTLR4 doesn’t build AST like ANTLR3 used to do. Everyone say: “Hey, use visitors!”, but I couldn’t find any example or more detailed explanation on HOW can I do this… I … Read more

What is a ‘semantic predicate’ in ANTLR?

What is a semantic predicate in ANTLR? Answer ANTLR 4 For predicates in ANTLR 4, checkout these stackoverflow Q&A’s: Syntax of semantic predicates in Antlr4 Semantic predicates in ANTLR4? ANTLR 3 A semantic predicate is a way to enforce extra (semantic) rules upon grammar actions using plain code. There are 3 types of semantic predicates: … Read more

What does “fragment” mean in ANTLR?

What does fragment mean in ANTLR? I’ve seen both rules: fragment DIGIT : ‘0’..’9′; and DIGIT : ‘0’..’9′; What is the difference? Answer A fragment is somewhat akin to an inline function: It makes the grammar more readable and easier to maintain. A fragment will never be counted as a token, it only serves to … Read more

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

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 8 years ago. Improve this question I’ve used lex and yacc (more usually bison) in the past for various projects, usually translators … Read more