Stringlang: an interpreted, Expression-oriented Language

StringLang

An interpreted, expression-oriented language where everything evaluates to strings.

Usage

Installation

You need Go to build the official interpreter from this repository.
Run go get github.com/skius/stringlang/cmd/stringlang to install the CLI on your machine.

CLI

Run StringLang programs using stringlang <program.stringlang> <arg0> <arg1> ..., or alternatively run the StringLang REPL by running stringlang with no arguments.

Running from code

To interpret StringLang code from your Go program, all you need is the following:

package main

import (
   "github.com/skius/stringlang"
   "os"
   "strconv"
)

func main() {
   source := `"Replace me with the " + "source code of your StringLang program"`
   expr, err := stringlang.Parse([]byte(source))
   if err != nil {
      panic(err)
   }
   // The built-in functions your StringLang program will have access to
   funcs := map[string]func([]string) string{
      "length": func(as []string) string { return strconv.Itoa(len(as[0])) },
      // Add more built-in functions here
   }
   // Arguments to your StringLang program
   args := os.Args
   ctx := stringlang.NewContext(args, funcs)
   result := expr.Eval(ctx)
}

See the CLI's main.go for a more advanced example.

Contributing

Feel free to open Issues and Pull Requests! The language specification and interpreter is by no means final. To change the syntax of the language, you'll need to modify lang.bnf and also ast/ast.go if you need new structures. Every time you change lang.bnf, you need to run gocc -o "./internal/frontend" -p "github.com/skius/internal/frontend" lang.bnf to generate the new parser and lexer.

Get the parser generator gocc used in this project from: goccmack/gocc

Example StringLang programs

See stringlang_programs/

Syntax

The following code block contains a simple (and not 100% correct, see Caveats section below the block) overview of what constitutes a StringLang source file. The complete grammar can be found in lang.bnf.

identifier: any string of alphanumeric and underscore characters not beginning with a digit
number: non-negative integer
string_literal: a "double-quoted" string, containing any sequence of characters, escapes allowed using '\'
comment: any text enclosed by /* and */, except '/*' and '*/' (no nested comments)


program:
     header block           

header:
    function1 function2 ... functionN                       // N may be 0  

function:
    fun identifier(param1, param2, ..., paramN) { block }   // paramX are identifiers, N may be 0

block:
    expression1; expression2; ...; expressionN              // no trailing semi-colon and N cannot be 0

expression:
    string_literal
    identifier
    identifier = expression
    $number
    expression[expression]
    expression[number]
    expression(expression1, expression2, ..., expressionN)  // N can be 0
    
    expression || expression
    expression && expression
    expression != expression
    expression == expression
    expression + expression
    
    (expression)
    
    ifelse
    while
    
    lambda
    
ifelse:
    if (expression) { block } else { block }
    if (expression) { block } else ifelse                   // This effectively allows else-if 
    
while:
    while (expression) { block }

lambda:
    fun(param1, param2, ..., paramN) { block }              // paramX are identifiers, N may be 0

Caveats

While the above description gives a good overview of StringLang, there are some important notes to be made:

  1. identifier = expression may only appear (but possibly repeated) at the beginning of an expression without parentheses, e.g. a = b = c = "foo";. Otherwise they need to be inside parentheses, e.g. "foo" + (a = c = "bar").
  2. A block is a non-empty, ; -separated list of expressions, with no trailing ;.
  3. A call (identifier(expr1, ..., exprN)) may also be without arguments, i.e. identifier()

Semantics

Values

All expressions/values in StringLang are Strings.

Functions

Functions in StringLang can either be user-defined (i.e. they are written in StringLang and reside as a top-level function in the header of the interpreted file, or are lambdas), or they can be built-in (i.e. supplied to the interpreter via the context). Because built-in functions are written in Go, they can accomplish anything Go can accomplish.

User-defined StringLang functions are evaluated with their own completely separate variable scope and are mutually recursive. The arguments passed to them are bound to the variables in the corresponding parameter lists.

All functions in StringLang are pass-by-value, hence also strict.

Calls

In a expr(args...) call, finding the function corresponding to expr has the following order:

  1. Check if expr is an identifier equal to some f and that there exists a top-level, user-defined function fun f(params) { block }, if so, call that function.
  2. Check if expr is an identifier equal to some f and that there exists a built-in function that is mapped to that f in the provided context, if so, call that.
  3. If expr is not an identifier with corresponding named function, then evaluate expr and treat the resulting String as source code of a lambda, then call that lambda.

Lambdas

Lambdas in StringLang capture their environment by-value, and encode it as simple assignments at the top of the block. Evaluating them (which is different to calling them) results in a canonical source representation of the lambda.

Example: The expression fun(x) { x + y } is evaluated differently depending on its context. In particular, the run-time value of the identifier y will be copied into the block, e.g. assuming y evaluates to "value" in the current context the lambda becomes: fun(x) { y = "value"; x + y }, a context-insensitive lambda. Now it can be evaluated into a String and returned:

"fun(x) {
   y = \"value\";
   x + y
}"

At the site of a call, this String can now be interpreted as the source code of a lambda, and called as such.
Note that because we stored the value of y inside the lambda, the context in which we call this "lambda-turned-String" does not matter.

Also note that lambdas are still user-defined functions, which are evaluated using a separate variable scope. Hence the y = "value" in the block will not cause the caller's y to be set to "value".

If you need more examples, see lambdas.stringlang or ski_combinator.stringlang to see how the SK-calculus looks like in StringLang.

Binary Operators

The following list gives the binary operators, ordered from low to high precedence:

||   Or              Interprets operands as booleans           
&&   And             Interprets operands as booleans  
!=   Not Equals      Compares the values of the operands
==   Equals          Compares the values of the operands
+    Concatenation   Concatenates the operands

Note:

  1. The boolean value of a StringLang value is true if and only if the String is not "" and not "false", else it is false.
  2. The StringLang value of a boolean result of a logic operation is always either "true" or "false"

Evaluation

string_literal ------------ The value of 'string_literal'
identifier ---------------- The current value of the variable with identifier 'identifier'.
identifier = expression --- The value of 'expression'. 
                            Side effect: Variable 'identifier' now has that value.
$number ------------------- The value of the 'number'-th (zero-indexed) argument to the program.
expr1[expr2 or number] ---- The character at position 'expr2' resp. 'number' of the value 
                            that 'expr1' evaluates to.
expr(expr1, ...) ---------- Function call to function 'expr' (See 'Functions' section) with arguments 'expr1, ...'.
                            Arguments are evaluated before passed to the function.
                            Evaluates to the function's return value.
expr1 <binop> expr2 ------- The value of the corresponding binary operation. 

ifelse -------------------- The value of the then-block if the condition evaluates to a true value,
                            or the value of the else-block if the condition evaluates to a false value.
while --------------------- The value of the last iteration of the block if it gets executed once, else "".
                            Side effects: All iterations might cause side effects
                            
lambda -------------------- The canonical source representation of the whole lambda as string, but with the blocks's
                            used variables captured by-value in the lambda.
                            
block --------------------- The value of the last expression in the block.
                            Side effects: Evaluates all expressions in the list.

Exceptions, errors, defaults

In the case of an invalid (out-of-bounds or NaN) character-access or argument expression, the returned value is always "". The values of all variables are initialized to "".

Context (functions and arguments)

To evaluate a StringLang program, the interpreter needs a stringlang.Context object. It contains fields which allow the interpreter's user to supply their custom built-in functions and arguments to the program. See cmd/stringlang/main.go for an example.

There is a channel available with context.GetExitChannel() for quickly killing the whole evaluation. Additionally, one can set the (approximate) maximum stack space in bytes the StringLang program is allowed to use with context.SetMaxStackSize(int) to a non-negative number. cmd/stringlang/main.go also contains examples for these two features.

Why?

It started out as a simple String builder using provided arguments (read: "my string".replace("$0", args[0])...) for a chat bot, which allowed generating new commands in-chat. After switching to a parsed grammar for some simple operators, I figured why not just make it Turing-complete. What could possibly go wrong allowing users to build their own commands...

Author: Skius
Source Code: https://github.com/skius/stringlang 
License: MIT license

#go #golang #language 

What is GEEK

Buddha Community

Stringlang: an interpreted, Expression-oriented Language
Ananya Gupta

Ananya Gupta

1594464365

Advantage of C Language Certification Online Training in 2020

C language is a procedural programming language. C language is the general purpose and object oriented programming language. C language is mainly used for developing different types of operating systems and other programming languages. C language is basically run in hardware and operating systems. C language is used many software applications such as internet browser, MYSQL and Microsoft Office.
**
Advantage of doing C Language Training in 2020 are:**

  1. Popular Programming language: The main Advantage of doing C language training in 2020 is popular programming language. C programming language is used and applied worldwide. C language is adaptable and flexible in nature. C language is important for different programmers. The basic languages that are used in C language is Java, C++, PHP, Python, Perl, JavaScript, Rust and C- shell.

  2. Basic language of all advanced languages: The another main Advantage of doing C language training in 2020 is basic language of all advanced languages. C language is an object oriented language. For learning, other languages, you have to master in C language.

  3. Understand the computer theories: The another main Advantage of doing C language training in 2020 is understand the computer theories. The theories such as Computer Networks, Computer Architecture and Operating Systems are based on C programming language.

  4. Fast in execution time: The another main Advantage of doing C language training in 2020 is fast in execution time. C language is to requires small run time and fast in execution time. The programs are written in C language are faster than the other programming language.

  5. Used by long term: The another main Advantage of doing C language training in 2020 is used by long term. The C language is not learning in the short span of time. It takes time and energy for becoming career in C language. C language is the only language that used by decades of time. C language is that exists for the longest period of time in computer programming history.

  6. Rich Function Library: The another main Advantage of doing C language training in 2020 is rich function library. C language has rich function of libraries as compared to other programming languages. The libraries help to build the analytical skills.

  7. Great degree of portability: The another main Advantage of doing C language training in 2020 is great degree of portability. C is a portable assemble language. It has a great degree of portability as compilers and interpreters of other programming languages are implemented in C language.
    The demand of C language is high in IT sector and increasing rapidly.

C Language Online Training is for individuals and professionals.
C Language Online Training helps to develop an application, build operating systems, games and applications, work on the accessibility of files and memory and many more.

C Language Online Course is providing the depth knowledge of functional and logical part, develop an application, work on memory management, understanding of line arguments, compiling, running and debugging of C programs.

Is C Language Training Worth Learning for You! and is providing the basic understanding of create C applications, apply the real time programming, write high quality code, computer programming, C functions, variables, datatypes, operators, loops, statements, groups, arrays, strings, etc.

The companies which are using C language are Amazon, Martin, Apple, Samsung, Google, Oracle, Nokia, IBM, Intel, Novell, Microsoft, Facebook, Bloomberg, VM Ware, etc.
C language is used in different domains like banking, IT, Insurance, Education, Gaming, Networking, Firmware, Telecommunication, Graphics, Management, Embedded, Application Development, Driver level Development, Banking, etc.

The job opportunities after completing the C Language Online certificationAre Data Scientists, Back End Developer, Embedded Developer, C Analyst, Software Developer, Junior Programmer, Database Developer, Embedded Engineer, Programming Architect, Game Programmer, Quality Analyst, Senior Programmer, Full Stack Developer, DevOps Specialist, Front End Web Developer, App Developer, Java Software Engineer, Software Developer and many more.

#c language online training #c language online course #c language certification online #c language certification #c language certification course #c language certification training

Ananya Gupta

Ananya Gupta

1599550659

Benefits Of C Language Over Other Programming Languages

C may be a middle-level programing language developed by Dennis Ritchie during the first 1970s while performing at AT&T Bell Labs within the USA. the target of its development was within the context of the re-design of the UNIX OS to enable it to be used on multiple computers.

Earlier the language B was now used for improving the UNIX. Being an application-oriented language, B allowed a much faster production of code than in programming language. Still, B suffered from drawbacks because it didn’t understand data-types and didn’t provide the utilization of “structures”.

These drawbacks became the drive for Ritchie for the development of a replacement programing language called C. He kept most of the language B’s syntax and added data-types and lots of other required changes. Eventually, C was developed during 1971-73, containing both high-level functionality and therefore the detailed features required to program an OS. Hence, many of the UNIX components including the UNIX kernel itself were eventually rewritten in C.

Benefits of C language

As a middle-level language, C combines the features of both high-level and low-level languages. It is often used for low-level programmings, like scripting for it also supports functions of high-level C programming languages, like scripting for software applications, etc.
C may be a structured programing language that allows a posh program to be broken into simpler programs called functions. It also allows free movement of knowledge across these functions.

Various features of C including direct access to machine level hardware APIs, the presence of C compilers, deterministic resource use, and dynamic memory allocation make C language an optimum choice for scripting applications and drivers of embedded systems.

C language is case-sensitive which suggests lowercase and uppercase letters are treated differently.
C is very portable and is employed for scripting system applications which form a serious a part of Windows, UNIX, and Linux OS.

C may be a general-purpose programing language and may efficiently work on enterprise applications, games, graphics, and applications requiring calculations, etc.
C language features a rich library that provides a variety of built-in functions. It also offers dynamic memory allocation.

C implements algorithms and data structures swiftly, facilitating faster computations in programs. This has enabled the utilization of C in applications requiring higher degrees of calculations like MATLAB and Mathematica.

Riding on these advantages, C became dominant and spread quickly beyond Bell Labs replacing many well-known languages of that point, like ALGOL, B, PL/I, FORTRAN, etc. C language has become available on a really wide selection of platforms, from embedded microcontrollers to supercomputers.

#c language online training #c language training #c language course #c language online course #c language certification course

Stringlang: an interpreted, Expression-oriented Language

StringLang

An interpreted, expression-oriented language where everything evaluates to strings.

Usage

Installation

You need Go to build the official interpreter from this repository.
Run go get github.com/skius/stringlang/cmd/stringlang to install the CLI on your machine.

CLI

Run StringLang programs using stringlang <program.stringlang> <arg0> <arg1> ..., or alternatively run the StringLang REPL by running stringlang with no arguments.

Running from code

To interpret StringLang code from your Go program, all you need is the following:

package main

import (
   "github.com/skius/stringlang"
   "os"
   "strconv"
)

func main() {
   source := `"Replace me with the " + "source code of your StringLang program"`
   expr, err := stringlang.Parse([]byte(source))
   if err != nil {
      panic(err)
   }
   // The built-in functions your StringLang program will have access to
   funcs := map[string]func([]string) string{
      "length": func(as []string) string { return strconv.Itoa(len(as[0])) },
      // Add more built-in functions here
   }
   // Arguments to your StringLang program
   args := os.Args
   ctx := stringlang.NewContext(args, funcs)
   result := expr.Eval(ctx)
}

See the CLI's main.go for a more advanced example.

Contributing

Feel free to open Issues and Pull Requests! The language specification and interpreter is by no means final. To change the syntax of the language, you'll need to modify lang.bnf and also ast/ast.go if you need new structures. Every time you change lang.bnf, you need to run gocc -o "./internal/frontend" -p "github.com/skius/internal/frontend" lang.bnf to generate the new parser and lexer.

Get the parser generator gocc used in this project from: goccmack/gocc

Example StringLang programs

See stringlang_programs/

Syntax

The following code block contains a simple (and not 100% correct, see Caveats section below the block) overview of what constitutes a StringLang source file. The complete grammar can be found in lang.bnf.

identifier: any string of alphanumeric and underscore characters not beginning with a digit
number: non-negative integer
string_literal: a "double-quoted" string, containing any sequence of characters, escapes allowed using '\'
comment: any text enclosed by /* and */, except '/*' and '*/' (no nested comments)


program:
     header block           

header:
    function1 function2 ... functionN                       // N may be 0  

function:
    fun identifier(param1, param2, ..., paramN) { block }   // paramX are identifiers, N may be 0

block:
    expression1; expression2; ...; expressionN              // no trailing semi-colon and N cannot be 0

expression:
    string_literal
    identifier
    identifier = expression
    $number
    expression[expression]
    expression[number]
    expression(expression1, expression2, ..., expressionN)  // N can be 0
    
    expression || expression
    expression && expression
    expression != expression
    expression == expression
    expression + expression
    
    (expression)
    
    ifelse
    while
    
    lambda
    
ifelse:
    if (expression) { block } else { block }
    if (expression) { block } else ifelse                   // This effectively allows else-if 
    
while:
    while (expression) { block }

lambda:
    fun(param1, param2, ..., paramN) { block }              // paramX are identifiers, N may be 0

Caveats

While the above description gives a good overview of StringLang, there are some important notes to be made:

  1. identifier = expression may only appear (but possibly repeated) at the beginning of an expression without parentheses, e.g. a = b = c = "foo";. Otherwise they need to be inside parentheses, e.g. "foo" + (a = c = "bar").
  2. A block is a non-empty, ; -separated list of expressions, with no trailing ;.
  3. A call (identifier(expr1, ..., exprN)) may also be without arguments, i.e. identifier()

Semantics

Values

All expressions/values in StringLang are Strings.

Functions

Functions in StringLang can either be user-defined (i.e. they are written in StringLang and reside as a top-level function in the header of the interpreted file, or are lambdas), or they can be built-in (i.e. supplied to the interpreter via the context). Because built-in functions are written in Go, they can accomplish anything Go can accomplish.

User-defined StringLang functions are evaluated with their own completely separate variable scope and are mutually recursive. The arguments passed to them are bound to the variables in the corresponding parameter lists.

All functions in StringLang are pass-by-value, hence also strict.

Calls

In a expr(args...) call, finding the function corresponding to expr has the following order:

  1. Check if expr is an identifier equal to some f and that there exists a top-level, user-defined function fun f(params) { block }, if so, call that function.
  2. Check if expr is an identifier equal to some f and that there exists a built-in function that is mapped to that f in the provided context, if so, call that.
  3. If expr is not an identifier with corresponding named function, then evaluate expr and treat the resulting String as source code of a lambda, then call that lambda.

Lambdas

Lambdas in StringLang capture their environment by-value, and encode it as simple assignments at the top of the block. Evaluating them (which is different to calling them) results in a canonical source representation of the lambda.

Example: The expression fun(x) { x + y } is evaluated differently depending on its context. In particular, the run-time value of the identifier y will be copied into the block, e.g. assuming y evaluates to "value" in the current context the lambda becomes: fun(x) { y = "value"; x + y }, a context-insensitive lambda. Now it can be evaluated into a String and returned:

"fun(x) {
   y = \"value\";
   x + y
}"

At the site of a call, this String can now be interpreted as the source code of a lambda, and called as such.
Note that because we stored the value of y inside the lambda, the context in which we call this "lambda-turned-String" does not matter.

Also note that lambdas are still user-defined functions, which are evaluated using a separate variable scope. Hence the y = "value" in the block will not cause the caller's y to be set to "value".

If you need more examples, see lambdas.stringlang or ski_combinator.stringlang to see how the SK-calculus looks like in StringLang.

Binary Operators

The following list gives the binary operators, ordered from low to high precedence:

||   Or              Interprets operands as booleans           
&&   And             Interprets operands as booleans  
!=   Not Equals      Compares the values of the operands
==   Equals          Compares the values of the operands
+    Concatenation   Concatenates the operands

Note:

  1. The boolean value of a StringLang value is true if and only if the String is not "" and not "false", else it is false.
  2. The StringLang value of a boolean result of a logic operation is always either "true" or "false"

Evaluation

string_literal ------------ The value of 'string_literal'
identifier ---------------- The current value of the variable with identifier 'identifier'.
identifier = expression --- The value of 'expression'. 
                            Side effect: Variable 'identifier' now has that value.
$number ------------------- The value of the 'number'-th (zero-indexed) argument to the program.
expr1[expr2 or number] ---- The character at position 'expr2' resp. 'number' of the value 
                            that 'expr1' evaluates to.
expr(expr1, ...) ---------- Function call to function 'expr' (See 'Functions' section) with arguments 'expr1, ...'.
                            Arguments are evaluated before passed to the function.
                            Evaluates to the function's return value.
expr1 <binop> expr2 ------- The value of the corresponding binary operation. 

ifelse -------------------- The value of the then-block if the condition evaluates to a true value,
                            or the value of the else-block if the condition evaluates to a false value.
while --------------------- The value of the last iteration of the block if it gets executed once, else "".
                            Side effects: All iterations might cause side effects
                            
lambda -------------------- The canonical source representation of the whole lambda as string, but with the blocks's
                            used variables captured by-value in the lambda.
                            
block --------------------- The value of the last expression in the block.
                            Side effects: Evaluates all expressions in the list.

Exceptions, errors, defaults

In the case of an invalid (out-of-bounds or NaN) character-access or argument expression, the returned value is always "". The values of all variables are initialized to "".

Context (functions and arguments)

To evaluate a StringLang program, the interpreter needs a stringlang.Context object. It contains fields which allow the interpreter's user to supply their custom built-in functions and arguments to the program. See cmd/stringlang/main.go for an example.

There is a channel available with context.GetExitChannel() for quickly killing the whole evaluation. Additionally, one can set the (approximate) maximum stack space in bytes the StringLang program is allowed to use with context.SetMaxStackSize(int) to a non-negative number. cmd/stringlang/main.go also contains examples for these two features.

Why?

It started out as a simple String builder using provided arguments (read: "my string".replace("$0", args[0])...) for a chat bot, which allowed generating new commands in-chat. After switching to a parsed grammar for some simple operators, I figured why not just make it Turing-complete. What could possibly go wrong allowing users to build their own commands...

Author: Skius
Source Code: https://github.com/skius/stringlang 
License: MIT license

#go #golang #language 

Cayla  Erdman

Cayla Erdman

1594369800

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Models for SQL exist. In any case, the SQL that can be utilized on every last one of the major RDBMS today is in various flavors. This is because of two reasons:

1. The SQL order standard is genuinely intricate, and it isn’t handy to actualize the whole standard.

2. Every database seller needs an approach to separate its item from others.

Right now, contrasts are noted where fitting.

#programming books #beginning sql pdf #commands sql #download free sql full book pdf #introduction to sql pdf #introduction to sql ppt #introduction to sql #practical sql pdf #sql commands pdf with examples free download #sql commands #sql free bool download #sql guide #sql language #sql pdf #sql ppt #sql programming language #sql tutorial for beginners #sql tutorial pdf #sql #structured query language pdf #structured query language ppt #structured query language

How to Upload and Store Images in MySQL using Node.js and Express

Today we are going to explore the basic usage of Express-FileUpload. In addition to this, I will show you how you can save/update a user record with a profile image that you can upload.

Chapters:
0:00 Introduction:
1:16 NPM Project Setup
3:54 Creating Express Server
5:51 Setting up Layouts & Routes
9:46 Express Upload Form
21:50 User Card
33:40 Database
52:05 Ending

Source Files:
https://raddy.co.uk/blog/upload-and-store-images-in-mysql-using-node-js-express-express-fileupload-express-handlebars/

#node.js #express #express-fileupload #express-handlebars #mysql #upload and store images