abstract-syntax-tree

Haskell parser to AST data type, assignment

会有一股神秘感。 提交于 2019-11-30 11:43:09
问题 I have been searching around the interwebs for a couple of days, trying to get an answer to my questions and i'm finally admitting defeat. I have been given a grammar: Dig ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Int ::= Dig | Dig Int Var ::= a | b | ... z | A | B | C | ... | Z Expr ::= Int | - Expr | + Expr Expr | * Expr Expr | Var | let Var = Expr in Expr And i have been told to parse, evaluate and print expressions using this grammar where the operators * + - has their normal meaning The

Go parser not detecting Doc comments on struct type

我的未来我决定 提交于 2019-11-30 09:01:07
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.ParseDir(fset, "./", nil, parser.ParseComments) if err != nil { fmt.Println(err) return } for _, f :=

How to extract AST from Objective-C code?

眉间皱痕 提交于 2019-11-30 08:32:00
问题 I need to analyze Objective-C static code, mainly AST, after looking into the possible tools I found out that Clang tool from LLVM can dump the AST, so I used the terminal to test it using this command: clang -cc1 -ast-dump ~/SomeTest.m but I'm getting this error: In file included from /Users/myusername/SomeTest.m:9: /Users/myusername/SomeTest.h:9:9: fatal error: 'UIKit/UIKit.h' file not found #import <UIKit/UIKit.h> ^ typedef __int128_t __int128_t; typedef __uint128_t __uint128_t; typedef

How to access comments from the java compiler tree api generated ast?

故事扮演 提交于 2019-11-30 07:38:58
I've used the java compiler tree api to generate the ast for java source files. However, i'm unable to access th comments in the source files. So far, i've been unable to find a way to extract comments from source file .. is there a way using the compiler api or some other tool ? Our SD Java Front End is a Java parser that builds ASTs (and optionally symbol tables). It captures comments directly on tree nodes. The Java Front End is a member of a family of compiler langauge front ends (C, C++, C#, COBOL, JavaScript, ...) all of which are supported by DMS Software Reengineering Toolkit . DMS is

Language parser library written in PHP

谁都会走 提交于 2019-11-30 07:24:54
I am looking for a language parser written in PHP . The goal is to read a custom language , not read PHP code. Basically, I want to specify a language syntax, give a code snippet and get back a structure representing it. Then I can traverse that structure to execute the code snippet. I believe the structure will be an AST , but I don't know if this is the only option (I am not intimate with parsers and their vocabulary). I had a look at the Doctrine DQL parser but it doesn't seem like a generic language parser. This is not a complete list, if you're looking for PHP runtime lexer/parsers, one

How to programmatically rename a method using JDT

落花浮王杯 提交于 2019-11-30 04:23:20
问题 My aim is to programmatically call the Refactor >> Rename Eclipse command for a method inside a Java Source File. Renaming a method as such should also apply the change to all the instances where this method is being used/referred. I believe that JDT has a Refactoring API, but not able to find any documents or tutorials for the same. Can somebody point me in the right direction. Edit: The change is not needed at runtime. 回答1: I think your most promising approach is to go to the eclipse source

Visiting nodes in a syntax tree with Python ast module

走远了吗. 提交于 2019-11-30 04:13:16
I'm playing with python ast (abstract syntax tree). I wrote the following and it visited all nodes of the AST. import ast class Py2Neko(ast.NodeVisitor): def generic_visit(self, node): print type(node).__name__ ast.NodeVisitor.generic_visit(self, node) def visit_Name(self, node): print 'Name :', node.id def visit_Num(self, node): print 'Num :', node.__dict__['n'] def visit_Str(self, node): print "Str :", node.s if __name__ == '__main__': node = ast.parse("a = 1 + 2") print ast.dump(node) v = Py2Neko() v.visit(node) Then added some methods to Py2Neko class def visit_Print(self, node): print

Converting Data.Reify explicit sharing graph to AST with de Bruijn indices

别等时光非礼了梦想. 提交于 2019-11-30 03:54:20
问题 I'm trying to recover sharing (in the Type-Safe Observable Sharing in Haskell sense) for a simple AST, using Data.Reify : {-# LANGUAGE DeriveFoldable, DeriveFunctor, DeriveTraversable, TypeFamilies #-} module Sharing where import Data.Foldable import Data.Reify import Data.Traversable -- Original AST, without sharing. Expressed as a functor for ease of -- use with Data.Reify. data AstF f = LitF Int | AddF f f deriving (Foldable, Functor, Show, Traversable) newtype Fix f = In { out :: f (Fix f

How to make use of Clang's AST?

依然范特西╮ 提交于 2019-11-30 00:06:51
I am looking at making use of the Clang's AST for my C code and do some analysis over the AST. Some pointers on where to start, how to obtain the Clang's AST, tutorials or anything in this regard will be of great help!!! I have been trying to find some and I got this link which was created 2 years back. But for some reason, it is not working for me. The sample code, in the tutorial, gives me too many errors. So I am not sure, if I build the code properly or some thing is wrong with the tutorial. But I would be happy to start from some other page as well. Start with the tutorial linked by

Translate C# code into AST?

亡梦爱人 提交于 2019-11-29 22:32:53
Is it currently possible to translate C# code into an Abstract Syntax Tree? Edit: some clarification; I don't necessarily expect the compiler to generate the AST for me - a parser would be fine, although I'd like to use something "official." Lambda expressions are unfortunately not going to be sufficient given they don't allow me to use statement bodies, which is what I'm looking for. The Roslyn project is in Visual Studio 2010 and gives you programmatic access to the Syntax Tree , among other things. SyntaxTree tree = SyntaxTree.ParseCompilationUnit( @" C# code here "); var root =