else
This commit is contained in:
parent
5fafa6f342
commit
f649edf9a5
1 changed files with 9 additions and 2 deletions
11
src/main.rs
11
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<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();
|
||||
|
|
Loading…
Reference in a new issue