From c85b6fe40a229e5c086a5a9b8d9c09c6008f13c3 Mon Sep 17 00:00:00 2001 From: Houcine EL ADDALI Date: Sun, 3 Dec 2023 22:10:34 +0100 Subject: [PATCH] feat: abstract synthax tree contracts definition --- AST/ast_interfaces.go | 33 +++++++++++++++++++++++++++++++++ lexer/lexer.go | 4 ---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 AST/ast_interfaces.go diff --git a/AST/ast_interfaces.go b/AST/ast_interfaces.go new file mode 100644 index 0000000..de49eb7 --- /dev/null +++ b/AST/ast_interfaces.go @@ -0,0 +1,33 @@ +package ast + +/* +* Abstract syntax tree is the data structure +* which our parser will return it's is an hierarchical DS +* that represents 'the flow of the tokens' with a top down approach +* It's called abstract because it doesn't include all elements such whitespace break lines .. + */ + +/* +* The node type which be contained in the tree + */ +type Node interface{ + /* + * The token literal representation in the node + * This will be used only for testing and debugging purposes + */ + TokenLiteral() string +} + +/* +* we wil be define for now 2 types of nodes +* Statements nodes: doesn't return any value +* Expression nodes : does return a value +*/ +type Statement interface { + Node + statementNode() +} +type Expression interface { + Node + expressionNode() +} \ No newline at end of file diff --git a/lexer/lexer.go b/lexer/lexer.go index 831512d..154cf47 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -1,7 +1,6 @@ package lexer import ( - "fmt" "unicode/utf8" "github.com/houcine7/JIPL/token" @@ -32,7 +31,6 @@ func (l *Lexer) NextToken() token.Token { // var tokens []token.Token var test token.Token l.ignoreWhiteSpace() - fmt.Println(string(l.char),l.currentPos) switch l.char{ case '=': @@ -104,8 +102,6 @@ func (l *Lexer) NextToken() token.Token { } } - fmt.Print(test) - l.readChar() // move to next char return test }