KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
Persian-Compiler
★ 12
Open GitHub ↗
~ Just Another Persian Compiler
Download README (.md)
Explore Similar Repositories
longitudinal-notebooks
:
No description available.
shopping-list-app
:
[WIP] Shopping List App. Created during the Girl Develop It Hackathon at Audible.
automl-genetic
:
Applying genetic programming to AutoML https://travis-ci.org/deil87/automl-genetic.svg?branch=master
blur_desktop
:
纯html实现类似mac os 动态高斯模糊效果
SharedSequence.kt
:
No description available.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
Persian-Compiler
?
Download (.md)
[](https://hits.seeyoufarm.com) # Persian Compiler — کامپایلر فارسی A compiler for a **Persian-syntax programming language**, built with Flex and Bison. Source programs are written entirely in Persian script (including keywords, identifiers, and numerals), and the compiler produces intermediate C code via a quadruple-based intermediate representation. --- ## Features - **Full Persian keyword set** — all reserved words are valid Persian words - **Persian & ASCII numerals** — mix `۱۲۳` and `123` freely - **Persian & ASCII punctuation** — semicolons (`؛`/`;`), commas (`،`/`,`), and question marks (`؟`/`?`) - **Four primitive types** — integer, real, character, boolean - **Structs, global/local variables, constants, and arrays** - **Functions** with typed parameters and return values - **Control flow** — if/else, while, switch/case/default - **Rich operator set** — arithmetic, relational, logical, assignment shortcuts, increment/decrement - **Intermediate code generation** — outputs a valid C file (`generatedCode.c`) that can be compiled with any C compiler - **Parse trace** — writes grammar rule reductions to `output.txt` for debugging --- ## Language Overview ### Keywords | Persian | English equivalent | |---|---| | `برنامه` | `program` (entry point declaration) | | `ساختار` | `struct` | | `ثابت` | `const` | | `صحیح` | `int` | | `اعشاری` | `real` / `float` | | `حرف` | `char` | | `منطقی` | `bool` | | `درست` | `true` | | `غلط` | `false` | | `اگر` | `if` | | `آنگاه` | `then` | | `وگرنه` | `else` | | `کلید` | `switch` | | `حالت` | `case` | | `پیشفرض` | `default` | | `تمام` | `end` (closes a switch block) | | `وقتی` | `while` | | `برگردان` | `return` | | `بشکن` | `break` | | `و` | `and` (`&&`) | | `یا` | `or` (`\|\|`) | | `یاوگرنه` | `xor` | | `وهمچنین` | `also` (short-circuit and) | | `خلاف` | `not` (`!`) | ### Operators | Category | Operators | |---|---| | Arithmetic | `+` `-` `*` `/` `%` | | Relational | `<` `>` `<=` `>=` `==` | | Assignment | `=` `+=` `-=` `*=` `/=` | | Increment / Decrement | `++` `--` | | Unary | `-` (negation) `*` (array length) `؟`/`?` (random element) | --- ## Code Examples ### Hello, Factorial ``` برنامه فاکتوریل صحیح محاسبه_فاکتوریل (صحیح عدد) { اگر عدد < ۰ آنگاه برگردان -۱؛ وگرنه اگر عدد == ۱ آنگاه برگردان ۱؛ وگرنه { صحیح قبلی = محاسبه_فاکتوریل (عدد - ۱)؛ برگردان قبلی * عدد؛ } } صحیح اصلی () { صحیح نتیجه = محاسبه_فاکتوریل(۵)؛ } ``` ### While Loop & Switch/Case ``` برنامه جمله صحیح اصلی () { صحیح کنترلگر = ۱۰؛ صحیح مقدار = ۱؛ وقتی (درست) { اگر کنترلگر < ۰ آنگاه بشکن؛ وگرنه { مقدار *= کنترلگر؛ کنترلگر--؛ } } صحیح عملگر = ۲؛ اعشاری اول = ۲.۵؛ صحیح دوم = ۴؛ کلید (عملگر) حالت ۱: { اول += دوم؛ بشکن؛ }؛ حالت ۲: { اول = اول - دوم؛ بشکن؛ }؛ پیشفرض: اول = ۰؛ تمام } ``` ### Structs ``` برنامه من ساختار ماهی { ثابت صحیح آ = ۲۳؛ اعشاری ب = ۰.۰۳؛ حرف ث = 'آ'؛ منطقی ت = درست؛ } ``` --- ## Prerequisites | Tool | Purpose | |---|---| | [Flex](https://github.com/westes/flex) | Lexer generator | | [Bison](https://www.gnu.org/software/bison/) | Parser generator | | `clang++` (C++14) or `g++` | Compiles the generated scanner and parser | Install on Debian/Ubuntu: ```bash sudo apt-get install flex bison clang ``` --- ## Build & Usage ```bash # Build the compiler and run it against input.txt make # Clean all generated files make clean # Build with verbose parser output (parser.output) make debug ``` The compiler reads from **`input.txt`** and produces: | Output file | Contents | |---|---| | `output.txt` | Grammar rule trace (one line per reduction) | | `generatedCode.c` | Intermediate C code ready to compile | To execute the generated program: ```bash clang generatedCode.c -o program && ./program ``` --- ## Project Structure ``` Persian-Compiler/ ├── lex.lex # Flex lexer — tokenises Persian source code ├── parser.y # Bison parser — grammar rules + intermediate code generation ├── llist.h # Linked-list header (used for backpatching) ├── llist.cpp # Linked-list implementation ├── Makefile # Build rules ├── input.txt # Sample program (main test input) ├── expression.txt # Sample: expressions and arrays ├── function.txt # Sample: functions and structs └── statement.txt # Sample: control-flow statements ``` --- ## How It Works ``` Persian source (.txt) │ ▼ Lexer (Flex) lex.lex — converts Persian text to tokens, │ handles both Persian & ASCII digits/punctuation ▼ Parser (Bison) parser.y — validates grammar, builds symbol table, │ emits quadruples (4-tuple intermediate representation) ▼ Code Generator parser.y — translates quadruples to C statements, │ writes generatedCode.c ▼ generatedCode.c — standard C file, compilable with clang/gcc ``` The intermediate representation uses **quadruples** of the form `(operation, arg1, arg2, result)`, covering arithmetic, comparisons, control-flow jumps, array access, type casts, and print helpers.