summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-08 22:09:41 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-08 22:09:41 +0100
commit62e5257752bd9097e1edde5a7310f35222a40608 (patch)
treec7eb080d90685647fac3d30d54aa4293e3d5ba9f /src
parentParser: Add support for parsing variable statements (diff)
downloadinterpreter-62e5257752bd9097e1edde5a7310f35222a40608.tar.gz
interpreter-62e5257752bd9097e1edde5a7310f35222a40608.tar.bz2
interpreter-62e5257752bd9097e1edde5a7310f35222a40608.zip
Parser: Add grammar docs
Diffstat (limited to 'src')
-rw-r--r--src/parser.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/parser.zig b/src/parser.zig
index d6fb5d9..4e01f44 100644
--- a/src/parser.zig
+++ b/src/parser.zig
@@ -53,6 +53,7 @@ pub const Parser = struct {
         return self.parse_program();
     }
 
+    // Program ::= Statement+
     fn parse_program(self: *Parser) !*Node {
         var nodes = std.ArrayList(*Node).init(self.allocator);
         defer nodes.deinit();
@@ -67,6 +68,7 @@ pub const Parser = struct {
         return node;
     }
 
+    // Statement ::= (VariableStatement | PrintStatement) SEMICOLON
     fn parse_statement(self: *Parser) ParserError!*Node {
         const token = self.peek_token() orelse return ParserError.ParsingError;
 
@@ -96,6 +98,7 @@ pub const Parser = struct {
         }
     }
 
+    // VariableStatement ::= ("let" IDENTIFIER | IDENTIFIER) EQUALS Expression
     fn parse_variable_statement(self: *Parser) ParserError!*Node {
         const token = self.peek_token() orelse return ParserError.ParsingError;
 
@@ -122,9 +125,8 @@ pub const Parser = struct {
         return node;
     }
 
+    // PrintStatement :== PRINT LPAREN Expression RPAREN
     fn parse_print_statement(self: *Parser) ParserError!*Node {
-        // print + ( + statement + ) + ;
-
         _ = try self.accept_token(tokenizer.TokenType.PRINT);
 
         _ = try self.accept_token(tokenizer.TokenType.LPAREN);