antlr

How to write Antlr rules in a non-recursive way?

百般思念 提交于 2020-02-25 22:44:51
问题 I have the following the expressions I need to parse and(true, false) or(true, false, true) not(or(true, false, true)) and(and(true, false), false) or(or(true, false, true), true) so far I have the following grammar expr : orExpr ; orExpr : OR '(' andExpr (',' andExpr)+ ')' | andExpr ; andExpr : AND '(' equalityExpr (',' equalityExpr)+ ')' | equalityExpr ; equalityExpr : comparison ((EQUALS | NOT_EQUALS) comparison)* ; comparison : notExpr ((GREATER_THAN_EQUALS | LESS_THAN_EQUALS | GREATER

ANTLR 介绍

人盡茶涼 提交于 2020-02-08 02:47:30
ANTLR 介绍 作者: Terence Parr 译者:Nicholas @ NirvanaStudio 原文出处: http://www.cs.usfca.edu/~parrt/course/652/lectures/antlr.html 介绍 自1980年以来我手工编写了很多识别程序(recognizer)和翻译程序(translator)但最终我感到很恶心并且尝试将这个过程自动化:来源于我的座右铭: “ Why program by hand in five days what you can spend five years of your life automating. “ 手工编写过很多程序之后你就可以发现一些共性,并且这些共性可以合理地格式化并且自动生成。我当时对 yacc 不是很熟悉但是想要一些东西去代替我原本需要手工 编码的工作。ANTLR就是这个最终的结果(实际上原来它叫做PCCTS)。我现在已经为之工作了十年了。 ANTLR , ANother Tool for Language Recognition, 是一个可以接受含有语法描述的语言描述符并且生成程序能够识别这些语言所产生的句子。作为一个翻译程序的 一部分,你可以给你的语法附上简单的操作符和行为并且告诉ANTLR如何构造AST并且如何输出它们。ANTLR知道如何使用Java,C++,C

ANTLR 介绍

删除回忆录丶 提交于 2020-02-08 02:44:50
作者: Terence Parr 译者:Nicholas @ NirvanaStudio 介绍 自1980年以来我手工编写了很多识别程序(recognizer)和翻译程序(translator)但最终我感到很恶心并且尝试将这个过程自动化:来源于我的座右铭: " Why program by hand in five days what you can spend five years of your life automating. " 手工编写过很多程序之后你就可以发现一些共性,并且这些共性可以合理地格式化并且自动生成。我当时对 yacc 不是很熟悉但是想要一些东西去代替我原本需要手工 编码的工作。ANTLR就是这个最终的结果(实际上原来它叫做PCCTS)。我现在已经为之工作了十年了。 ANTLR , ANother Tool for Language Recognition, 是一个可以接受含有语法描述的语言描述符并且生成程序能够识别这些语言所产生的句子。作为一个翻译程序的 一部分,你可以给你的语法附上简单的操作符和行为并且告诉ANTLR如何构造AST并且如何输出它们。ANTLR知道如何使用Java,C++,C#或者Python来生成它们。 ANTLR知道如何构造识别程序并且将语法结构应用到三种不同的输入上:(i) 字符流, (ii) 标记(token)流,(iii)

Token return values in ANTLR 3 C

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-02 02:59:33
问题 I'm new to ANTLR, and I'm attempting to write a simple parser using C language target (antler3C). The grammar is simple enough that I'd like to have each rule return a value, eg: number returns [long value] : ( INT {$value = $INT.ivalue;} | HEX {$value = $HEX.hvalue;} ) ; HEX returns [long hvalue] : '0' 'x' ('0'..'9'|'a'..'f'|'A'..'F')+ {$hvalue = strtol((char*)$text->chars,NULL,16);} ; INT returns [long ivalue] : '0'..'9'+ {$ivalue = strtol((char*)$text->chars,NULL,10);} ; Each rule collects

AS3 Grammar: Most accurate

房东的猫 提交于 2020-01-31 05:12:19
问题 I'm looking for an accurate AS3 grammar (format in not an issue, but I presume ANTLR will feature the most) to use for a practice grammar I'm making. What is the most accurate grammar available for AS3? 回答1: I think this one is pretty accurate if you are looking for an ANTLR grammar: AS3.g This grammar has been originally developed a couple of years ago by Martin Schnable and then extended for the Meta-AS project. There are of course other ActionScript 3 parsers available as well, but they do

Uncaught ReferenceError: ___ is not defined - typescript

有些话、适合烂在心里 提交于 2020-01-25 20:53:08
问题 I am getting "Uncaught ReferenceError: ___ is not defined" in typescript at runtime even though the class is defined in the same file and exported. Please guide. Update : I was able to fix this issue by changing the order of exported class. That means I defined ExpressionContext class before it's used. It's a dirty way since it's a generated code and I don't want to touch it. I would like to understand why it's failing. 来源: https://stackoverflow.com/questions/43765160/uncaught-referenceerror

Gradle ANTLR4 plugin in Android app: build fails

妖精的绣舞 提交于 2020-01-25 12:37:27
问题 I spent few days spotting this issue, and I'd like to post my finding here. I'm building an Android app with several modules, one of them using ANTLR plugin. While the module with ANTLR builds OK, as it is a Java module, the android module fails in transformClassesWithDexForDebug task: * What went wrong: Execution failed for task ':Android:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util

Code Editor using ANTLR

梦想与她 提交于 2020-01-25 11:20:46
问题 I'm in the process of writing a code editor for a custom language. We're using ANTLR for the lexer and parser, and CodeMirror for the editor framework (running in a browser). I can do some basic things like syntax coloring of keywords, as well as providing rudimentary code completion. What I'm finding is that the user is frequently in the middle of editing something, so the ANTLR parser is not very useful since the current input stream is not fully parseable (and often leads ANTLR down the

ANTLR Grammar Mutually Left Recursive

狂风中的少年 提交于 2020-01-24 01:08:11
问题 I do know that this question has been asked a lot of times. I am trying to build a grammar using ANTLR. Predicate : LOWERCASE | Predicate VarChars ; VarChars : LOWERCASE | UPPERCASE; fragment LOWERCASE : [a-z] ; fragment UPPERCASE : [A-Z] ; I am getting the following error :"The following sets of rules are mutually left-recursive [Predicate]" Please show me how this is fixed. How to remove the mutual left recursion in my antlr grammar. 回答1: Get rid of the recursive occurrence of "Predicate"

ANTLR学习

送分小仙女□ 提交于 2020-01-23 04:47:18
**ANTLR学习笔记一:概念理解 ** 一、什么是ANTLR。 ANTLR是ANother Tool for Language Recognition的缩写, 意为“另一种语言识别工具”,读作Antler。 它是一种解析器程序的代码生成器(作用类似于YACC), 使用LL(*)方法,即从输入字符串的左到右, 用候选项的最左符号匹配输入(即与所有以终结符开头的候选项匹配), 每次向前(右)看n个符号(好像计算机下棋那样)。 二、ANTLR的特点 ANTLR作为一种编译器的制作工具,具有很多有用的功能和特点。 使用语法(.g文件)作为输入,生成语言识别器的代码。 支持生成各种语言的代码(只需修改与实现语言相关的部分)。 自身用Java实现。 使用上下文无关语法。 (即语法的所有产生式/规则的左侧总是非终结符, 简单说就是,一个被识别的非终结符无论放在什么地方, 都可以用已有的方式推导) 语法基于EBNF(扩展的巴科斯范式)。 这意味着,在ANTLR中既可以使用BNF元语言符号 冒号(:)表示推导, 竖线(|)表示或, 也可以使用扩展的元语言符号如 星号(*)表示出现0次或以上。 问号(?)表示出现0次或1次。 加号(+)表示出现1次或以上。 关于EBNF更多介绍可以参考这里: http://hi.baidu.com/helloweenpad/blog/item