antlr

If/else statements in ANTLR using listeners

ε祈祈猫儿з 提交于 2019-11-26 03:26:06
问题 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 these can actually be implemented when using the listener pattern as ANTLR decides in which order to traverse the parse tree when using listeners and I imagine that the

lexers vs parsers

扶醉桌前 提交于 2019-11-26 02:39:07
问题 Are lexers and parsers really that different in theory? It seems fashionable to hate regular expressions: coding horror, another blog post. However, popular lexing based tools: pygments, geshi, or prettify, all use regular expressions. They seem to lex anything... When is lexing enough, when do you need EBNF? Has anyone used the tokens produced by these lexers with bison or antlr parser generators? 回答1: What parsers and lexers have in common: They read symbols of some alphabet from their

How to create AST with ANTLR4?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 01:35:34
问题 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 have a grammar must like C, but with every commands written in Portuguese (portuga programming language). I can easily generate the parse tree using ANTLR4. My question is: What I need to do

ANTLR: Is there a simple example?

白昼怎懂夜的黑 提交于 2019-11-26 01:25:55
问题 I\'d like to get started with ANTLR, but after spending a few hours reviewing the examples at the antlr.org site, I still can\'t get a clear understanding of the grammar to Java process. Is there some simple example, something like a four-operations calculator implemented with ANTLR going through the parser definition and all the way to the Java source code? 回答1: Note : this answer is for ANTLR3 ! If you're looking for an ANTLR4 example, then this Q&A demonstrates how to create a simple

How to output the AST built using ANTLR?

∥☆過路亽.° 提交于 2019-11-26 00:33:09
问题 I\'m making a static analyzer for C. I have done the lexer and parser using ANTLR in which generates Java code. Does ANTLR build the AST for us automatically by options {output=AST;} ? Or do I have to make the tree myself? If it does, then how to spit out the nodes on that AST? I am currently thinking that the nodes on that AST will be used for making SSA, followed by data flow analysis in order to make the static analyzer. Am I on the right path? 回答1: Raphael wrote: Does antlr build the AST

What is a 'semantic predicate' in ANTLR?

▼魔方 西西 提交于 2019-11-26 00:11:36
问题 What is a semantic predicate in ANTLR? 回答1: ANTLR 4 For predicates in ANTLR 4, checkout these stack overflow 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: validating semantic predicates; gated semantic predicates; disambiguating semantic predicates. Example grammar Let's say you have a block of text consisting