Data Structure and Dart Programming language problems

  • Home
  • Data Structure
    • Array and String
    • Linklist
  • Google Flutter
    • Google Flutter
    • DART
  • About Us
  • Home
  • Data Structure
    • Array and String
    • Linklist
  • Google Flutter
    • Google Flutter
    • DART
  • About Us

Sunday, August 6, 2017

Dart replacing the node in the abstract syntax tree

 Tech host     4:15 AM     abstract-syntax-tree, dart, dart-analyzer, flutter, google-flutter     No comments   

Dart replacing the node in the abstract syntax tree

Here is the solution for that.
import 'package:analyzer/analyzer.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/src/dart/ast/token.dart';

String src = """
void main(){
String a ="hey";
String b ="there"; 
print(\$a);
}
""";

AstNode ast;

main() async {

  ast = parseCompilationUnit(src, parseFunctionBodies: true);
  print(ast.toString());
  Visitor v = new Visitor();
  ast.visitChildren(v);
  print(ast.toString());
}    

class Visitor extends SimpleAstVisitor {
  @override
  visitFunctionDeclaration(FunctionDeclaration node) {
    for (var cn in node.childEntities) {
      if (cn.runtimeType.toString() == "FunctionExpressionImpl") {
        Visitor v = new Visitor();
        cn.visitChildren(v);
      }
    }
  }

  @override
  visitBlockFunctionBody(BlockFunctionBody node) {
    Visitor v = new Visitor();
    node.visitChildren(v);
 }

  @override
   visitBlock(Block node) {
     for (var cn in node.childEntities) {
       if (cn.runtimeType.toString() == "ExpressionStatementImpl") {
         Visitor v = new Visitor();
         cn.visitChildren(v);
       }
     }
   }

  @override
  visitMethodInvocation(MethodInvocation node) {
  String result = "print(\$a\$b)";
  Token resultToken =
    new StringToken(TokenType.STRING, result, node.beginToken.offset);
  AstNode replacement = new SimpleStringLiteral(resultToken, result);
  node.parent.accept(new NodeReplacer(node, replacement));
 }
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Dart Programming

 Tech host     4:01 AM     abstract-syntax-tree, dart, dart-analyzer, flutter, google-flutter     No comments   

Dart Programming

Hey guys i am providing the solutions for the some of the problems that i have faced and worked on while exploring the dart programming language

Post 1

How to change dart code using dart analyser. (Abstract Syntax Tree)

Solution
You can find the solution for this here.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Blog Archive

  • ▼  2017 (18)
    • ▼  August (2)
      • Dart replacing the node in the abstract syntax tree
      • Dart Programming
    • ►  March (10)
    • ►  February (6)
  • ►  2016 (1)
    • ►  December (1)
  • ►  2013 (1)
    • ►  August (1)

Popular Posts

  • Dart replacing the node in the abstract syntax tree
    Dart replacing the node in the abstract syntax tree Here is the solution for that. import 'package:analyzer/analyzer.dart'...
  • How to print the node of the given linked list
    Linklist Interview Question How to print the node of the given linked list If you're new to linked lists, this is a great ex...
  • Array Left Rotation
    Array Interview Question Hacker Rank Question Array Left Rotation Hey guys i am providing the solutions for the question given in...
  • Arrays-String interview question 4
    Cracking the coding interview Arrays and String solutions Hey guys i am providing the solutions for the question given in the Ch...
  • Reverse of a given linked list
    linked list Interview Question Reverse of a given linked list You’re given the pointer to the head node of a linked list. Change...
  • Insert Node at nth position in a linked list
    linked list Interview Question Insert Node at nth position in a linked list You’re given the pointer to the head node of a linke...
  • Arrays-String interview question 5
    Cracking the coding interview Arrays and String solutions Hey guys i am providing the solutions for the question given in the C...
  • Arrays-String interview question 3
    Cracking the coding interview Arrays and String solutions Hey guys i am providing the solutions for the question given in the Ch...
  • Arrays-String interview question 7
    Cracking the coding interview Arrays and String solutions Hey guys i am providing the solutions for the question given in the Cha...
  • Arrays-String interview question 1
    Cracking the coding interview Arrays and String question solutions Hey guys i am providing the solutions for the question given i...

Categories

  • about-scra
  • abstract-syntax-tree
  • array
  • array-interview-question
  • array-left-rotation
  • compare-two-linked-list
  • cracking-the-coding-interview
  • dart
  • dart-analyzer
  • flutter
  • frequently-asked-question
  • google-flutter
  • interview-question
  • java
  • left-rotation
  • linklist-interview-question
  • linklist-print-a-node
  • linklist-question
  • popular-linklist-question
  • popular-string-question
  • scra
  • scra-2018
  • string
  • string-interview-question
  • string-palindrome-question

About Me

Tech host
I am a blogger interested in programming and coding challenges. I am interested in knowing about the new technologies and new tech products that are launched daily and to write about them.
View my complete profile

Label

  • about-scra
  • abstract-syntax-tree
  • array
  • array-interview-question
  • array-left-rotation
  • compare-two-linked-list
  • cracking-the-coding-interview
  • dart
  • dart-analyzer
  • flutter
  • frequently-asked-question
  • google-flutter
  • interview-question
  • java
  • left-rotation
  • linklist-interview-question
  • linklist-print-a-node
  • linklist-question
  • popular-linklist-question
  • popular-string-question
  • scra
  • scra-2018
  • string
  • string-interview-question
  • string-palindrome-question
Powered by Blogger.
Revoltify

Revoltify

Copyright © Data Structure and Dart Programming language problems | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates