惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Vulnerabilities – Threatpost
云风的 BLOG
云风的 BLOG
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
Scott Helme
Scott Helme
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News: Ask HN
Hacker News: Ask HN
The GitHub Blog
The GitHub Blog
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
S
Security Affairs
宝玉的分享
宝玉的分享

Minko Gechev's blog

skillgrade Unit Tests for AI Agent Skills You Should Care About AI Generative Development LLM-first Web Framework Reactive framework in ~200 lines of JavaScript Managing Angular Are LLMs going to replace us? Prefetching Heuristics Design Patterns in Open Source Projects - Part II Design Patterns in Open Source Projects - Part I What I learned doing 125 public talks - Part I Dynamic imports solve all the problems, right? 5 Angular CLI Features You Didn't Know About Angular quicklink Preloading Strategy Introducing Bazel Schematics for Angular CLI Building TypeScript Projects with Bazel Joining Google Playing Mortal Kombat with TensorFlow.js. Transfer learning and data augmentation Fast, extensible, configurable, and beautiful linter for Go Introducing Guess.js - a toolkit for enabling data-driven user-experiences on the Web Machine Learning-Driven Bundling. The Future of JavaScript Tooling. JavaScript Decorators for Declarative and Readable Code 3 Tricks For Using Redux and Immutable.js with TypeScript Follow Your Dream Career with Open Source. Personal Story. Redux Anti-Patterns - Part 1. State Management. Faster Angular Applications - Understanding Differs. Developing a Custom IterableDiffer Faster Angular Applications - Part 2. Pure Pipes, Pure Functions and Memoization Faster Angular Applications - Part 1. On Push Change Detection and Immutability Understanding Dynamic Scoping and TemplateRef Implementing a Simple Compiler on 25 Lines of JavaScript Developing Statically Typed Programming Language WebVR for a Gamified IDE 7 Angular Tools That You Should Consider Announcing ngrev - Reverse Engineering Tool for Angular Implementing Angular's Dependency Injection in React. Understanding Element Injectors. Distributing an Angular Library - The Brief Guide Angular in Production Ahead-of-Time Compilation in Angular 2.5X Smaller Angular 2 Applications with Google Closure Compiler Using Stripe with Angular (Deprecated) Building an Angular Application for Production Implementing the Missing "resolve" Feature of the Angular 2 Router Scalable Single-Page Application Architecture Managing ambient type definitions and dealing with the "Duplicate identifier" TypeScript error Static Code Analysis of Angular 2 and TypeScript Projects Enforcing Best Practices with Static Code Analysis of Angular 2 Projects ViewChildren and ContentChildren in Angular Dynamically Configuring the Angular's Router Angular 2 Hot Loader Lazy Loading of Route Components in Angular 2 Aspect-Oriented Programming in JavaScript Flux in Depth. Store and Network Communication. Using JSX with TypeScript Flux in Depth. Overview and Components. Even Faster AngularJS Data Structures Boost the Performance of an AngularJS Application Using Immutable Data - Part 2 Angular2 - First Impressions Build Your own Simplified AngularJS in 200 Lines of JavaScript Persistent State of ReactJS Component Boost the Performance of an AngularJS Application Using Immutable Data Processing Binary Protocols with Client-Side JavaScript Stream your Desktop to HTML5 Video Element Multi-User Video Conference with WebRTC Asynchronous calls with ES6 generators Binary Tree iterator with ES6 generators WebRTC chat with React.js AngularJS in Patterns (Part 3) AngularJS in Patterns (Part 2). Services. Using GitHub Pages with Jekyll! AngularJS in Patterns (Part 1). Overview of AngularJS Singleton in JavaScript Express over HTTPS What I get from the JavaScript MV* frameworks Remote Desktop Client with AngularJS and Yeoman The magic of $resource (or simply a client-side Active Record) AngularJS Inheritance Patterns AngularAOP v0.1.0 Advanced JavaScript at Sofia University AngularJS style guide Lazy prefetching of AngularJS partials VNC client on 200 lines of JavaScript Aspect-Oriented Programming with AngularJS CSS3 flipping effect Practical programming with JavaScript Why I should use publish/subscribe in JavaScript JavaScript, the weird parts Functional programming with JavaScript plainvm Looking for performance? Probably you should NOT use [].sort (V8) JavaScript image scaling Caching CSS with localStorage Self-invoking functions in JavaScript (or Immediately Invoked Function Expressions) Asus N56VZ + Ubuntu 12.04 (en) Asus N56VZ + Ubuntu 12.04 Debian Squeeze + LXDE on Google Nexus S (or having some fun while suffering) HTML5 image editor Курсови проекти – ФМИ Carousel Gallery SofiaJS...
ELang
2012-09-15 · via Minko Gechev's blog

And one more blog post by me! It’s going to be in brand new topic than the others. For about an year and a half I’ve got an idea which I wanted to accomplish…To create my own simple programming language. Actually it’s very useful task and quite interesting. Creating it you can get better understanding how the compilers and interpreters work and probably write better code. Unfortunately there were two problems…I didn’t have enough time for such task and…I’ve not studied formal grammars (and as I mentioned I don’t have enough time to study them…there are just so much more interesting things to read about :-P ). Last weekend I wasn’t in very good health condition. I think that I have a tradition to make different cool stuffs when I don’t feel very well :-)…Soo for two days I’ve wrote about forty Java classes which actually were ELang.

I opened my Java IDE (I decided to not write the language in JavaScript) and I created few different classes…Actually I had idea to create something very basic, just variables, if, while, number expressions and boolean expressions. Oh…I almost forgot to tell that my language is interpreted so that’s why I decided to have three different stages in the execution process: lexing, parsing and interpreting. The lexing process was straight-forward so there’s nothing interesting about it…I’ve just created different tokens from the long string which is the actual program. Here’s more information about that https://en.wikipedia.org/wiki/Tokenization. After I finished with the lexing…ahh after that…it was the Parsing…Actually that was the process which has been scaring me :-). I’ve created an interface IStatement which was something that has a void method called “execute”. Here’s the interface:

public interface IStatement {
    void execute();
}

Another key part is the interface IExpression which was something similar but:

public interface IExpression {
    Value evaluate();
}

As you might guess Value is a terminal which is a class defined by myself. The statement actually is a list of IStatement-s (Composite). Well it’s not exactly accurate because the if statement, for example, which also implements IStatement has a list of  IStatements and a condition which is actually an IExpression :-). Depending on the current token I make decisions what kind of statement (or expression) should I create. Very important moment is that the variables must be variables in the statements even after the statement is evaluated! Why? Because there’s a while statement. The statements inside the while statement are executed multiple times so if we substitute the variable with it’s value we will loose our statement and possibly create an infinite loop. All expressions are parsed into a reverse polish notation. This is an easy algorithm which can be found just everywhere...Expressions are lists of symbols. A single symbol could be – variable, value (boolean/string/number) or an operator. After an expression is created it can be evaluated with it’s method evaluate (implemented because of the implementation of IExpression). Evaluating expressions in reverse polish notation is quite easy.

With this construction the interpreting process is extremely simple:

public void interpret() {
    Iterator iter = this.statements.iterator();
    IStatement current;
    while (iter.hasNext()) {
        current = iter.next();
        current.execute();
    }
}

I also want to have interaction with the user. So there are also implementations of read and print methods. That’s why I’ve created special kind of IExpression (actually there’s nothing special but just separated in different package :-) ). The print function is a list of IExpressions. After the list is evaluated everything is just put on the user’s screen…Here is the implementation:

public Value evaluate() {
    Value result = this.toPrint.evaluate();
    System.out.print(result.getValue());
    return result;
}

Easy, right? With this kind of language I’ve achieved programs like that:

def fibonacci(n)
    if n >= 0:
        a1 = 0;
        a2 = 1;
        current = 0;
        while n > current:
            temp = a2;
            a2 = a1 + a2;
            a1 = temp;
            current = current + 1;
        endwhile;
        result = a1;
    else: 
        result = 0;
    endif;
    return result;
enddef;

def factorial(n)
    result = 1;
    current = 1;
    while current <= n:
        result = result * current;
        current = current + 1;
    endwhile;
    return result;
enddef;

print 'Enter n for fibonacci number: ';
n = read;
print 'The result for the fibonacci number entered is: ';
print fibonacci(n);
print '\n';

print 'Enter n for factorial: ';
n = read;
print 'The result for the number you entered for factorial is: ';
print factorial(n);
print '\n';

It also allows recursion:

def recursiveFibonacci(n)
    if n == 0:
        return 0;
    endif;
    if n == 1:
        return 1;
    endif;
    return recursiveFibonacci(n - 1) + recursiveFibonacci(n - 2);
enddef;

The github repository can be found here: https://github.com/mgechev/ELang/

After I finished with that I have a desire to improve it a little…Including feature for importing external files will be very useful and may make the language even useful :D. The language can be extended to object-oriented easy by adding hash. If the hash values can be primitives, other hashes and methods this extension can be accomplished without much troubles.

Actually now ELang is quite useful for writing simple programs and teaching beginner programmers how to write different basic constructs but it’s potential ends very quickly after these programmers learn how to use if, while, print, read and declare different functions. :-).