Search Results

Search found 166 results on 7 pages for 'ast'.

Page 1/7 | 1 2 3 4 5 6 7  | Next Page >

  • Working with expression AST:s

    - by Marcus
    Hi, Is there any best practice when working with AST:s? I have a parsed expression AST. ConstantExpression, BinaryExpression etc. I want to populate a GUI-dialog with information from the AST, and it's here where I get kinda confused because my code gets pretty messy. Example: expression = "Var1 > 10 AND Var2 < 20" I want to populate two textboxes with value 10 resp. 20 from the AST. What I'm doing now is a recursive method that checks for correct child expression-types (with .Net Is-operator) and acts accordingly and the code is really "smelly" :) Is there any design pattern, like Visitor or such, that makes this somewhat easier/more readable/maintainable ?

    Read the article

  • Generating scala AST for recursive method.

    - by scout
    I am generating the scala AST using the following code: val setting = new Settings(error) val reporter = new ConsoleReporter(setting, in, out) { override def displayPrompt = () } val compiler = new Global(setting, reporter) with ASTExtractor{ override def onlyPresentation = true } //setting.PhasesSetting("parser", "parserPhase") val run = new compiler.Run val sourceFiles:List[String] = List("Test.scala") run.compile(sourceFiles.toList) I guess this is the standard code used to run the compiler in the code and generate the AST to work with. The above code worked fine for any valid scala code in Test.scala till now. When I use a recursive function in Test.scala, like def xMethod(x:Int):Int = if(x == 0) -1 else xMethod(x-1) It gives me a java.lang.NullPointerException. The top few lines of the stack trace look like this at scala.tools.nsc.typechecker.Typers$Typer.checkNoDoubleDefsAndAddSynthetics$1(Typers.scala:2170) at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2196) at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:1951) at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3815) at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4124) at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4177) at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:199) The code works fine for a method like def aMethod(c:Int):Int = { bMethod(c) } def bMethod(x:Int):Int = aMethod(x) Please let me know if recursive functions need any other setting.

    Read the article

  • Creating AST for shared and local variables

    - by Rizwan Abbasi
    Here is my grammar grammar simulator; options { language = Java; output = AST; ASTLabelType=CommonTree; } //imaginary tokens tokens{ SHARED; LOCALS; BOOL; RANGE; ARRAY; } parse : declaration+ ; declaration :variables ; variables : locals ; locals : (bool | range | array) ; bool :ID 'in' '[' ID ',' ID ']' ('init' ID)? -> ^(BOOL ID ID ID ID?) ; range : ID 'in' '[' INT '..' INT ']' ('init' INT)? -> ^(RANGE ID INT INT INT?) ; array :ID 'in' 'array' 'of' '[' INT '..' INT ']' ('init' INT)? -> ^(ARRAY ID INT INT INT?) ; ID : (('a'..'z' | 'A'..'Z'|'_')('a'..'z' | 'A'..'Z'|'0'..'9'|'_'))* ; INT : ('0'..'9')+ ; WHITESPACE : ('\t' | ' ' | '\r' | '\n' | '\u000C')+ {$channel = HIDDEN;} ; INPUT flag in [down, up] init down pc in [0..7] init 0 CA in array of [0..5] init 0 AST It is having a small problem. Variables (bool, range or array) can be of two abstract types 1. locals (each object will have it's own variable) 2. shared (think of static in java, same for all object) Now the requirements are changed. I want the user to input like this NEW INPUT domains: upDown [up,down] possibleStates [0-7] booleans [true,false] locals: pc in possibleStates init 0 flag in upDown init down flag1 in upDown init down map in array of booleans init false shared: pcs in possibleStates init 0 flag in upDown init down flag1 in upDown init down maps in array of booleans init false Again, all the variables can be of two types (of any domain sepecified) 1. Local 2. Shared In Domains: upDown [up,down] possibleStates [0-7] upDown, up, down and possibleStates are of type ID (ID is defined in my above grammar), 0 and 7 are of type INT Can any body help me how to convert my current grammar to meet new specifications.

    Read the article

  • Building a control-flow graph from an AST with a visitor pattern using Java

    - by omegatai
    Hi guys, I'm trying to figure out how to implement my LEParserCfgVisitor class as to build a control-flow graph from an Abstract-Syntax-Tree already generated with JavaCC. I know there are tools that already exist, but I'm trying to do it in preparation for my Compilers final. I know I need to have a data structure that keeps the graph in memory, and I want to be able to keep attributes like IN, OUT, GEN, KILL in each node as to be able to do a control-flow analysis later on. My main problem is that I haven't figured out how to connect the different blocks together, as to have the right edge between each blocks depending on their nature: branch, loops, etc. In other words, I haven't found an explicit algorithm that could help me build my visitor. Here is my empty Visitor. You can see it works on basic langage expressions, like if, while and basic operations (+,-,x,^,...) public class LEParserCfgVisitor implements LEParserVisitor { public Object visit(SimpleNode node, Object data) { return data; } public Object visit(ASTProgram node, Object data) { data = node.childrenAccept(this, data); return data; } public Object visit(ASTBlock node, Object data) { } public Object visit(ASTStmt node, Object data) { } public Object visit(ASTAssignStmt node, Object data) { } public Object visit(ASTIOStmt node, Object data) { } public Object visit(ASTIfStmt node, Object data) { } public Object visit(ASTWhileStmt node, Object data) { } public Object visit(ASTExpr node, Object data) { } public Object visit(ASTAddExpr node, Object data) { } public Object visit(ASTFactExpr node, Object data) { } public Object visit(ASTMultExpr node, Object data) { } public Object visit(ASTPowerExpr node, Object data) { } public Object visit(ASTUnaryExpr node, Object data) { } public Object visit(ASTBasicExpr node, Object data) { } public Object visit(ASTFctExpr node, Object data) { } public Object visit(ASTRealValue node, Object data) { } public Object visit(ASTIntValue node, Object data) { } public Object visit(ASTIdentifier node, Object data) { } } Can anyone give me a hand? Thanks!

    Read the article

  • Converting ANTLR AST to Java bytecode using ASM

    - by Nick
    I am currently trying to write my own compiler, targeting the JVM. I have completed the parsing step using Java classes generated by ANTLR, and have an AST of the source code to work from (An ANTLR "CommonTree", specifically). I am using ASM to simplify the generating of the bytecode. Could anyone give a broad overview of how to convert this AST to bytecode? My current strategy is to explore down the tree, generating different code depending on the current node (using "Tree.getType()"). The problem is that I can only recognise tokens from my lexer this way, rather than more complex patterns from the parser. Is there something I am missing, or am I simply approaching this wrong? Thanks in advance :)

    Read the article

  • org.hibernate.hql.ast.QuerySyntaxException: TABLE NAME is not mapped

    - by Coronatus
    I have two models, Item and ShopSection. They have a many-to-many relationship. @Entity(name = "item") public class Item extends Model { @ManyToMany(cascade = CascadeType.PERSIST) public Set<ShopSection> sections; } @Entity(name = "shop_section") public class ShopSection extends Model { public List<Item> findActiveItems(int page, int length) { return Item.find("select distinct i from Item i join i.sections as s where s.id = ?", id).fetch(page, length); } } findActiveItems is meant to find items in a section, but I get this error: org.hibernate.hql.ast.QuerySyntaxException: Item is not mapped [select distinct i from Item i join i.sections as s where s.id = ?] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111) at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93) at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:322) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:272) ... 8 more What am I doing wrong?

    Read the article

  • How to keep AST for feature access?

    - by greenoldman
    Consider such code (let's say it is C++) Foo::Bar.get().X How one should keep the AST for this -- as "tree" with root at left Foo(Bar(get(X)), or with root at right (((Foo)Bar)get)X? Or maybe as a flat structure (list)? The first one seems more convenient when resolving names, the second when working with it as expression. I set tag parsing but I am asking from semantic analysis POV really (there is no such tag).

    Read the article

  • How to convert source code to a xml based representation of the ast?

    - by autobiographer
    i wanna get a xml representation of the ast of java and c code. 3 months ago, i asked this question yet but the solutions weren't comfortable for me srcml seems to be a good solution for this problem but it does not support line numbers and columns but i need that feature. about elsa: cite: "There is ongoing effort to export the Elsa AST as an XML document; we expect to be able to advertise this in the next public release." dms... didn't understand that. especially for java, there is javaml which supports line numbers. but the sourceforge page doesn't list any files. question: there's software available which supports conversion of ast into xml which supports line numbers (and columns) [especially for java and c/c++]? is there an alternative to javaml and srcml? ps: i don't wanne have parser generators. i hope to find a tool which can be used on the console typing: ./my-xml-generator Test.java [or something like that]... or a java implementation would be great too.

    Read the article

  • Visualizing an AST created with ANTLR (in a .Net environment)

    - by Benjamin Podszun
    Hi there. For a pet project I started to fiddle with ANTLR. After following some tutorials I'm now trying to create the grammar for my very own language and to generate an AST. For now I'm messing around in ANTLRWorks mostly, but now that I have validated that the parse tree seems to be fine I'd like to (iteratively, because I'm still learning and still need to make some decisions regarding the final structure of the tree) create the AST. It seems that antlrworks won't visualize it (or at least not using the "Interpreter" feature, Debug's not working on any of my machines). Bottom line: Is the only way to visualize the AST the manual way, traversing/showing it or printing the tree in string representation to a console? What I'm looking for is a simple way to go from input, grammar - visual AST representation a la the "Interpreter" feature of ANTLRWorks. Any ideas?

    Read the article

  • Processing an n-ary ANTLR AST one child at a time

    - by Chris Lieb
    I currently have a compiler that uses an AST where all children of a code block are on the same level (ie, block.children == {stm1, stm2, stm3, etc...}). I am trying to do liveness analysis on this tree, which means that I need to take the value returned from the processing of stm1 and then pass it to stm2, then take the value returned by stm2 and pass it to stm3, and so on. I do not see a way of executing the child rules in this fashion when the AST is structured this way. Is there a way to allow me to chain the execution of the child grammar items with my given AST, or am I going to have to go through the painful process of refactoring the parser to generate a nested structure and updating the rest of the compiler to work with the new AST? Example ANTLR grammar fragment: block : ^(BLOCK statement*) ; statement : // stuff ; What I hope I don't have to go to: block : ^(BLOCK statementList) ; statementList : ^(StmLst statement statement+) | ^(StmLst statement) ; statement : // stuff ;

    Read the article

  • Creating simple calculator with bison & flex in C++ (not C)

    - by ak91
    Hey, I would like to create simple C++ calculator using bison and flex. Please note I'm new to the creating parsers. I already found few examples in bison/flex but they were all written in C. My goal is to create C++ code, where classes would contain nodes of values, operations, funcs - to create AST (evaluation would be done just after creating whole AST - starting from the root and going forward). For example: my_var = sqrt(9 ** 2 - 32) + 4 - 20 / 5 my_var * 3 Would be parsed as: = / \ my_var + / \ sqrt - | / \ - 4 / / \ / \ ** 32 20 5 / \ 9 2 and the second AST would look like: * / \ my_var 3 Then following pseudocode reflects AST: ast_root = create_node('=', new_variable("my_var"), exp) where exp is: exp = create_node(OPERATOR, val1, val2) but NOT like this: $$ = $1 OPERATOR $3 because this way I directly get value of operation instead of creation the Node. I believe the Node should contain type (of operation), val1 (Node), val2 (Node). In some cases val2 would be NULL, like above mentioned sqrt which takes in the end one argument. Right? It will be nice if you can propose me C++ skeleton (without evaluation) for above described problem (including *.y file creating AST) to help me understand the way of creating/holding Nodes in AST. Code can be snipped, just to let me get the idea. I'll also be grateful if you point me to an existing (possibly simple) example if you know any. Thank you all for your time and assistance!

    Read the article

  • Cucumber error under bundler

    - by Senthil
    I've confirmed cucumber tests work fine without bundler, but with bundler it breaks. This is the error I get: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each (NoMethodError) /home/senthil/rails/othersprograms/nmicho-teambox/vendor/plugins/cucumber/lib/cucumber/formatter/console.rb:148:in `record_tag_occurrences' /home/senthil/rails/othersprograms/nmicho-teambox/vendor/plugins/cucumber/lib/cucumber/formatter/pretty.rb:71:in `before_feature_element' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:190:in `__send__' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:190:in `send_to_all' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:188:in `each' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:188:in `send_to_all' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:179:in `broadcast' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:50:in `visit_feature_element' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/feature.rb:26:in `accept' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/feature.rb:25:in `each' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/feature.rb:25:in `accept' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:20:in `visit_feature' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:180:in `broadcast' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:19:in `visit_feature' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/features.rb:29:in `accept' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/features.rb:17:in `each' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/features.rb:17:in `each' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/features.rb:28:in `accept' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:14:in `visit_features' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:180:in `broadcast' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/ast/tree_walker.rb:13:in `visit_features' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/cli/main.rb:61:in `execute!' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/../lib/cucumber/cli/main.rb:20:in `execute' /var/lib/gems/1.8/gems/cucumber-0.6.1/bin/cucumber:8 /var/lib/gems/1.8/bin/cucumber:19:in `load' /var/lib/gems/1.8/bin/cucumber:19 I've searched all over Google and nothing. Oh btw the above tests is when I was trying to run cucumber tests in Teambox app. I've downloaded it fresh and it still breaks. But if I use their old versions where they didn't not have bundler installed, it works fine. Can anyone help? Thanks

    Read the article

  • ANTLR AST rules fail with RewriteEmptyStreamException

    - by Barry Brown
    I have a simple grammar: grammar sample; options { output = AST; } assignment : IDENT ':=' expr ';' ; expr : factor ('*' factor)* ; factor : primary ('+' primary)* ; primary : NUM | '(' expr ')' ; IDENT : ('a'..'z')+ ; NUM : ('0'..'9')+ ; WS : (' '|'\n'|'\t'|'\r')+ {$channel=HIDDEN;} ; Now I want to add some rewrite rules to generate an AST. From what I've read online and in the Language Patterns book, I should be able to modify the grammar like this: assignment : IDENT ':=' expr ';' -> ^(':=' IDENT expr) ; expr : factor ('*' factor)* -> ^('*' factor+) ; factor : primary ('+' primary)* -> ^('+' primary+) ; primary : NUM | '(' expr ')' -> ^(expr) ; But it does not work. Although it compiles fine, when I run the parser I get a RewriteEmptyStreamException error. Here's where things get weird. If I define the pseudo tokens ADD and MULT and use them instead of the tree node literals, it works without error. tokens { ADD; MULT; } expr : factor ('*' factor)* -> ^(MULT factor+) ; factor : primary ('+' primary)* -> ^(ADD primary+) ; Alternatively, if I use the node suffix notation, it also appears to work fine: expr : factor ('*'^ factor)* ; factor : primary ('+'^ primary)* ; Is this discrepancy in behavior a bug?

    Read the article

  • AST with fixed nodes instead of error nodes in antlr

    - by ahe
    I have an antlr generated Java parser that uses the C target and it works quite well. The problem is I also want it to parse erroneous code and produce a meaningful AST. If I feed it a minimal Java class with one import after which a semicolon is missing it produces two "Tree Error Node" objects where the "import" token and the tokens for the imported class should be. But since it parses the following code correctly and produces the correct nodes for this code it must recover from the error by adding the semicolon or by resyncing. Is there a way to make antlr reflect this fixed input it produces internally in the AST? Or can I at least get the tokens/text that produced the "Tree Node Errors" somehow? In the C targets antlr3commontreeadaptor.c around line 200 the following fragment indicates that the C target only creates dummy error nodes so far: static pANTLR3_BASE_TREE errorNode (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_TOKEN_STREAM ctnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e) { // Use the supplied common tree node stream to get another tree from the factory // TODO: Look at creating the erronode as in Java, but this is complicated by the // need to track and free the memory allocated to it, so for now, we just // want something in the tree that isn't a NULL pointer. // return adaptor->createTypeText(adaptor, ANTLR3_TOKEN_INVALID, (pANTLR3_UINT8)"Tree Error Node"); } Am I out of luck here and only the error nodes the Java target produces would allow me to retrieve the text of the erroneous nodes?

    Read the article

  • Using antlr and the DLR together -- AST conversion

    - by RCIX
    I have an AST generated via ANTLR, and I need to convert it to a DLR-compatible one (Expression Trees). However, it would seem that i can't use tree pattern matchers for this as expression trees need their subtrees at instantiation (which i can't get). What solution would be best for me to use?

    Read the article

  • Translate C# code into AST?

    - by Erik Forbes
    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.

    Read the article

  • AST generation for a an application developed both in visual basic and c#

    - by Dev
    Hi, I'm currently understanding one application developed both in visual basic and c#. Running through the code is getting tough as code is around 50KLOC. So i'm planning for generation of AST (abstract syntax tree). Will it be possible to generate for both language together. Atleast a call graph generation will be helpful (but can't find any tool which works for both languages) Please let me know if this question is confusing. Thanks in Advance Dev

    Read the article

  • AppEngine JRuby - OutOfMemoryError: Java heap space - can it be solved?

    - by elado
    I use AppEngine JRuby on Rails (SDK version 1.3.3.1) - a problem I encounter often is that after a few requests the server is getting really SLOW, until it dies and throws OutOfMemoryError on the terminal (OSX). The requests themselves are very lightweight, not more than looking for an entity or saving it, using DataMapper. On appspot, this problem is not happening. Is there any way to enlarge the heap space for JRuby? The exception log: Exception in thread "Timer-2" java.lang.OutOfMemoryError: Java heap space Apr 29, 2010 8:08:22 AM com.google.apphosting.utils.jetty.JettyLogger warn WARNING: Error for /users/close_users java.lang.OutOfMemoryError: Java heap space at org.jruby.RubyHash.internalPut(RubyHash.java:480) at org.jruby.RubyHash.internalPut(RubyHash.java:461) at org.jruby.RubyHash.fastASet(RubyHash.java:837) at org.jruby.RubyArray.makeHash(RubyArray.java:2998) at org.jruby.RubyArray.makeHash(RubyArray.java:2992) at org.jruby.RubyArray.op_diff(RubyArray.java:3103) at org.jruby.RubyArray$i_method_1_0$RUBYINVOKER$op_diff.call(org/jruby/RubyArray$i_method_1_0$RUBYINVOKER$op_diff.gen) at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:146) at org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57) at org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123) at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104) at org.jruby.ast.BlockNode.interpret(BlockNode.java:71) at org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373) at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:346) at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:303) at org.jruby.runtime.Block.yield(Block.java:194) at org.jruby.RubyArray.collect(RubyArray.java:2354) at org.jruby.RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$collect.call(org/jruby/RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$collect.gen) at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:115) at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:122) at org.jruby.ast.CallNoArgBlockNode.interpret(CallNoArgBlockNode.java:64) at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:61) at org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123) at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104) at org.jruby.ast.BlockNode.interpret(BlockNode.java:71) at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:98) at org.jruby.ast.BeginNode.interpret(BeginNode.java:83) at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104) at org.jruby.ast.BlockNode.interpret(BlockNode.java:71) at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96) at org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:201) at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:183)

    Read the article

  • Creating an AST node in Erlang

    - by dagda1
    Hi, I am playing about with Erlang and I am trying to write a simple arithmetic parser. I want to try and parse the following expression: ((12+3)-4) I want to parse the expression into a stack of AST nodes. When parsing this expression, I would first of all create a binary expression for the (12+3) expression which would look something like this in C#: var binaryStructure = new BinaryStructure(); binaryStructure.Left = IntegerLiteralExpression(12); binaryStructure.Right = IntegerLiteralExpression(4); binaryStructure.Operator = binaryExpression.Operator != BinaryOperatorType.Addition; I am quite new to Erlang and I am wondering how I would go about creating a structure like this in Erlang that I can place on a List that I would use as the stack of expressions. Can anyone suggest how to create such a tree like structure? Would a function be a good fit? Thanks Paul

    Read the article

  • C++ vector and segmentation faults

    - by Headspin
    I am working on a simple mathematical parser. Something that just reads number = 1 + 2; I have a vector containing these tokens. They store a type and string value of the character. I am trying to step through the vector to build an AST of these tokens, and I keep getting segmentation faults, even when I am under the impression my code should prevent this from happening. Here is the bit of code that builds the AST: struct ASTGen { const vector<Token> &Tokens; unsigned int size, pointer; ASTGen(const vector<Token> &t) : Tokens(t), pointer(0) { size = Tokens.size() - 1; } unsigned int next() { return pointer + 1; } Node* Statement() { if(next() <= size) { switch(Tokens[next()].type) { case EQUALS : Node* n = Assignment_Expr(); return n; } } advance(); } void advance() { if(next() <= size) ++pointer; } Node* Assignment_Expr() { Node* lnode = new Node(Tokens[pointer], NULL, NULL); advance(); Node* n = new Node(Tokens[pointer], lnode, Expression()); return n; } Node* Expression() { if(next() <= size) { advance(); if(Tokens[next()].type == SEMICOLON) { Node* n = new Node(Tokens[pointer], NULL, NULL); return n; } if(Tokens[next()].type == PLUS) { Node* lnode = new Node(Tokens[pointer], NULL, NULL); advance(); Node* n = new Node(Tokens[pointer], lnode, Expression()); return n; } } } }; ... ASTGen AST(Tokens); Node* Tree = AST.Statement(); cout << Tree->Right->Data.svalue << endl; I can access Tree->Data.svalue and get the = Node's token info, so I know that node is getting spawned, and I can also get Tree->Left->Data.svalue and get the variable to the left of the = I have re-written it many times trying out different methods for stepping through the vector, but I always get a segmentation fault when I try to access the = right node (which should be the + node) Any help would be greatly appreciated.

    Read the article

  • Interrogating Java source code

    - by VibeofBoston
    I have a Java source code that I need to interrogate and apply security policies [for e.g. applying CWE] I have couple of ideas, for starters using AST and then travel thru the tree. Others include using regular expression. Are there any options other than AST or regex that I could use for such process.

    Read the article

  • Boost::Spirit::Qi autorules -- avoiding repeated copying of AST data structures

    - by phooji
    I've been using Qi and Karma to do some processing on several small languages. Most of the grammars are pretty small (20-40 rules). I've been able to use autorules almost exclusively, so my parse trees consist entirely of variants, structs, and std::vectors. This setup works great for the common case: 1) parse something (Qi), 2) make minor manipulations to the parse tree (visitor), and 3) output something (Karma). However, I'm concerned about what will happen if I want to make complex structural changes to a syntax tree, like moving big subtrees around. Consider the following toy example: A grammar for s-expr-style logical expressions that uses autorules... // Inside grammar class; rule names match struct names... pexpr %= pand | por | var | bconst; pand %= lit("(and ") >> (pexpr % lit(" ")) >> ")"; por %= lit("(or ") >> (pexpr % lit(" ")) >> ")"; pnot %= lit("(not ") >> pexpr >> ")"; ... which leads to parse tree representation that looks like this... struct var { std::string name; }; struct bconst { bool val; }; struct pand; struct por; struct pnot; typedef boost::variant<bconst, var, boost::recursive_wrapper<pand>, boost::recursive_wrapper<por>, boost::recursive_wrapper<pnot> > pexpr; struct pand { std::vector<pexpr> operands; }; struct por { std::vector<pexpr> operands; }; struct pnot { pexpr victim; }; // Many Fusion Macros here Suppose I have a parse tree that looks something like this: pand / ... \ por por / \ / \ var var var var (The ellipsis means 'many more children of similar shape for pand.') Now, suppose that I want negate each of the por nodes, so that the end result is: pand / ... \ pnot pnot | | por por / \ / \ var var var var The direct approach would be, for each por subtree: - create pnot node (copies por in construction); - re-assign the appropriate vector slot in the pand node (copies pnot node and its por subtree). Alternatively, I could construct a separate vector, and then replace (swap) the pand vector wholesale, eliminating a second round of copying. All of this seems cumbersome compared to a pointer-based tree representation, which would allow for the pnot nodes to be inserted without any copying of existing nodes. My question: Is there a way to avoid copy-heavy tree manipulations with autorule-compliant data structures? Should I bite the bullet and just use non-autorules to build a pointer-based AST (e.g., http://boost-spirit.com/home/2010/03/11/s-expressions-and-variants/)?

    Read the article

  • Creating a Compilation Unit with type bindings

    - by hizki
    I am working with the AST API in java, and I am trying to create a Compilation Unit with type bindings. I wrote the following code: private static CompilationUnit parse(ICompilationUnit unit) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(unit); parser.setResolveBindings(true); CompilationUnit compiUnit = (CompilationUnit) parser.createAST(null); return compiUnit; } Unfortunately, when I run this code in debug mode and inspect compiUnit I find that compiUnit.resolver.isRecoveringBindings is false. Can anyone think of a reason why it wouldn't be true, as I specified it to be? Thank you

    Read the article

1 2 3 4 5 6 7  | Next Page >