mohi2code / PLC

A lexical analyzer for a programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OVERVIEW ✨

This documentation contains general semantic rules and briefly summarizes details regarding the lexical analyzer.

GOAL 🎯

The semantic for the language was designed to be readable and easy to learn

How to run

flex mohi.l
bison mohi.y -d
gcc mohi.tab.c -lfl -o mohi
./mohi
Note: input3.mpl should generate an error

Variables

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

Arithmatic operations

  • + addition operator
  • - substraction operator
  • * multiplication operator
  • / division operator

example:
number _x = 5 * 4

Boolean expressions & Comparison operators

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

IF/ELSE Statement

semantic and structure
if expression
      statements
if not
      statements

example
if _x equals 5
      _x = _x + 1
if not
      _x = 5

While Loop

semantic and structure
while expression
      statements

example
while _age bigger than 18
      _adults = _adults + 1

Presedence Rules

/ * - + left to right
equals, not equals, bigger than, less than left to right

About

A lexical analyzer for a programming language


Languages

Language:C 97.3%Language:Yacc 1.8%Language:Lex 0.9%