Daily Archives: July 12, 2014

Mass Programming Language (5) Variables Scope

Previos Post

I finally started a new implementation of variables and their scope in programming language Mass. My idea is:

– Have local variables

– No need to explicitly declare

– Access available "outside" if necessary

The basic idea is:

– Any variable assignment involves the local level

That is, if I assign

a = 3

in a function, this refers to a local variable in the function. No matter if there is a variable external to the function

See for example

https://github.com/ajlopez/Mass/blob/master/Src/Mass.Core.Tests/MachineFiles/Local.ms

# file variable
a = 1

define foo()
    a = 2 # local variable
end

foo()

The first variable a is a variable of the file in process (the module). The variable assigned in the foo function is local to that function, and it is different from the outside variable.

But if we do not assign the variable, and only consulted it, its value is returned. example:

https://github.com/ajlopez/Mass/blob/master/Src/Mass.Core.Tests/MachineFiles/Scope.ms

# file variable
a = 1

define foo()
   a # access file variable
end

foo()

In this case, the function foo returns the value to "outside", since this variable has not been assigned in the function when evaluating the return value.

How to edit an "external” variable, that is, a non-local variablel? Well, this is a topic for an upcoming post. The idea: to access the value of a non-local variable, it must be implied, without declaring anything extra. BUT modifying its value must should be explicit: we put something to explicitly declare "we are changing the value of a non-local variable".

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Node.Js: Links, News And Resources (22)

Previous Post
Next Post

More links from my collection. More updated links at http://delicious.com/ajlopez/nodejs

javascript – Do you know any tutorial for mongoDB in nodeJS? – Stack Overflow
http://stackoverflow.com/questions/6166322/do-you-know-any-tutorial-for-mongodb-in-nodejs

NodeCellar
https://github.com/ccoenraets/nodecellar
Sample application built with Backbone.js, Twitter Bootstrap, Node.js, Express, MongoDB

Node.js, Express, Stylus, MongoDB example
https://github.com/kulakowka/nodejs-express-stylus-mongodb-example

flitbit/fpipe
https://github.com/flitbit/fpipe
Node.js module for grafting a middleware pipeline over a target function

deanmao/node-hubbub
https://github.com/deanmao/node-hubbub
NodeJS html parser npm package using the parser library from the netsurf web browser — it’s fast and accurate

qraftlabs/node-odata-parser
https://github.com/qraftlabs/node-odata-parser
OData query string parser for node.js

theLIFT – A Digital Innovation Group
http://www.thelift.net/

Express.js by Dan Zajdband – Comunidad Nodejs Argentina – YouTube
http://www.youtube.com/watch?v=pQN5U0EQoUo&feature=youtu.be

Websockets y Node.js en las nubes – MedellínJS (Medellín) – Meetup
http://www.medellinjs.org/events/86130022/

NPM shrinkwrap
https://npmjs.org/doc/shrinkwrap.html
Lock down dependency versions

shigeki/node-class-diagram
https://github.com/shigeki/node-class-diagram
Class Diagram of Node.js
This shows the class structure of Node.js at a glance. This covers most of classes in the node manual but has a few exceptions

Bifocals by Dashron
http://bifocalsjs.com/
A node.js View library with support for asynchronous sub-views (aka partials) and interchangeable rendering systems.

Node.js, Express, Mongoose demo
https://github.com/madhums/nodejs-express-mongoose-demo

Node.js & WebSocket – Simple chat tutorial
http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial

Node.js Application using Socket.io
http://www.windowsazure.com/en-us/develop/nodejs/tutorials/app-using-socketio/

url routing – Organize routes in Node.js – Stack Overflow
http://stackoverflow.com/questions/4602212/organize-routes-in-node-js

node.js – Using routes in Express-js – Stack Overflow
http://stackoverflow.com/questions/8864626/using-routes-in-express-js

Node.js: A Todo App with Express | Blog :: The JavaScript Playground
http://javascriptplayground.com/blog/2012/04/node-js-a-todo-app-with-express

Express.js Tutorial
http://www.hacksparrow.com/express-js-tutorial.html

Creating a basic site with node.js and Express – shapeshed
http://shapeshed.com/creating-a-basic-site-with-node-and-express/

Getting Started with Express – How To Node – NodeJS
http://howtonode.org/getting-started-with-express

Seattle Node.js (Seattle, WA) – Meetup
http://www.meetup.com/Seattle-Node-js/

Episode 12 – Isaac Schlueter – http://www.jsconflive.com
http://www.jsconflive.com/pages/20120631
The man behind NPM and now the newly annointed leader of Node.js, Isaac Schlueter, stops by for a quick chat.

How to Write Portable Node.js Code – Node.js on Windows Azure
http://nodeblog.azurewebsites.net/how-to-write-portable-nodejs-code

stomita/node-salesforce
https://github.com/stomita/node-salesforce
Salesforce API Connection Library for Node.js Applications

My Links
http://delicious.com/ajlopez/nodejs

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

GrammGen In C# (2) First Rules

Previous Post

Let’s see today how a parser is built with GrammGen using code. The idea is to define using GrammGen how to build a tree with expressions detected in the text under process. The text is written in the programming language that we want to implement. The expression tree is created using the GrammGen definition, given by code.

I presented in the previous post for an example of a console program, which employs GrammGen. A parser is defined using rules. The rules indicate:

– How to process text characters
– How then form text elements, such as numbers, names, operators
– How to go from putting together such elements, expressions, commands that define our language to implement.

In the sample of calculator

https://github.com/ajlopez/GrammGen/tree/master/Samples/Calculator

the rules are defined by the parser:

https://github.com/ajlopez/GrammGen/blob/master/Samples/Calculator/Calculator/ExpressionParser.cs

The first rules:

private static Rule[] rules = new Rule[]
{
   Rule.Or(' ', '\t', '\r', '\n').Skip(),
   Rule.Or('+', '-').Generate("Oper0"),
   Rule.Or('*', '/').Generate("Oper1"),
// ...


The idea is to get an Expression. The first rule defines that anyone (Rule.Or) of space, tab, carriage return, new line items are ignored (. Skip ()). You can put more than one rule of this type, for example, to set comments to be ignored from the input text.

The second rule defines both + (the plus sign) and – (minus sign) produce a called terminal Oper0. They differ from * (the token) and / (divide sign) because we want to take precedence among operators.

There is a rule to construct integers:

 

Rule.Get("0-9").OneOrMore().Generate("Integer", MakeIntegerConstantExpression), 

The Rule.Get allows you to specify a range of characters, and then, with the fluent interface defined, you can attach the .OneOrMore () method, which specifies that the rule can be applied once or several times. When you can not apply more, it ends generating a node called "Integer". But in GrammGen a node, in addition to a name, may have an associated object. Al. A second parameter can be passed to Generate method, with a function that creates the associated object.

MakeIntegerConstantExpression job is:

– Get the object that was formed with the rule, in this case, a concatenated string with all digits were found.

– Transform it to integer

– Create a ConstantExpression with the intever as constant value.

The class ConstantExpression is not from GrammGen. It is defined by us. We have the freedom to define the objects we want to attach to each node of the GrammGen generated tree.

The code of MakeIntegerConstantExpression is:


   private static object MakeIntegerConstantExpression(object obj)
   {
       int value = int.Parse((string)obj);

       return new ConstantExpression(value);
   }

In the next posts we will see how the nodes of binary operations are formed, how operator precedence is implemented, how to manage left recursion, and evaluation of the generated expressions.

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez