about summary refs log tree commit diff
path: root/grammar.ebnf
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-10-19 23:40:59 +0200
committerMel <einebeere@gmail.com>2021-10-19 23:40:59 +0200
commitf375aaf974c0edfdc6d8bc66b21b5098863b3153 (patch)
tree1992bf2fa047ea428d9176f20e3fb9657c26759c /grammar.ebnf
parent552573df2606f61b382166db57c27f209605e487 (diff)
downloadrabbithole-f375aaf974c0edfdc6d8bc66b21b5098863b3153.tar.zst
rabbithole-f375aaf974c0edfdc6d8bc66b21b5098863b3153.zip
Expand grammar.
Diffstat (limited to 'grammar.ebnf')
-rw-r--r--grammar.ebnf52
1 files changed, 44 insertions, 8 deletions
diff --git a/grammar.ebnf b/grammar.ebnf
index 1805abb..425c64a 100644
--- a/grammar.ebnf
+++ b/grammar.ebnf
@@ -1,16 +1,52 @@
 (* Grammar definition in EBNF format. *)
 
-Expression = TermExpression;
+Program = {Statement} EOF;
 
-TermExpression = FactorExpression { ("+" | "-") FactorExpression };
+(* Statement *)
 
-FactorExpression = UnaryExpression { ("*" | "/") UnaryExpression };
+Statement = ExpressionStatement | ReturnStatement | PrintStatement;
+
+ExpressionStatement = Expression ";";
+ReturnStatement = "return" Expression ";";
+(* NOTE: Hard-coded PrintStatement until Rabbithole has an standard library *)
+PrintStatement = "print" Expression ";";
+
+(* Expression *)
 
-UnaryExpression = ( "-" | "!" ) | GroupExpression;
+Expression = AssignmentExpression;
+
+(* Expressions affected by precedence*)
+
+(* NOTE: Only allow IDENTIFIERs and their fields as the LValue for now. *)
+AssignmentExpression = IDENTIFIER {"." IDENTIFIER} ("=" | ":=") AssignmentExpression | TermExpression;
+TermExpression = FactorExpression { ("+" | "-") FactorExpression };
+FactorExpression = UnaryExpression { ("*" | "/") UnaryExpression };
+UnaryExpression = ( "-" | "!" ) UnaryExpression | UnitExpression ;
                 
-UnitExpression = NaturalDigit {Digit} | "(" Expression ")";;
+(* Unaffected Expressions *)
+
+UnitExpression = FLOAT | INT | STR | GroupExpression | BlockExpression | FnExpression | | TypeExpression | FormExpression | IfExpression;
+
+GroupExpression = "(" Expression ")";
+BlockExpression = Block;
+FnExpression = "fn" FnHeader Block;
+TypeExpression = "type" TypeBlock;
+(* NOTE: Will associated functions clash with fields? *)
+FormExpression = "form" TypeBlock;
+IfExpression = "if" Expression Block { "elif" Expression Block } [ "else" Block ];
+
+(* Parts *)
+
+FnHeader = (FnSingleParameter | FnMultipleParameters) ["->" Type];
+FnSingleParameter = "self" | FnParameter;
+FnMultipleParameters = "(" FnSingleParameter { "," FnParameter} ")";
+FnParameter = IdentiferType;
+
+(* Utils *)
 
-(* Basics *)
+Block = "{" { Statement } [Expression] "}";
+TypeBlock = "{" [ IdentiferType ] { "," IdentiferType } "}";
 
-NaturalDigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
-Digit = "0" | NaturalDigit ;
\ No newline at end of file
+IdentiferType = IDENTIFIER ":" Type;
+(* NOTE: Type doesn't include anything other than simple named types for now. *)
+Type = IDENTIFIER;