abstract-syntax-tree

How do i access v8 parse tree how can it be done?

假装没事ソ 提交于 2019-12-04 04:20:54
I like to take the v8 engine and to transform its code to other programming language based on this for example if i understand it right first step i need to get the parse tree my question is : can i get it already from v8 or do i need to generate it from the js code . what is the easer way ? It looks hard to get the AST (Annotated Syntax Tree, the Parse tree) from V8 itself but there are plenty of other parsers for JavaScript that will do what you're looking for. I'd recommend having a look at Esprima ( http://esprima.org/ ) which is a JavaScript parser written in JavaScript. This allows you

Extract the AST from a Ruby block

你说的曾经没有我的故事 提交于 2019-12-04 04:08:16
Is it possible to grab the AST of a block from Ruby itself? I've had a look at both ParseTree and ruby_parser, but they both seem to have sketchy support (from what I've read) for Ruby 1.9.2. I need something that works well with 1.9.2. Ripper is included in MRI 1.9 out of the box. ruby-1.9.2-p180 :004 > require 'ripper' => true ruby-1.9.2-p180 :005 > Ripper.sexp("def a; end") => [:program, [[:def, [:@ident, "a", [1, 4]], [:params, nil, nil, nil, nil, nil], [:bodystmt, [[:void_stmt]], nil, nil, nil]]]] In 1.8, Ruby executes the code by traversing the AST, so it is possible to get the AST for a

Unparse AST < O(exp(n))?

梦想的初衷 提交于 2019-12-04 01:20:13
Abstract problem description: The way I see it, unparsing means to create a token stream from an AST, which when parsed again produces an equal AST. So parse(unparse(AST)) = AST holds. This is the equal to finding a valid parse tree which would produce the same AST. The language is described by a context free S-attributed grammar using a eBNF variant. So the unparser has to find a valid 'path' through the traversed nodes in which all grammar constraints hold. This bascially means to find a valid allocation of AST nodes to grammar production rules. This is a constraint satisfaction problem (CSP

Parsing “->” assignment operator in R

做~自己de王妃 提交于 2019-12-03 23:41:16
问题 My question is about parsing expressions in R language. Let me jump right into an example: fun_text <- c(" 0 -> var f1 <- function() { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 } (function() { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 })->f2 f3 = function(x) { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 } ") fun_tree <- parse(text=fun_text) fun_tree fun_tree[[1]] fun_tree[[2]] fun_tree[[3]] fun_tree[[4]] After that, we obtain those results: expression(0 -> var, f1 <- function() { 0 -> sum_var sum

Generate .pyc from Python AST?

前提是你 提交于 2019-12-03 17:30:20
问题 How would I generate a .pyc file from a Python AST such that I could import the file from Python? I've used compile to create a code object, then written the co_code attribute to a file, but when I try to import the file from Python, I get an ImportError: Bad magic number in output.pyc . 回答1: The solution can be adapted from the py_compile module: import marshal import py_compile import time import ast codeobject = compile(ast.parse('print "Hello World"'), '<string>', 'exec') with open(

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

与世无争的帅哥 提交于 2019-12-03 16:32:32
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 ANTLR examples (non of them are working out of the box without significant "homework") and absolutely

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

倖福魔咒の 提交于 2019-12-03 16:28:35
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. Basic code: const fileNames = ["C:\\MyFile.ts"]; const compilerOptions: ts.CompilerOptions = { // compiler options go here if any... // look at ts.CompilerOptions to see what's available }; const program = ts.createProgram(fileNames,

Parsing SQL like syntax, design pattern

痞子三分冷 提交于 2019-12-03 16:13:10
问题 I am trying mock sql syntax to build a simple sql like interface to a key-value storage. The values are essentially POJOs An example would be select A.B.C from OBJ_POOL where A.B.X = 45 AND A.B.Y > '88' AND A.B.Z != 'abc'; OBJ_POOL is just a list of POJOs of the same class. In this example A would be the base class. Class A Class B String C Integer X String Y String Z Now A.B.C is equivalent A.getB().getC() I am using Antlr to parse the above statement to get an AST, and then hoping to use

Pretty Printing Syntax Tree with Operator Precedence and Associativity in Haskell

青春壹個敷衍的年華 提交于 2019-12-03 14:47:05
问题 Is there any commonly used method or even a library for pretty printing (and parsing) a syntax tree with (binary) operators that have an associativity and a precedence level assigned, so that the result uses as few brackets as possible? Take the formulas of propositional calculus as an example: data Formula = Atom String | Not (Formula) | And (Formula) (Formula) | Or (Formula) (Formula) | Imp (Formula) (Formula) Assume that the precedence is Imp < Or < And < Not (so Not binds the most) and

API to compare AST? [closed]

坚强是说给别人听的谎言 提交于 2019-12-03 13:50:50
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. Most diff tools compare lines, not syntax trees (see Wikipedia article for discussion ). There are some techical papers that talk about how to do syntax tree compares, e.g., Diff/TS: A Tool for Fine-Grained Structural Change Analysis There are no APIs for computing tree differences available anywhere as far as I know. The problem is more complex than it first sounds, if you want to get a