Skip to content

Commit

Permalink
doc: add developer guide
Browse files Browse the repository at this point in the history
  • Loading branch information
mykeels committed Jan 2, 2019
1 parent 59946ab commit 67b7dce
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ yorl sample/test.yl

You should get something like: ``báwo ni ayé``

## Developer Guide

For Developers, [these docs](./src/README.md) will help you understand Yorlang's internal architecture, should you wish to make adjustments.

## Unit and Integration Tests

To run tests in the project, run the following in your terminal:
Expand Down
63 changes: 63 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Developer Guide

Yorlang is an interpreted programming language built on NodeJS.

When you run `yorl <file>.yl` in your terminal, the `yorl` command is handled by the [cli.js](../cli.js) file, which uses [commander](https://www.npmjs.com/package/commander) to start the Yorlang interpreter, which performs the following actions:

## InputStream

The file path is passed into the [InputStream](./inputstream.js) instance, which reads the file's contents as a string.

An InputStream contains methods such as `next`, `peek` and `isEndOfFile`.

### - next()

It maintains a cursor position which begins at the beginning of the file, and everytime `next()` is called, the character immediately after the cursor is returned, and the cursor moved one-char forward.

> This [repl](https://repl.it/@mykeels/yl-input-stream-next-demo) shows how InputStream's `next()` works.
### - peek()

Rather than update the cursor position, the `peek()` function returns the character immediately after the cursor, and keeps its position the same.

### - isEndOfFile()

This returns a boolean value when the cursor has reached the end of the input file.

> This [repl](https://repl.it/@mykeels/yl-input-stream-peek-demo) shows how InputStream's `peek()` and `isEndOfFile()` work.
## Lexical Analyser

The [Lexer](./lexer.js) instance accepts an InputStream as an argument, and attempts to read each character, and recognise token such as identifiers, operators, keywords, and numbers.

A Lexer contains methods such as:

### - readWhile(predicate)

This will retrieve the next characters from the InputStream until a character is found that does not match the condition given by a predicate function.

> `readWhile((c) => c != ";")` will read characters until either one of them matches `";"`, or the end of the file is reached.
### - readNext()

This makes sure to skip whitespaces and comments, and depending on the nature of a character read, it calls and returns other methods such as:

### - readString()

This is called by `readNext()` when a quote character is found. It will attempt to read the characters until a closing quote is found.

### - readNumber()

This is called by `readNext()` when a digit is found. It will attempt to read a valid number (including dots), until no more digits can be found.

### - readIdentifier()

This is called by `readNext()` when a character is found that matches the `constants.REGEX.IDENTIFIER` regex pattern. It will attempt to read subsequent characters that match the pattern, till either one is found that does not, or the end of file is reached.

### - isPunctuation()

This determines whether a character read is a punctuation. The list of punctuations can be found in `constants.LIST.PUNCTUATIONS`.

### - isOperator()

This determines whether a character read is an operator. The list of operators can be found in `constants.LIST.OPERATORS`.

0 comments on commit 67b7dce

Please sign in to comment.