abstract-syntax-tree

How to Extract AST of given Typescript code using the open source Typescript compiler code?

我与影子孤独终老i 提交于 2019-12-21 05:29:10
问题 As it is known that Typescript is completely opensource now. which is available at Tyescript. I am building an application that will get Typescript code as input and give output the AST of the given code. Provide me a proper way to extract this AST(Abstract Syntax Tree) of input Typescript code rather than comppliling it and converting it into Javascript. 回答1: Basic code: const fileNames = ["C:\\MyFile.ts"]; const compilerOptions: ts.CompilerOptions = { // compiler options go here if any... /

Examples / tutorials for usage of javax.lang.model or ANTLR JavaParser to get information on Java Source Code

Deadly 提交于 2019-12-21 05:25:10
问题 I would like to create an automatic Flowchart-like visualization to simple Java Logic, for this I need to parse Java Source code, I have 2 candidates, ANTLR and javax.lang.model of Java 6. Neither are easy. I have yet to find a single working example that will be even remotely close to what I want to achieve. I want to find simple variable declarations, assignments, and flows (if, for, switch, boolean conditions etc) Is there a simple example or tutorial for either of these? I found very few

How do I pretty-print productions and line numbers, using ANTLR4?

我的梦境 提交于 2019-12-21 04:27:08
问题 I'm trying to write a piece of code that will take an ANTLR4 parser and use it to generate ASTs for inputs similar to the ones given by the -tree option on grun ( misc.TestRig ). However, I'd additionally like for the output to include all the line number/offset information. For example, instead of printing (add (int 5) '+' (int 6)) I'd like to get (add (int 5 [line 3, offset 6:7]) '+' (int 6 [line 3, offset 8:9]) [line 3, offset 5:10]) Or something similar. There aren't a tremendous number

API to compare AST? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-21 04:23:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there a open source java api that allows to compare two Abstract Syntax Trees of java source code? I would like to see the differences between the two syntax trees, similar to how it is done in diff tools. 回答1: Most diff tools compare lines, not syntax trees (see Wikipedia article for discussion). There are

Modify existing yaml file and add new data and comments

心已入冬 提交于 2019-12-21 01:17:08
问题 I recently saw that the go yaml lib has new version (V3) with the nodes capabilities (which in my opinion is a killer feature :) ) which can helps a lots with modifying yamls without changing the structure of the file But since it is fairly new (from last week ) I didn't find some helpful docs and example for the context which I need (add new object/node and to keep the file structure the same without removing the comments etc) what I need is to manipulate yaml file for example lets say I’ve

A parser for regular expressions in PHP?

自作多情 提交于 2019-12-20 10:24:52
问题 I need to parse regular expressions into their components in PHP. I have no problem creating the regular expressions or executing them, but I want to display information about the regular expression (e.g. list the capture groups, attach repetition characters to their targets, ...). The overall project is a plugin for WordPress that gives info about the rewrite rules, which are regexes with substitution patterns, and can be cryptic to understand. I have written a simple implementation myself,

What is the max LINQ Expression Trees can do?

我的未来我决定 提交于 2019-12-19 04:01:00
问题 What is the maximum that LINQ expression Tree can do? Can it define a class? How about a method, with all the declared name, modifiers, parametertype and return type? Must the program always define the tree itself? Is it possible to generate the tree from a given C# file? 回答1: In C# 3, expression trees can represent expressions . Hence the name. And they are further restricted to a subset of C# expressions -- no assignment expressions, no expressions involving pointer types, and so on. In the

Go parser not detecting Doc comments on struct type

我的未来我决定 提交于 2019-12-18 13:01:34
问题 I am trying to read the assocated Doc comments on a struct type using Go’s parser and ast packages. In this example, the code simply uses itself as the source. package main import ( "fmt" "go/ast" "go/parser" "go/token" ) // FirstType docs type FirstType struct { // FirstMember docs FirstMember string } // SecondType docs type SecondType struct { // SecondMember docs SecondMember string } // Main docs func main() { fset := token.NewFileSet() // positions are relative to fset d, err := parser

Any differences between terms parse trees and derivation trees?

断了今生、忘了曾经 提交于 2019-12-18 12:25:15
问题 The terms AST (Abstract Syntax Tree), parse tree and derivation tree are bandied about by different people when referring to the result of parsing texts conforming to a grammar. Assuming we are talking about parsing computer languages, are their differences minute enough that we can use these terms interchangeably ? If not, how do we use the terms correctly ? 回答1: AFAIK, "derivation tree" and "parse tree" are the same. Abstract syntax tree In computer science, an abstract syntax tree (AST),

How to construct an abstract syntax tree

送分小仙女□ 提交于 2019-12-18 09:58:56
问题 I have a general idea of what an AST is, but I want to know how to construct one. If you're given a grammar and a parse tree, how do you construct the AST? How do you do it if you're given a grammar and an expression? 回答1: Well, first off, the grammar is used to construct a parse tree from an expression. So if you already have a parse tree, you don't need the grammar. Depending on how much work your parser does, the resulting tree that is formed from parsing an expression could already be an