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,
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<NoneTerminals, BareTokens> {
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<NoneTerminals, BareTokens> {
}
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 grammar = grammer();