This commit is contained in:
jusax23 2024-10-29 12:34:06 +01:00
parent 5fafa6f342
commit f649edf9a5
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

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