https://github.com/gustavoaca1997/basic-tran-interpreter
Un interpretador de BasicTran
https://github.com/gustavoaca1997/basic-tran-interpreter
alex grammar happy haskell interpreted-programming-language interpreter lexer parser
Last synced: 8 months ago
JSON representation
Un interpretador de BasicTran
- Host: GitHub
- URL: https://github.com/gustavoaca1997/basic-tran-interpreter
- Owner: gustavoaca1997
- License: bsd-3-clause
- Created: 2018-06-27T03:45:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-26T03:57:55.000Z (over 6 years ago)
- Last Synced: 2025-07-02T21:02:47.573Z (8 months ago)
- Topics: alex, grammar, happy, haskell, interpreted-programming-language, interpreter, lexer, parser
- Language: Haskell
- Homepage: https://tintin.glitch.me/5932
- Size: 252 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README-en.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic-Translation Interpreter
[Language specifications](https://drive.google.com/file/d/1Lsapac7c9lrTpRm5uTsGvMoeMd34Oorf/view?usp=sharing)
## Members:
* German Robayo (14-10924)
* Gustavo Castellanos (14-10192)
## Parts of the interpreter
### Lexer
#### What is it?
A lexer is a tool that allows us to analyze a sequence of characters and extract _tokens_ from it (lexicographic analysis) for its subsequent parsing.
#### Tool used
It was used as a programming language *__Haskell__* and as a generator tool for lexicographical analyzers *__Alex__*.
The use of Alex was fundamental, as we focused on only determining regular expressions to extract the tokens from the file.
#### Brief explanation
Alex provides several wrappers, but the one of our interest was `posn` because it provides the same functionality as the` basic` but adding the column and row of each detected token.
To implement the `show` of each token, a type of data` TkObject` was created that can be seen as an ordered pair whose first coordinate is a token and the second is its `AlexPosn`. Thus, it was avoided having to write a `show` for each token.
To filter errors, a token called `TkErr` was created. When we invoke `alexScanTokens` we have an array of `TkObject`'s. To see if there is an error, we only filter the TkObjects and if the resulting array is empty, there are no errors and each token is printed in the described format. Otherwise, only errors are printed.
#### Additional libraries
None. Although certain functions could be imported, it was decided, to practice the language more, that we ourselves implement those functions.
## Parser
### What is it?
A perser is a computer program that analyzes a string of symbols (syntactically) according to the rules of a formal grammar.
#### Tool used
It was used as programming language *__Haskell__* and as a parser generating tool *__Happy__*.
The use of Happy focused us only on determining the grammar of the language.
#### Brief explanation
Through Happy, the grammar that defines the BasicTrans language was formed. This had to be modified during the development of the parser to eliminate conflicts _shift/reduce_ and _reduce/reduce_.
A `Parsed` data type was defined, which instantiates the` Monad` typeclass, in order to know if an error occurred or not while parsing.
The `ToStr` typeclass was defined, so that the Abstract Syntactic Tree could be printed on the console, which is instantiated by the types of data that define the analyzed tokens.
## Use of the interpreter
To compile the interpreter:
```bash
stack build
```
To run the interpreter:
```bash
stack exec BasicTran-Interpreter-exe
```