Statically typed imperative language
Implemented in Python. Main use case - simulation of operations on the foreign exchange market.
Basic features:
- Primitive (
integer
,string
,float
,boolean
) and complex types (like structures) - Embeded
rate
,direction
,pair
,trend
,trader
types - some basic operators (
+
,-
,/
,*
,%
) - builtin functions
output
,numtoa
,rateToUSD
- Small standard library with basic functions like print, type conversion and currency convertion
if
andwhile
control statements
- Clone this repository.
- Create
.py
file and import theSemanticAnalyzer
. - Create instance of
SemanticAnalyzer
and runanalyze_file
method.
Numbers are represented with 2 possible types: integer and float with support of +, -, /, *, % operators between all of them. Strings are like in most other languages
"String example"
Character is the one unicode character in single quotes
'c'
Boolean
ugu, net // istead true and false
Functions are declared with func
keyword followed by it's type.
func boolean isPositive(d direction) {...}
NOTE: function parameters has format
identifier, type
.
There is 3 builtin functions:
output
(takes string as an argument and prints it),numtoa
(takes 1 argument (integer
orfloat
), returns string)rateToUSD
(takes 1 argument (with typerate
), returnsrate
with right pair leg equal to USD).
Nothing unusual for primitive types. Complex types can be assigned with block or by accessing some specific property
let pair testPair;
testPair.left = "EUR";
testPair.right = "USD";
or
let pair testPair;
testPair = {
left = "EUR";
right = "USD";
}
Conditional expression must evaluate to boolean type, else block is optional
if (r1.rateValue < r2.rateValue) {
return ->;
}
else {
return <-;
}
Conditional expression must evaluate to boolean type.
let integer counter;
counter = 3;
while (counter < 5) {
output(numtoa(counter));
counter = counter + 1;
}
First step is parsing syntax to lexemes. Next is building and validating AST tree against semantic rules. Language is statically typed so static analysis is performed by semantic analyzer.
This language is designed to simplify the presentation of processes in the foreign exchange market and their simulation.
pair
- currency pair. Has two fields:left
andright
. (Price of pair always in the right currency). For example: if left = "EUR" and right = "USD" this is similar to the EURUSD currency.rate
- currency rate (price of particular currency pair). Has two fields:ratePair
andrateValue
.ratePair
has typepair
,rateValue
- price of currency pair.direction
- can be->
(direction up) and<-
(direction down).trend
- trend of particular rate line. Has two fields:trDirection
andtrendSize
.trDirection
has typedirection
and means the price rises or drops,trendSize
is greater or equal to 0.
rateToUSD
- converts currency rate to USD. Takes 1 argument (with typerate
), returnsrate
with right pair leg equal to USD (right = 'USD'
). This funtion is VERY useful if you need to compare currency pairs with different right leg currency.
See example2.txt
with example of using this types.