project-langx / X

A placeholder language with shareable bytecode IR.
2 stars 0 forks source link

Add variable support in X #40

Open frankhart2018 opened 2 years ago

frankhart2018 commented 2 years ago

Closes #21

Implementation

  1. Identify 'var' keyword, assignment operator ('='), and identifiers in tokenizer.
  2. Add VarDeclNode for variable declaration.
  3. Parse the variable declaration statement according to the new grammar.
  4. Compile var declaration node to VAR opcode.
  5. Add a way to check the symbol table.
  6. Add a virtual memory for storing variables, and -m to debug memory.
  7. Add VarAssignNode for variable assignment.
  8. Parse the variable assignment statement according to the new grammar.
  9. Compile var assignment node to ASSIGN opcode.
  10. Add a way to update the existing symbol table entry.
  11. Add support for the ASSIGN opcode in the VM, the memory now gets updated with the value.
  12. Check if variables are declared or redeclared in the symbol table and throw errors accordingly.
  13. Add IdentifierNode for using variables in expressions.
  14. Compile identifier node to LOAD_VAR opcode.
  15. Check if the variable is declared before actually using it.
  16. Add support for LOAD_VAR in VM, now the variables are actually usable.