-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
16 lines (16 loc) · 986 Bytes
/
grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<AP> ::= (<Declaration> | <Assign> | <IfElse> | <Loop>)*
<Declaration> ::= "int" <ID> ("," <ID>)* ("=" <Expression> ("," <Expression>)*)? ";"
<Assign> ::= <ID> ("=" | "+=" | "*=" | "/=" | "-=" | "%=") <Expression> ";"
<IfElse> ::= ("if" <Expression> ":" "begin" (<Assign>)* "end") ("elif" <Expression> ":" "begin" (<Assign>)* "end")* ("else" ":" "begin" (<Assign>)* "end")?
<Loop> ::= "loopc" <Expression> ":" "begin" (<Assign>)* "end"
<Expression> ::= <Disjunction> ("or" <Disjunction>)*
<Disjunction> ::= <Conjunction> ("and" <Conjunction>)*
<Conjunction> ::= <Equality> (("==" | "!=") <Equality>)*
<Equality> ::= <SoftComparison> ((">=" | "<=" ) <SoftComparison>)*
<SoftComparison> ::= <HardComparison> ((">" | "<" ) <HardComparison>)*
<HardComparison> ::= <PlusMinus> (("+" | "-") <PlusMinus>)*
<PlusMinus> ::= <Term> (("*" | "/" | "%") <Term>)*
<Term> ::= <Factor> ("^" <Factor>)*
<Factor> ::= <ID> | <Number> | "(" <Expression> ")"
<ID> ::= ([a-z] | [A-Z])+
<Number> ::= ([0-9])+