This documentation contains general semantic rules and briefly summarizes details regarding the lexical analyzer.
The semantic for the language was designed to be readable and easy to learn
flex mohi.l
bison mohi.y -d
gcc mohi.tab.c -lfl -o mohi
./mohi
Note: input3.mpl should generate an error
Types
- number: represents integers and float numbers.
- text: represents all alphabet characters singular, or plural
Variables declaration
all variables identifiers should start with an underscore and every statement should end with a newline, no semicolons needed.
Variables assignment
assignment can be done upon declaration or in a new statement
example:
number _apples
_apples = 5000
or
number _trees = _apples / 50
+
addition operator-
substraction operator*
multiplication operator/
division operator
example:
number _x = 5 * 4
equals
checks for equality between two variabls
not equals
checks for inequality between two variables
bigger than
returns true if left hand variable is bigger than the right hand variable
less than
returns true if the left hand variable is less than the right hand variable
example
number _students = 5
number _teachers = 4
_students equals _teachers
should evaluate to false
semantic and structure
if expression
statements
if not
statements
example
if _x equals 5
_x = _x + 1
if not
_x = 5
semantic and structure
while expression
statements
example
while _age bigger than 18
_adults = _adults + 1
/ * - +
left to right
equals, not equals, bigger than, less than
left to right