abstract-syntax-tree

ANTLR Visitor Class is returning null for Parse tree in C#

孤人 提交于 2020-07-23 08:23:06
问题 I am trying to build an AST using the visitor pattern on ANTLR Java Grammar (Java Grammar) in C# (.Net Core 3.1). I have created IJavaParserVisitor , JavaParserbaseVisitor , JavaLexer , and JavaParser file for grammar and created parse tree for java source file. But when I am trying to create AST using JavaParserBaseVisitor.Visit() I am getting null as a result. AntlrFileStream stream = new AntlrFileStream(file); ITokenSource lexer = new JavaLexer(stream); ITokenStream tokens = new

ANTLR Visitor Class is returning null for Parse tree in C#

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-23 08:22:10
问题 I am trying to build an AST using the visitor pattern on ANTLR Java Grammar (Java Grammar) in C# (.Net Core 3.1). I have created IJavaParserVisitor , JavaParserbaseVisitor , JavaLexer , and JavaParser file for grammar and created parse tree for java source file. But when I am trying to create AST using JavaParserBaseVisitor.Visit() I am getting null as a result. AntlrFileStream stream = new AntlrFileStream(file); ITokenSource lexer = new JavaLexer(stream); ITokenStream tokens = new

Modification of the AST-tree of the GCC compiler

可紊 提交于 2020-07-17 22:26:10
问题 It is needed to gather the necessary information about the translation unit using the plugin for GCC and to modify AST on its base. I've already understood how to gather information. But I haven't understand yet how to modify AST before it's passed into CRT. Very little information is available on this subject. Tell me plese what should I read on this subject? Share thoughts, links. Thank's. P.S. I've already read everything on these links: http://en.wikibooks.org/wiki/GNU_C_Compiler

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

这一生的挚爱 提交于 2020-07-10 07:01:11
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

故事扮演 提交于 2020-07-10 07:00:40
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

What happens when you invoke a function that contains yield?

狂风中的少年 提交于 2020-06-28 09:51:07
问题 I read here the following example: >>> def double_inputs(): ... while True: # Line 1 ... x = yield # Line 2 ... yield x * 2 # Line 3 ... >>> gen = double_inputs() >>> next(gen) # Run up to the first yield >>> gen.send(10) # goes into 'x' variable If I understand the above correctly, it seems to imply that Python actually waits until next(gen) to "run up to" to Line 2 in the body of the function. Put another way, the interpreter would not start executing the body of the function until we call

find out elements of _ast module, which is imported in ast.py

五迷三道 提交于 2020-06-26 12:07:12
问题 I am using python 3.4.3 and I am working with the python abstract syntax tree(ast) module. I looked at the source of the ast.py module and I found out that all the ast node classes are implemented in the _ast module, which the ast.py module imports. from _ast import * Now, I wanted to look at the elements of the ast module, so I got the name of all the classes implemented in this module : import _ast import inspect for element in inspect.getmembers(_ast) : print(element) I got the names of

How to represent clang AST in JSON format?

瘦欲@ 提交于 2020-06-16 06:34:31
问题 clang-check -ast-dump -ast-dump-filter=<function_name> main.c gives a AST (only a function declaration) of the particular code. How can we represent generated AST in JSON format? PS: I Want AST for function declaration only. 回答1: Call clang with the -ast-dump=json argument. This was implemented only recently (May 2019) so you need an up-to-date version of Clang. See https://reviews.llvm.org/D60910 for details. There's also a library to export more lower-level information available via

How to parse Python 2.x with Python 3.x ast module?

谁说胖子不能爱 提交于 2020-06-10 03:36:46
问题 I recently wrote a Sublime Text 3 plugin that parses Python code and issues some stats from it. Nothing too complex, except I noticed Sublime Text 3 uses Python 3.x and apparently the ast module expects to see Python 3.x code as well. I looked at the documentation for the ast module but couldn't find anything that allows me to specify the version. Obviously this causes issues when parsing perfectly valid Python 2.7 code. Is there a way to specify or somehow detect/guess the Python version ?

How to parse Python 2.x with Python 3.x ast module?

◇◆丶佛笑我妖孽 提交于 2020-06-10 03:35:12
问题 I recently wrote a Sublime Text 3 plugin that parses Python code and issues some stats from it. Nothing too complex, except I noticed Sublime Text 3 uses Python 3.x and apparently the ast module expects to see Python 3.x code as well. I looked at the documentation for the ast module but couldn't find anything that allows me to specify the version. Obviously this causes issues when parsing perfectly valid Python 2.7 code. Is there a way to specify or somehow detect/guess the Python version ?