A hungarian notation based programming language.
Hungarian is an interpreted programming language whose syntax is based on Hungarian notation with the aim of improving the readability of the source code and avoiding ambiguities in the declaration of variables and constants.
The language is inspired by the following languages:
Do you like or benefit from my work? please consider make a donation, a cup of coffee would be nice!
- Hungarian Notation
- Roadmap
- Prerequisites
- Installation
- Usage
- Syntax
- Variable and Constant declarations
- Declarations
- Functions
- Procedures
- Classes
- Methods and Properties of Classes
- Examples
- License
Hungarian notation is a naming convention for variables and constants in which the name of the variable or constant is prefixed with a letter or letters that indicate the type of data stored in the variable or constant. For example:
sName = "John"
nAge = 25
bState = true
In the above example, the variable sName
stores a string, the variable nAge
stores a number, and the variable bState
stores a boolean value.
- Expressions
- Variables
- Functions
- Procedures
- First class functions and procedures
- While loop
- For loop
- Repeat loop
- If/else statement
- Defer Statement
- Simple declare statement
- Commam separated declare statements
- Block (declare - end) of declarations
- Arrays
- Maps
- Modules
- Builtin type checker
- Classes
- Objects (Instances)
- Variadic Functions
- Optinal Parameters
- Array builtins
- Map builtins
- String builtins
- Function builtins
- Native builtins
- Class builtins
- Java 8 or higher.
-
Download the latest version of the interpreter from the releases page.
-
Place
Hungaro.jar
in a folder of your choice. -
Open a terminal and navigate to the folder where you placed
Hungaro.jar
. -
Run the following command:
java -jar Hungaro.jar
- Open a terminal and navigate to the folder where you placed
Hungaro.jar
. - Run the following command:
java -jar Hungaro.jar
- The interpreter will start and you will be able to write your code.
- To execute your code, press
Enter
. - To exit the interpreter, type
exit
. - To clear the screen, type
cls
. - To see the list of available commands, type
help
.
Both variables and constants are declared with the reserved word let. The rules for naming variables and constants are as follows:
-
If the variable is global, then its first character must be
g
, and its second character must represent the data type it stores. For example:gsName, gnAge, gbState, etc.
-
If the variable is local, then its first character must represent the data type it stores. For example:
sName, nAge, bState, etc.
-
All constants must be in uppercase, and the use of underscores to separate words is allowed.
-
If the constant is global, then its first character must be
_
followed by the name of the constant. For example:_PI, _EULER, _GOLDEN_RATIO, etc.
-
If the constant is local, then its first character must be a capital letter followed by the name of the constant. For example:
PI, EULER, GOLDEN_RATIO, etc.
- All declarations are made with the reserved word
def
. Let's see the syntax rules for declarations depending on their type:
-
If the function is global, then its first character must be
g
followed byf
, which stands for function, and then the function name. For example:gfSum, gfSub, gfMul, etc.
-
If the function is local, then its first character must be
f
, which stands for function, and then the function name. For example:fSum, fSub, fMul, etc.
-
If the procedure is global, then its first character must be
g
followed byp
, which stands for procedure, and then the procedure name. For example:gpShow, gpHide, gpDelete, etc.
-
If the procedure is local, then its first character must be
p
, which stands for procedure, and then the procedure name. For example:pShow, pHide, pDelete, etc.
-
If the class is global, then its first character must be
g
followed byc
, which stands for class, and then the class name. For example:gcPerson, gcCar, gcHouse, etc.
-
If the class is local, then its first character must be
c
, which stands for class, and then the class name. For example:cPerson, cCar, cHouse, etc.
-
If the method is abstract (has no body), then a
-
must be placed before the method name, followed by the method name and a pair of parentheses. For example:-getName(), -setName(), -getAge(), -setAge(), etc.
-
If the method is concrete (has a body), then the method name must be followed by a pair of parentheses (if it has parameters) and the body of the method. If the method has no parameters then the parentheses are not requiered, eg:
getName, setName(psName), getAge, setAge(pnAge), etc.
-
Properties can be defined either inside the constructor (pInit() procedure) or before the constructor. Only properties with their values are allowed eg:
sName = "John", nAge = 25, etc.
and the use oflet
is not allowed to define properties, this in order to speed up the reading of the source code. -
The declaration of the methods also does not allow the use of
def
to define them, this in order to speed up the reading of the source code.
- The parameters of functions, procedures and methods must begin with the letter
p
followed by the type of data it stores. ex:psName, pnAge, pbState, etc.
- Modules follow the same rules as classes, only that instead of
c
we usel
which refers tolibrary
. ex:lPerson, lCar, lHouse, etc.
Letter | Type |
---|---|
d | Date |
t | DateTime |
v | Variant |
s | String |
a | Array |
n | Number |
b | Boolean |
o | Object |
m | Map |
- It is only allowed to associate the null value to variables of type
variant
andobject
. - If a variable is created without initializing then its value will depend on the letter that defines it. Eg: if the variable is of type
string
then its value will be an empty string '', etc.
- String addition is done with the
&
operator. Ex:"Hello " & "world"
->"Hello world"
. The only rule is that the first operand must be a string and the rest of the operands can be of any type.
- The logical operators are the same as in other programming languages. Ex:
or, and, not
- The relational operators are the same as in other programming languages. Ex:
<, >, <=, >=, ==, !=
.
- The arithmetic operators are the same as in other programming languages. Ex:
+, -, *, /, %, ^
.
- Assignment operators are the same as in other programming languages. Ex:
=, +=, -=, *=, /=
.
# Strings
"Hello World"
# Numbers (integers and floating points)
1
3.14
# Booleans
true
false
# Arrays
[1, 2, 3]
# Maps
{ "key": "value" }
# Variable declaration
let sLocalName = "John"
let gsGlobalName = "John"
# Variable assignment
sLocalName = "John" # assignments allows the same type.
# Constant declaration
let INTEREST = 0.05 # INTEREST is a local constant
let _CAPITAL = 1000 # _CAPITAL is a global constant
"""
Local constants start with a capital letter
Global constants start with an underscore
Constants cannot be reassigned
"""
# this function add two numbers
def fSum(pnA, pnB)
return pnA + pnB
end
# this procedure shows a message
def pShow(psMessage)
pPrintLn(psMessage)
end
# A person class
def cPerson
sName = ""
nAge = 0
def pInit(psName, pnAge)
@sName = psName
@nAge = pnAge
end
def fGetName
return @sName
end
def pSetName(psName)
@sName = psName
end
def fGetAge
return @nAge
end
def pSetAge(pnAge)
@nAge = pnAge
end
end
MIT
NO WARRANTY
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.