项目作者: daniel-shimon

项目描述 :
Rashi Plus Plus - the new Hebrew scripting language
高级语言: C++
项目地址: git://github.com/daniel-shimon/rpp.git
创建时间: 2018-01-28T11:05:40Z
项目社区:https://github.com/daniel-shimon/rpp

开源协议:MIT License

下载


Rashi Plus Plus (RPP) - The New Hebrew Scripting Language

Release version
Code size
Stars
Build status
License

Interpreted, untyped, object-oriented and super cool.

  1. פלוט 'שלום עולם!'

Table of Contents

Installation

The project depends on cmake and gcc (MinGW64 on windows).

A precompiled version for Windows x64 is available in the release section.
  1. mkdir build
  2. cd build
  3. cmake ..
  4. make

Variables, comparison and math

  1. מ = 10
  2. מ = מ / 100
  3. פלוט מ // 0.1
  4. מ = ((מ ** 2) * 300) % 40
  5. פלוט מ // 3
  6. פלוט מ שווהל 100 או 1 == 1 // true
  7. פלוט מ גדולמ 70 וגם שקר // false
  8. פלוט לא קטןמ 0.34) // true

Operators

Any of the c-style operators can be used interchangeably with the hebrew keywords

c-style rpp
== שווהל
!= שונהמ
> גדולמ
< קטןמ
>= —-
<= —-
! לא
/ חלקי
* כפול
% —-
- —-
+ —-
  • Power operator: ** (python-style)
  • Boolean values: אמת and שקר
  • Boolean operators: או, וגם and לא

Control flow

  1. מ = 1
  2.  
  3. כלעוד מ קטןמ 10:
  4. אם מ שווהל 2:
  5. פלוט 'שתיים'
  6. אחרת אם מ % 2 == 0:
  7. פלוט 'זוגי'
  8. אחרת:
  9. פלוט 'אי-זוגי'
  10. מ = מ + 1
  11.  
  12. // אי-זוגי
  13. // שתיים
  14. // אי-זוגי
  15. // זוגי
  16. // ...
  17.  
  18. לכל מ בתוך טווח(100):
  19. פלוט מ
  20.  
  21. // 0, 1, 2, ...

Keywords

c-style rpp
if אם
else אחרת
while כלעוד
continue המשך
break שבור
python-style rpp
for לכל
in בתוך

Flexible syntax

All code blocks can be written in a one-line form or a multi-line indented block

  1. כלעוד אמת:
  2. פלוט 1
  3.  
  4. כלעוד אמת פלוט 1
  5.  
  6. אם שקר פלוט 1 אחרת אם אמת פלוט 2 אחרת:
  7. פלוט 3
  8. // 2

Supported code blocks:

  • if, else if, else
  • functions
  • classes
  • while loops
  • for loops
  • try, catch

Functions

Functions in rpp are declared similarly to JavaScript - they can be declared by name or anonymously

  1. פיב = פעולה(מ):
  2. אם מ == 0 או מ == 1:
  3. החזר 1
  4. החזר פיב(מ - 1) + פיב(מ - 2)
  5.  
  6. פלוט_פיב = פעולה(מ) פלוט פיב(מ)
  7.  
  8. לכל מ בתוך טווח(5):
  9. פלוט_פיב(מ)
  10.  
  11. // 1, 1, 2, 3, 5, ...

Classes

Class declarations are declared similarly to functions (named or anonymous)

  1. מחלקה חישובים:
  2. פעולה כפל(א, ב):
  3. החזר א * ב
  4.  
  5. פלוט חישובים.כפל(4, 2)
  6. // 8
  7.  
  8. חישובים2 = מחלקה:
  9. פעולה ריבוע(מ):
  10. החזר מ ** 2
  11.  
  12. פלוט חישובים2.ריבוע(3)
  13. // 9

Magic methods (dunders)

Similarly to Python, rpp classes can implement “magic” methods that run in certain situations

  1. מחלקה סניף:
  2. פעולה __אתחל__(שם):
  3. אני.שם = שם
  4. אני.עובדים = רשימה()
  5.  
  6. פעולה הוסף_עובד(שם_עובד):
  7. אני.עובדים.הוסף(שם_עובד)
  8.  
  9. פעולה הסר_עובד_אחרון():
  10. אני.עובדים.הסר(אני.עובדים.גודל() - 1)
  11.  
  12. פעולה __טקסט__():
  13. החזר אני.שם + ': ' + טקסט(אני.עובדים)
  14.  
  15. סניף_מרכזי = סניף('תל אביב')
  16. סניף_מרכזי.הוסף_עובד('דניאל')
  17.  
  18. פלוט סניף_מרכזי
  19.  
  20. // תל אביב: [דניאל]
python-style rpp
__init__ __אתחל__
__str__ __טקסט__
__getitem__ __קח__
__setitem__ __שים__
__next__ __הבא__
__iterator__ __איטרטור__

Exceptions

Exceptions are thrown and caught by class type

python-style rpp
try נסה
catch תפוס
as בתור
throw זרוק
  1. נסה:
  2. ר = רשימה(1, 2)
  3. ר[23]
  4. תפוס __שגיאת_מיקום__:
  5. פלוט 'שיט'
  6.  
  7. פעולה זורק():
  8. ערך = רשימה(1, 2)
  9. זרוק ערך
  10.  
  11. נסה:
  12. זורק()
  13. תפוס רשימה בתור א:
  14. פלוט א

Exception types

  • Index exception (thrown in list): __שגיאת_מיקום__
  • Key exception (thrown in dictionary): __שגיאת_מפתח__
  • Stop exception (thrown in iterator end): __שגיאת_עצירה__

Built-ins

As all great programming languages, rpp is equipped with some useful built-ins

List

  1. ר = רשימה(1,2,3)
  2. ר[2] = אמת
  3. פלוט ר.גודל() // 3
  4. ר.הוסף('שלום')
  5. ר.הוצא(0)
  6. פלוט ר.מצא(אמת) // 2
  7. פלוט ר.מצא('היי') // -1
  8. פלוט ר // [אמת, 3, 'שלום']
  9. לכל איבר בתוך ר:
  10. פלוט איבר

Dictionary

Dictionaries in rpp support only string keys and any type of values

For looping a Dictionary will yield it’s keys

  1. ר = מילון()
  2. ר['שם'] = 'רשי ועוד ועוד'
  3. ר['גרסה'] = '0.1'
  4. פלוט ר.גודל() // 2
  5. ר.הוצא('גרסה')
  6. פלוט ר.מכיל('שם') // אמת
  7. פלוט ר // {'שם': 'רשי ועוד ועוד'}
  8. לכל מפתח בתוך ר:
  9. פלוט מפתח
  10. // שם

Range

Similarly to Python, rpp has a built-in Range functionality, with two calling signatures:

  • Iterate from 0 to max-1: טווח(12)
  • Iterate from min to max-1: טווח(10, 20)
  1. לכל מ בתוך טווח(10) אם מ % 2 שווהל 0 פלוט "זוגי" אחרת פלוט "איזוגי"
  2. // זוגי, איזוגי, ...

I/O

  • Printing to console: the פלוט command.
  • Receiving input from the user: the (פלט)קלוט function

Currently, Rashi Plus Plus supports hebrew I/O in the console!

Hebrew Console I/O

(To enable hebrew in the windows console, please enable a TrueType font such as “Courier New”)

  1. פלוט 'שלום'
  2. פלוט 90
  3. פלוט אמת
  4. פלוט רשימה()
  5.  
  6. קלוט('>')
  7. קלוט('מי אתה? ')
  8. קלוט()

Range

Similarly to Python, rpp has a built-in Range functionality, with two calling signatures:

  1. Iterate [0, max): טווח(12)
  2. Iterate [min, max): טווח(10, 20)
  1. לכל מ בתוך טווח(10) אם מ % 2 שווהל 0 פלוט "זוגי" אחרת פלוט "איזוגי"
  2. // זוגי, איזוגי, ...

Random

Three random function signatures:

  1. Random real number in range [0, 1): ()אקראי
  2. Random integer in range [0, max): אקראי(3)
  3. Random integer in range [min, max): אקראי(1000, 2000)

Conversions and types

  • String literals can be written with single (‘) or double (“) quotes
  1. פלוט "המספר הוא " + טקסט(34) // המספר הוא 34
  2. פלוט מספר("3") * 2 // 6
  3. פלוט סוג(אמת) //

Patterns

The Iterator pattern

To implement an Iterator in rpp, a class must implement the following:

  • Return the iterator: __איטרטור__()
  • Return the next value and throw __שגיאת_עצירה__ on end: __הבא__()
  1. מחלקה קומבינציות:
  2. פעולה __אתחל__(רשימה_א, רשימה_ב):
  3. אני.רשימה_א = רשימה_א
  4. אני.רשימה_ב = רשימה_ב
  5. פעולה __איטרטור__():
  6. אני.א = 0
  7. אני.ב = -1
  8. החזר אני
  9. פעולה __הבא__():
  10. אני.ב = אני.ב + 1
  11.  
  12. אם אני.ב שווהל אני.רשימה_ב.גודל():
  13. אני.ב = 0
  14. אני.א = אני.א + 1
  15.  
  16. אם אני.א שווהל אני.רשימה_א.גודל():
  17. זרוק __שגיאת_עצירה__()
  18. החזר אני.רשימה_א[אני.א] + ' ' + אני.רשימה_ב[אני.ב]
  19.  
  20. שמות = קומבינציות(רשימה('דניאל', 'דני', 'רון'), רשימה('שמעון', 'בכר'))
  21.  
  22. לכל שם בתוך שמות:
  23. פלוט שם