Skip to content

Commit

Permalink
Added README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NLTN committed Mar 30, 2024
1 parent f334340 commit 6ec9340
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
# Rat24S Compiler
A compiler for Rat24S language is designed to be an easy to understand. It has a short grammar and relatively clean semantics.

#### Test Case 1
## Usage
Here is a simple example of checking a source code file for syntax errors, and print out to the console all the production rules used during syntax analyzing:
```bash
python3 main.py test_case_1.txt output_1.txt
python3 rat24s.py input.txt -o output.txt -v
```
**Optional arguments**
The Rat24S compiler has many options for reading input from a file, writing output to a file, extracting the tokens, and checking your code syntax.
|Flag|Full tag|Description|
|--|--|--|
|`-o`|`--output`|Output file path.|
|`-t`|`--tokens`|Extract tokens only, but don't do anything beyond that.|
|`-v`|`--verbose`|Enable verbose mode.|

#### Test Case 2
```bash
python3 main.py test_case_2.txt output_2.txt
# Documentations
#### High level diagram
```mermaid
graph LR
START:::hidden -- source code--> LA[Lexical Analyzer]
LA--tokens-->SA[Syntax Analyzer]
SA-->T((Correct))
SA-->F((Error))
classDef hidden display: none;
```
#### Grammar Rules
```
R1. <Rat24S> ::= $ <Opt Function Definitions> $ <Opt Declaration List> $ <Statement List> $
R2. <Opt Function Definitions> ::= <Function Definitions> | <Empty>
R3. <Function Definitions> ::= <Function> | <Function> <Function Definitions>
R4. <Function> ::= function <Identifier> ( <Opt Parameter List> ) <Opt Declaration List> <Body>
R5. <Opt Parameter List> ::= <Parameter List> | <Empty>
R6. <Parameter List> ::= <Parameter> | <Parameter> , <Parameter List>
R7. <Parameter> ::= <IDs > <Qualifier>
R8. <Qualifier> ::= integer | boolean | real
R9. <Body> ::= { < Statement List> }
R10. <Opt Declaration List> ::= <Declaration List> | <Empty>
R11. <Declaration List> := <Declaration> ; | <Declaration> ; <Declaration List>
R12. <Declaration> ::= <Qualifier > <IDs>
R13. <IDs> ::= <Identifier> | <Identifier>, <IDs>
R14. <Statement List> ::= <Statement> | <Statement> <Statement List>
R15. <Statement> ::= <Compound> | <Assign> | <If> | <Return> | <Print> | <Scan> | <While>
R16. <Compound> ::= { <Statement List> }
R17. <Assign> ::= <Identifier> = <Expression> ;
R18. <If> ::= if ( <Condition> ) <Statement> endif | if ( <Condition> ) <Statement> else <Statement> endif
R19. <Return> ::= return ; | return <Expression> ;
R20. <Print> ::= print ( <Expression>);
R21. <Scan> ::= scan ( <IDs> );
R22. <While> ::= while ( <Condition> ) <Statement> endwhile
R23. <Condition> ::= <Expression> <Relop> <Expression>
R24. <Relop> ::= == | != | > | < | <= | =>
R25. <Expression> ::= <Expression> + <Term> | <Expression> - <Term> | <Term>
R26. <Term> ::= <Term> * <Factor> | <Term> / <Factor> | <Factor>
R27. <Factor> ::= - <Primary> | <Primary>
R28. <Primary> ::= <Identifier> | <Integer> | <Identifier> ( <IDs> ) | ( <Expression> ) |
<Real> | true | false
R29. <Empty> ::= ε
```

#### Test Case 3
```bash
python3 main.py test_case_3.txt output_3.txt
```
# License
This project is licensed under the MIT license - see the [LICENSE.md](LICENSE.md) file for details.

0 comments on commit 6ec9340

Please sign in to comment.