Skip to content

Formal languages project: a compiler for L language

License

Notifications You must be signed in to change notification settings

mkornaukhov03/Fl-project

 
 

Repository files navigation

Fl-project

Abstract language description (In Russian)
Specific language description (In Russian)
Tests
Examples


Features overview

  • Single function(main)
  • One scope for entire program
  • Single line comments
  • 3 types: Int(32 bit), Bool, String
  • Literals: 0b10101, 42, 'str', "another string", True
  • Operators:
    • Declaration and assignment
    • skip
    • if with optional else
    • while
    • print (prints String or Int)
  • Expression
    • '+' \ '-' \ '*' \ '/' - for operands of Int type
    • '<', '>', '<=', '>=' - for operands of Int type
    • '==', '!=' - for operands of all types
    • '!', '&&', '||' - for operands of 'Bool' type

Examples

  • GCD
    main() {
        // gcd(30, 24)
        Int x = 30;
        Int y = 24;
        while (x != 0) {
            if (y < x) {
                Int tmp = y;
                y = x;
                x = tmp;
            }
            y = y - x; 
        }
        print y;
    }
  • Finding sqrt
    main() {
        // finding sqrt(144) 
        Int val = 144;
        Int x = 0;
        while (x * x < val) {
            x = x + 1;
        }
        if (x * x == val) {
            print "Precise square root of val = ";
            print x;
        }
        else {
            print "Sqrt is not integer!";
        }
    }

Build

Prerequisites

  • Flex
  • Bison
  • LLVM
  • Clang

How to compile

l_to_exec.sh *source_file* *output_binary_file*

About

Formal languages project: a compiler for L language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 79.4%
  • Lex 11.5%
  • Shell 7.2%
  • Makefile 1.9%