abstract-syntax-tree

What is the equivalent of Python's ast.literal_eval() in Julia?

我的未来我决定 提交于 2019-12-04 19:31:38
问题 Is there anything in Julia which is equivalent to Python's literal_eval provided by the package ast (Abstract Syntax Tree)? A summary of its ( literal_eval ) description: This function only evaluates Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None , and can be used for safely evaluating strings from untrusted sources without the need to parse the values oneself. It is not capable of evaluating arbitrarily complex expressions, for example

Difference between @Delegate and @Mixin AST transformations in Groovy

馋奶兔 提交于 2019-12-04 16:45:22
问题 What's the difference between @Delegate and @Mixin AST transformations in Groovy. Maybe my question has to do with OO and when apply different patterns, but I use both and I can achieve the same behavior. class Person { String name = "Clark" def walk() { "Walk" } } @Mixin(Person) class Superhero { def fly() { "Fly" } } def superman = new Superhero() assert superman.name == "Clark" assert superman.walk() == "Walk" assert superman.fly() == "Fly" class Person { String name = "Clark" def walk() {

Representing C#3 code as an Abstract Syntax Tree in XML

試著忘記壹切 提交于 2019-12-04 14:35:53
I was wondering if there is something similar to GCC_XML for C#3; basically a way to represent a program's entire syntactic structure in XML. Once the representation is created, I was hoping to parse it into an XDocument and interpret or query it from there. Are there tools out there for this? Our DMS Software Reengineering Toolkit can do this with C# 2/3/4 . (EDIT 2014: and now C# 5) DMS has compiler accurate parsers for C# (as well as Java and many other languages). It automatically builds full Abstract Syntax Trees for whatever it parses. Each AST node is stamped with file/line/column for

Generate an AST in C++

被刻印的时光 ゝ 提交于 2019-12-04 13:54:30
问题 I'm making an interpreter in C++, so far I've got my lexer to generate tokens. The problem is I'm not sure how to generate an "walk" a parse tree. I was thinking of making my parse tree using an array of arrays, but I'm not sure how to actually insert the tokens into the parse tree in the correct order. I'm not sure whether or not to go top-down, left-right or bottom-up, right-left. Can anyone provide me with a simple LALR(1) algorithm? 回答1: I'm going to go against conventional wisdom here

Data Flow Graph Construction

余生颓废 提交于 2019-12-04 13:41:35
问题 I have been asked to write a program to construct a data flow graph of a input program code, given the abstract syntax tree. I search for the definition of data flow graph online and found there are a lot of things that goes on in data flow analysis of a code segment. I want to know what exactly I have to draw to construct a data flow graph for a given code. Any help is very much appreciated! 回答1: Given an AST, to produce a data flow graph, you must: build up symbol tables, so that every

How to retrieve a Control Flow Graph for python code?

眉间皱痕 提交于 2019-12-04 12:23:35
I would like to dump the Control Flow Graph of a given python code, similar to the option given by gcc compiler option: -fdump-tree-cfg for c code. I succeeded getting the AST (Abstract Syntax Trees) of a python code, but it seams quite complex and hassle to get the Control Flow Graph from AST phase. Is there an easier way to retrieve directly the Control Flow Graph of a python code? any suggestions? oh by the way I'm using python3.5 Thank you all! P.S I really don't know what kind of interpreter I'm using under the hood, As far as I know it's CPython (not sure), I don't think it's PyPy

Relation of free monad and AST

房东的猫 提交于 2019-12-04 12:17:37
问题 I'm referring to the Ken Scambler's source code listed below, also see GitHub source . package kenbot.free import scalaz._ import Scalaz._ import Free._ import scala.collection.mutable // This example is based off the one in Runar Bjarnason's "Dead Simple Dependency Injection" talk. // http://www.youtube.com/watch?v=ZasXwtTRkio // 0. Fantasy API // def put(key: String, value: String): Unit // def get(key: String): String // def delete(key: String): Unit // 1. ADT sealed trait KVS[+Next] case

How to implement a function call with Antlr so that it can be called even before it is defined?

孤者浪人 提交于 2019-12-04 12:00:07
问题 Once the AST is built, what is the best way implement the tree walker so that functions can be defined and called in whatever order? For example, this is valid in PHP: <?php f(); // function called before it’s defined function f() { print 3; } ?> I’m guessing that somehow there must be a second pass, or a tree transformation, but I can’t find anything interesting on this subject. The problem is probably not an Antlr-specific one, but if you could point me to an Antlr example of how this is

How to extract functions used in a python code file?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 11:51:39
问题 I would like to create a list of all the functions used in a code file. For example if we have following code in a file named 'add_random.py' ` import numpy as np from numpy import linalg def foo(): print np.random.rand(4) + np.random.randn(4) print linalg.norm(np.random.rand(4)) ` I would like to extract the following list: [numpy.random.rand, np.random.randn, np.linalg.norm, np.random.rand] The list contains the functions used in the code with their actual name in the form of 'module

Converting Antlr syntax tree into useful objects

最后都变了- 提交于 2019-12-04 11:32:39
I'm currently pondering how best to take an AST generated using Antlr and convert it into useful objects which I can use in my program. The purpose of my grammar (apart from learning) is to create an executable (runtime interpretted) language. For example, how would I take an attribute sub-tree and have a specific Attribute class instanciated. E.g. The following code in my language: Print(message:"Hello stackoverflow") would product the following AST: My current line of thinking is that a factory class could read the tree, pull out the name ( message ), and type( STRING ) value(" Hello