antlr

Serialization of ANTLR ParseTree

允我心安 提交于 2021-01-28 05:41:17
问题 I have a generated grammar that does two things: Check the syntax of a domain specific language Evaluate input against that domain specific language These two functions are separate, lets call them validate() and evaluate(). The validate() function builds the tree from a String input while ensuring it meets the requirements of the BNF for the language. The evaluate() function plugs in values to that tree to get a result (usually true or false). What the code is currently doing is running

ANTLR 4 - Tree pattern matching

夙愿已清 提交于 2021-01-28 02:02:14
问题 I am trying to understand parse tree matching in ANTLR 4, so for that I have the following java code: package sampleCodes; public class fruits { public static void main(String[] args){ int a = 10; System.out.println(a); } } I am using ANTLR 4 to create a parse tree of this code. Now, I want to use tree pattern matching function to find "int a = 10;". There is a doc on GitHub: https://github.com/antlr/antlr4/blob/master/doc/tree-matching.md which explains this(something like this) by an

Antlr generated classes access modifier to internal

我只是一个虾纸丫 提交于 2021-01-27 04:18:33
问题 I am building a library which contains certain parsers. These parsers are internally built with ANTLR4. Since the generated classes are all public, users of my library are able to see all the classes they do not need to see. Also the Sandcastle documentation contains all these classes. Is there any way I can tell Antlr to make the generated classes internal instead of public? 回答1: Actually, it's relatively easy to do. Internally, ANTLR uses StringTemplate files to generate code for each of

Antlr generated classes access modifier to internal

纵饮孤独 提交于 2021-01-27 04:18:32
问题 I am building a library which contains certain parsers. These parsers are internally built with ANTLR4. Since the generated classes are all public, users of my library are able to see all the classes they do not need to see. Also the Sandcastle documentation contains all these classes. Is there any way I can tell Antlr to make the generated classes internal instead of public? 回答1: Actually, it's relatively easy to do. Internally, ANTLR uses StringTemplate files to generate code for each of

Django REST framework--序列化

左心房为你撑大大i 提交于 2021-01-23 05:19:35
Django REST framework--序列化 基础准备工作 创建项目添加应用 (venv) lee@lee:~/PycharmProjects/Djdemo/ djdemo$ python manage.py startapp snippets (venv) lee@lee: ~/PycharmProjects/Djdemo/djdemo$ 项目目录结构 (venv) lee@lee:~/PycharmProjects/Djdemo/djdemo$ tree -L 2 . ├── djdemo │ ├── __init__ .py │ ├── __pycache__ │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── field_options │ ├── admin.py │ ├── apps.py │ ├── __init__ .py │ ├── migrations │ ├── models.py │ ├── __pycache__ │ ├── tests.py │ └── views.py ├── manage.py ├── many_to_many │ ├── admin.py │ ├── apps.py │ ├── __init__ .py │ ├── migrations │ ├── models.py │ ├─

ANTLR4 mutually left-recursive error when parsing

非 Y 不嫁゛ 提交于 2021-01-21 12:10:06
问题 I have this ANTLR 4 grammar: constantFixedExpresion : term (('+'|'-') term)+; term : factor (('*'|'//'|'REM')factor)+; factor : ('+'|'-')* ( wholeNumberConstant | constantFixedExpresion | 'TOFIXED' (stringConstant | bitCodeConstant) | identifier) ('FIT'constantFixedExpresion)*; I get the following error: error(119): LanguageA.g4::: The following sets of rules are mutually left-recursive [constantFixedExpresion, factor, term] I tried so many ways but can't fix it. What is the problem and how

ANTLR4 mutually left-recursive error when parsing

穿精又带淫゛_ 提交于 2021-01-21 12:08:13
问题 I have this ANTLR 4 grammar: constantFixedExpresion : term (('+'|'-') term)+; term : factor (('*'|'//'|'REM')factor)+; factor : ('+'|'-')* ( wholeNumberConstant | constantFixedExpresion | 'TOFIXED' (stringConstant | bitCodeConstant) | identifier) ('FIT'constantFixedExpresion)*; I get the following error: error(119): LanguageA.g4::: The following sets of rules are mutually left-recursive [constantFixedExpresion, factor, term] I tried so many ways but can't fix it. What is the problem and how

从0开始搭建数据仓库(2):产品经理如何“玩转”Hive SQL

自闭症网瘾萝莉.ら 提交于 2021-01-16 15:03:07
作者介绍 莲石东路@乌森 心之所向,***成长。从底层架构到应用实战,聊聊炼数成金背后的故事。 持续更新数据治理、数据科学、数据可视化、空间计算系列文章。 01 前言 公司新入职了的产品经理小美因为业务需要,想搭一个数据大屏方便自己查看数据。她找开发小王申请了数仓权限,然后从技术中台里找到了数据大屏的工具,把自己平时查数据用的sql搬上去跑,结果总是报错。 小美找到了做数据产品经理的师兄小帅看了看。 小帅:你这个查询有问题,业务系统的sql不能直接搬来用。 小美:我看长得差不多啊,除了多了个分区外,不都是sql吗? 小帅:你现在建的是Hive查询,Hive SQL虽说和SQL非常相似,但是一些细节上还是有区别的。 02 Hive SQL是什么? Hive是大数据领域常用的数据仓库组件,可以借助查询语言SQl将HDFS上存储的结构化文件映射成一张数据库表,并提供类SQL查询功能。Hive-SQL就是这个”类SQL查询功能”。Hive-SQL与SQL基本上一样,因为当初的设计目的,就是让会SQL不会编程MapReduce的也能完成处理数据工作。 【拓展】Hive-SQL是如何转化为MapReduce任务的呢?整个编译过程分为六个阶段: 1) Antlr定义SQL的语法规则,完成SQL词法,语法解析,将SQL转化为抽象语法树AST Tree 2) 遍历AST Tree

How to make ANTLR consume all available elements using recursion?

孤者浪人 提交于 2021-01-07 02:28:26
问题 This is my grammar: grammar test; text: foo EOF; foo: 'X' | '(' foo ')' | foo '!' | foo tail ; tail: (' ' foo)+; This is the input it perfectly parses: X (X! (X)! (X X X)!!!) X However, the output tree has too many tail elements, as I explained earlier here. Is it possible to fix this? 回答1: Thanks to @kaby76, the solution is found: foo: 'X' tail? | '(' foo ')' tail? | foo '!' tail? ; tail: ( ' ' 'X' | ' ' '(' foo ')' | ' ' foo '!' )+ ; 来源: https://stackoverflow.com/questions/64635366/how-to

ANTLR VS FLEX&BISON

删除回忆录丶 提交于 2020-12-29 15:51:49
1. ANTLR可以一站式的解决词法与语法解析器的生成。 FLEX&BISON需要配合使用,一个实现词法解析器,一个实现语法解析器。 2. ANTLR通过在文法文件中的设置,可以生成多个语言代码。 options {language=Cpp;} options {language=CSharp;} options {language=Java;} options {language=Python3;} FLEX&BISON只能生成C代码。 3. ANTLR可以生成语法解析树的图形化表示,方便开发与测试。 FLEX&BISON没有。 4. ANTLR支持多种IDE的协同开发插件。 FLEX&BISON没有,是纯粹的命令行程序。 5. 语义代码,ANTLR有多种方式支持,可以在文法文件中嵌入代码,也可以使用其它方法(我估计是listener,visitor, channel这些方式,还没搞明白) FLEX&BISON只有一种方式,将用户自己的语义代码嵌入式文法文件中。 来源: oschina 链接: https://my.oschina.net/u/4406457/blog/4868286