Download the PHP package railt/compiler without Composer

On this page you can find all versions of the php package railt/compiler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package compiler

Railt

Travis CI

PHP 7.1+ railt.org Discord Latest Stable Version Total Downloads License MIT

Compiler

This is the implementation of the so-called compiler-compiler based on the basic capabilities of Hoa\Compiler.

The library is needed to create parsers from grammar files and is not used during the parsing itself, this is only required for development.

Before you begin to work with custom implementations of parsers, it is recommended that you review the EBNF

Grammar

Each language consists of words that are added to sentences. And for the correct construction of the proposal, some rules are needed. Such rules are called grammar.

Let's try to create the corresponding grammar for the calculator, which can add two numbers. If you are familiar with alternative grammars (Antlr, BNF, EBNF, Hoa, etc.), then it will not be difficult for you.

The grammar of Railt is partly different from the original EBNF. In this way, let's restructure the same rule into the grammar of the Railt.

In order to test the performance simply use the reading and playing grammar on the fly!

On the output you will take an AST, which will be serialized in XML by the echo operator and which will look like this:

The naming register does not matter, but it is recommended that you name the tokens in upper case ("TOKEN_NAME"), and the rules with a capital letter ("RuleName"). Such recommendations will help you in the future easier to navigate in the existing grammar.

Definitions

In the Railt grammar there are 5 types of definitions:

Comments

In the Railt grammar, there are two types of C-like commentaries:

1) // Inline comment - This comment type begins with two slashes and ends with an end of the line. 2) /* Multiline comment */ - This comment type begins with /* symbols and ends with a */ symbol.

Output Control

You probably already noticed that in grammar, the definitions of tokens look a little different: <TOKEN> and ::TOKEN::.

This way of determining the tokens inside the grammar tells the compiler whether to print the ordered token as a result or not. It is for this reason that the token "plus" was ignored, because We do not need information about this token, but the values of "digit" tokens are important to us.

1) <TOKEN> - Keep token in AST. 2) ::TOKEN:: - Hide token from AST.

Declaring rules

Each rule starts with the name of this rule. In addition, each rule can be marked with a # symbol that indicates that the rule should be kept in the AST.

1) #Rule - The defined rule must be present in the AST. 2) Rule - The defined rule should be hide from AST.

After the name there is a production (body) of this rule, which are separated by one of the valid characters: = or :. The separator character does not matter and is present as compatibility with other grammars. In addition, the rule can end with an optional ; char.

The constructions of the PP2 language are the following:

Finally, the grammar of the PP2 language is written with the PP2 language.

Let's try to add support for the remaining symbols of the calculator: Moderation, Division and Subtraction; and at the same time slightly improve the rules of the lexer.

Simple expression 4 + 8 - 15 * 16 / 23 + -42 will be parsed into the followed tree:

Note that the grammar is quite trivial and does not contain the priorities of the operators.

Delegation

You can tell the compiler which php class to include the desired grammar rule using keyword -> after name of rule definition. In this case, each processed rule will create an instance of target class.

For more information about delegates, use the Parser documentation.

Parser compilation

Reading a grammar is quite simple operation, but it still takes time to execute. After the grammar rules have been formulated, you can "fix" the version in a separate parser class that will contain all the logic and no longer require reading the source code. After you compile it into a class, this package (railt/compiler) can be excluded from composer dependencies.

This code example will create a parser class in the current directory with the required class and namespace names. An example of the result of generation can be found in an existing project here. As a source, this grammar file.


All versions of compiler with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.3
ext-json Version *
ext-mbstring Version *
ext-pcre Version *
ext-spl Version *
railt/io Version ~1.3.0|1.3.x-dev
railt/lexer Version ~1.3.0|1.3.x-dev
railt/parser Version ~1.3.5|1.3.x-dev
zendframework/zend-code Version ~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package railt/compiler contains the following files

Loading the files please wait ....