Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change syntax analyzer to parse same level commands to the same level in AST #20

Open
NickSettler opened this issue Oct 28, 2022 · 0 comments
Labels
maybe Something that is not surely needed to be done or is not required at all refactor Code refactoring syntax_analyzer Syntax analysis changes

Comments

@NickSettler
Copy link
Owner

Current syntax analyzer implementation will process the following program

$a = 1;
$b = 2;

as the following tree

graph TD
  R(SYN_NODE_SEQUENCE) --L--> RL(SYN_NODE_SEQUENCE)
  R --R--> RR(SYN_NODE_ASSIGN)
  RL --L--> RLL(NULL)
  RL --R--> RLR(SYN_NODE_ASSIGN)
  RLR --L--> RLRL(SYN_NODE_INDENTIFIER)
  RLR --R--> RLRR(SYN_NODE_INTEGER)
  RR --L--> RRL(SYN_NODE_INDENTIFIER)
  RR --R--> RRR(SYN_NODE_INTEGER)
Loading

Current implementation parses program in a kind of binary tree.

This should be changed to make syntax tree able to store multiple nodes in a particular level. So the mentioned program must be parsed into the following tree to reduce nesting of the whole tree. This implementation is more suitable unlike the second one

graph TD
  R(PROGRAM) --1--> R1(SYN_NODE_ASSIGN)
  R --2--> R2(SYN_NODE_ASSIGN)
  R --"..."--> RN(...)
  R1 --1--> R1L(SYN_NODE_INDENTIFIER)
  R1 --2--> R1R(SYN_NODE_INTEGER)
  R2 --1--> R2L(SYN_NODE_INDENTIFIER)
  R2 --2--> R2R(SYN_NODE_INTEGER)
Loading

Also this can be parsed into the following tree. But such implementation will be hard to debug

graph TD
  R(PROGRAM) --N--> R1(SYN_NODE_ASSIGN)
  R1 --L--> R1L(SYN_NODE_INDENTIFIER)
  R1 --R--> R1R(SYN_NODE_INTEGER)
  R1 --N--> R2(SYN_NODE_ASSIGN)
  R2 --L--> R2L(SYN_NODE_INDENTIFIER)
  R2 --R--> R2R(SYN_NODE_INTEGER)
  R2 --N--> R3(...)
Loading
@NickSettler NickSettler added the refactor Code refactoring label Oct 28, 2022
@NickSettler NickSettler added this to the Sprint 5 milestone Oct 28, 2022
@NickSettler NickSettler added this to VUT Oct 28, 2022
@NickSettler NickSettler moved this to Todo in VUT Oct 28, 2022
@NickSettler NickSettler added syntax_analyzer Syntax analysis changes maybe Something that is not surely needed to be done or is not required at all labels Nov 7, 2022
@NickSettler NickSettler removed this from the Sprint 5 milestone Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe Something that is not surely needed to be done or is not required at all refactor Code refactoring syntax_analyzer Syntax analysis changes
Projects
Status: Todo
Development

No branches or pull requests

1 participant