diff --git a/src/main.rs b/src/main.rs index d474a6d..7de0486 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ double_enum!( Assign, While, If, + Else, LBrace, RBrace, LSBrace, @@ -67,6 +68,9 @@ scanner!( r"^if" : |_,_| { Some(If) } + r"^else" : |_,_| { + Some(Else) + } r"^\(" : |_,_| { Some(LBrace) } @@ -104,6 +108,7 @@ enum NoneTerminals { P, // Program, ; separated L, // Line of code Li, // line extended for assignments + IF, // if helper E, // Expression Ei, // Expression extended additive T, // Term, only containing Factors @@ -132,7 +137,9 @@ fn grammer() -> LLGrammar { P -> L,Semicolon,P; P -> ; L -> While,E,LQBrace,P,RQBrace; - L -> If,E,LQBrace,P,RQBrace; + L -> If,E,LQBrace,P,RQBrace,IF; + IF -> ; + IF -> Else,LQBrace,P,RQBrace; L -> Ident,FI,Li; Li -> Assign,E; Li -> ; @@ -158,7 +165,7 @@ fn grammer() -> LLGrammar { } fn main() { - let code = String::from("a = 4;while a != 5 { a = a+1; }; if a == 5 { a = 4; };"); + let code = String::from("a = 4; while a != 5 { a = a+1; }; if a == 5 { a = 4; } else {a = 5;};"); let mut m = Scanner::::new(code).with_skipping(Tokens::WhiteSpace); let mut grammar = grammer();