https://github.com/blankeos/c-parser
🤓 A proglang parser demonstrating lexical analysis and syntax analysis implemented in C#.
https://github.com/blankeos/c-parser
Last synced: about 1 year ago
JSON representation
🤓 A proglang parser demonstrating lexical analysis and syntax analysis implemented in C#.
- Host: GitHub
- URL: https://github.com/blankeos/c-parser
- Owner: Blankeos
- Created: 2022-12-02T21:18:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-06T12:43:07.000Z (over 3 years ago)
- Last Synced: 2025-02-13T08:52:00.757Z (over 1 year ago)
- Language: C#
- Size: 8.8 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🤓 The "Carlo" Parser in C#

A programming language parser implemented in C# as a final requirement for my CCS 238 Programming Languages class for **Dr. Felipe P. Vista IV**.
This program parses an "almost C/C++"-like programming language called `Carlo`.
It demonstrates compiler design theory from:
```
Scanner (Lexical Analysis) -> Parser (Syntax Analysis)
```
```
Written by:
- 🤓 Carlo Antonio T. Taleon
- 👧 Glecy S. Elizalde
- 🤠 Christopher Joseph T. Rubinos
- 💻 Jesmar Tolato
```
## Get Started
> Make sure to install [.Net SDK](https://dotnet.microsoft.com/en-us/download) if you haven't yet
1. Clone this repo and change your directory
```sh
# >
git clone https://github.com/Blankeos/cs-parser
cd cs-parser
# cs-parser>
```
2. Put your **inputs** inside `input.carlo`.
3. Run the project in your terminal
```sh
# cs-parser>
dotnet run
```
4. _Optional_: Build to `.dll` or `.exe` and run either
```sh
dotnet build # this command is already ran when you `dotnet run`
dotnet ./bin/Debug/net6.0/CParser.dll # opens .dll
./bin/Debug/net6.0/CParser.exe
```
5. Open `output.carlo` to check the **output**!
## Introducing: The 🤓 "Carlo" Programming Language
It's an "almost C/C++"-like language made for our programming languages class. As the name suggests, it has similar syntax to C/C++.
### Example usage
```c#
/* ----------input.carlo---------- */
boolean fMusta(char aNgaln[15], int num) {
Printf("Hello world!! Si '%s' na ewan ito! Pang-%d \n ::) \r",aNgaln, &num);
if (num!= len(aNgaln)) {return true;} else {printf("\r\n Tsamba!! \n"); return false;}
return ;}
/* ---------output.carlo---------- */
boolean fMusta(char aNgaln[15], int num)
{
Printf("Hello world!! Si '%s' na ewan ito! Pang-%d \n ::) \r", aNgaln, &num);
if (num!=len(aNgaln))
{
return true;
}
else
{
printf("\r\n Tsamba!! \n");
return false;
}
return;
}
/*
Lexed (52) tokens
```
### Grammar
```
Program -> Node*
Node :: FunctionDef | Assign | FunctionCall | IfStatement;
FunctionDef :: DataType Identifier FunctionArgs FunctionBody;
DataType :: 'boolean' | 'int' | 'string' | 'char';
Identifier :: 'identifier';
FunctionArgs ::
| '(' DataType Identifier [',' DataType Identifier]* ')'
;
Assign ::
| AssignInt | AssignChar | AssignBoolean | AssignString
;
AssignInt ::
| 'int'? Identifier '=' [Int | Identifier]
;
AssignChar ::
| 'char'? Identifier '=' [Char | Identifier]
;
AssignBoolean ::
| 'boolean'? Identifier '=' [Boolean | Identifier]
;
AssignString ::
| 'string'? Identifier '=' [String | Identifier]
;
IF STATEMENT ::
| 'if' '(' BooleanExpression | Identifier ')'
BooleanExpression ::
| NUMBER '==' |
```