Skip to content
/ Flux Public

Flux, an interpreted (tree-walking) programming language written in Python.

Notifications You must be signed in to change notification settings

DaggoggaD/Flux

Repository files navigation

Flux v0.4

Interpreted (tree-walking) programming language Flux written in Python.

print("this_is_flux");
class ClassName{
    store value = 3;
    store value_two = 4;
}

store ClassOBJ = Instantiate(ClassName);
store value_out = ClassOBJ $ value;
store value_two_out = ClassOBJ $ value_two;

print(value);
print(value_two);

setCV(ClassOBJ value_two_out 12);
store value_two_out = ClassOBJ $ value_two;
print(value_two);
this_is_flux
3
4
12
  • New features: CLASSES (class obj, initialization, value access, setCV)

Current state of progress

Early submission of flux.

Implemented features (grammar rules described later):

  • Binary operations
  • Variables (int, string, float, lists, booleans)
  • Print statement
  • While
  • If
  • Array set value
  • Array get value
  • Functions
  • Append array
  • Random values (int, float)
  • Array remove value
  • Import
  • Round
  • Math functions (root, log, pow)
  • Type conversion (int, string, float -> float; int, string, float -> int)
  • User input
  • Classes: class obj, class initialization, access values (variables)

WIP/planned features:

  • classes functions
  • Type conversion (int, string, float -> string)
  • Else
  • Errors
  • Python modules accessibility (?)

Issues

At the moment errors are poorly controlled and have no in-line info. A new system must be created handling errors more abstractly.

Language grammar

  • binary operations:
    • Math operations: + - * / are already implemented.
    • Power operation will be created inside the flux language as a function (pow(VALUE POWER)).
    • Sqrt operation will be implemented with the # keyword.
    • > < >= <= == becomes > < GOE LOE =.
  • variables:
    • Variable declaration: Variables are dynamically allocated, so they have no defined type and can change later. To declare one, use the "store" keyword: store NAME = VALUE;. To declare a variable you NEED to assign a value (None value will be added later) followed by a ";".
    • Variable value change: To change the value of a variable you still need to use the "store" keyword. This will NOT cause interferences with global/local variables.
      store NAME = "andrea";
      ...
      store NAME = "nautilus";
      
    • Array values: to create an array you initialize the variable, and then assign it an array: store ARRAY = [VALUE, VALUE, VALUES...,];. At the last index of the array, you must add a , like so: store ARRAY = [1,[1.1,1.2,1.3,],2,3,];.
      • Array get value: getAV(NAME INDEX);. CAN be nested
      • Array set value: setAV(NAME INDEX VALUE); CAN'T BE NESTED
      • Array append value: append(NAME VALUE): CAN'T BE NESTED
      • Array remove value: remAV(NAME INDEX); CAN'T BE NESTED
    • += -= *= /= %= are not supported and you'll need to use a "recursive" formula:
      store i = 0;
      store i = i + 1;
      
  • print:
    • To print values to the user, use the "print" keyword: print(VALUE);.
    • You can print integers, floats, strings and arrays by passing their value or identifier: print(1); or print(2.2); or print(VALUE); or print(variable_name);
  • while:
    • For loops won't be implemented to keep the language simpler.

    • While loops are similar to it's C++ counterpart: while(CONDITION){...}
  • if:
    • Again, if statements are similar to C++ grammar: if(CONDITION){...}
  • functions:
    • function declaration are structured as follows: func NAME(ARG ARG ...){EXPRESSIONS}.
    • functions are completely separated parts of code, so they cannot see public variables outside of the ARGS passed. To pass variables you must use ARGS.
    • function calls can return a value into a variable or not dynamically:
      func sum(a b){
          store sum = a + b;
          return sum;
      }
      store res = sum(1 2);
      sum(1 2);
      
      Where the second sum doesn't show in the console
  • random values:
    • random float: random(); -> returns float between 0 and 1.
    • random int: randint(START END); -> returns int between START and END.
  • import:
    • import a file: import FILENAME; with all variables and functions.
  • round:
    • round value: round(VALUE); -> FLOAT -> INT; INT->INT.
  • math functions:
    • power: Mpow(BASE POWER);
    • root: Mroot(EXPONENT VALUE);
    • log: Mlog(BASE VALUE);
  • type conversion:
    • int: int(VALUE);
    • float: float(VALUE);
  • user input:
    • load value from user: input(PROMPT);
    • assign value to var: store NAME = input(PROMPT);
  • classes:
    • class obj: (only variables, functions not yet implemented.
      class CLASSNAME {
         store a = 0;
         ...
      }
      
    • class initialization: Instantiate(CLASSNAME);. Can be stored: store CLASSOBJ = Instantiate(CLASSNAME);
    • access class value: CLASSNAME $ CLASS_VALUE_NAME;. Can be stored: store CLASSVALUE = CLASSNAME $ CLASS_VALUE_NAME
    • set class value: setCV(CLASSNAME CLASS_VALUE_NAME VALUE);

Other Infos

All grammar info will be updated as features gets added or changed. The language is expected to be finished earlier than September 2024, as it will be used as a lyceum essay.

About

Flux, an interpreted (tree-walking) programming language written in Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published