-
Notifications
You must be signed in to change notification settings - Fork 1
/
PJDC.ebnf
80 lines (50 loc) · 3.4 KB
/
PJDC.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Begin
<Translation_Unit> ::= {<Kiss_Declaration> | <Function_Definition> | <GlobalVariable_Definition> | <GlobalArray_Definition>}CODE_EOF
# Definition, Declaration
<Kiss_Declaration> ::= KISS IDENTIFIER ";"
<Type> ::= VOID | CHAR | INT | LONG
<Function_Definition> ::= <Type>["*"] IDENTIFIER "(" [<Parameter_List>] ")" <Compound_Statement>
<Parameter_List> ::= <LocalVariable_Declaration>{","<LocalVariable_Declaration>}
<GlobalVariable_Definition> ::= <Type>["*"] IDENTIFIER ["="(CONSTANT_INT | CONSTANT_CHAR)] ";"
<GlobalArray_Definition> ::= <Type>IDENTIFIER"["CONSTANT_INT"]" ["="<Initialize_List>] ";"
<Initialize_List> ::= "{" (CONSTANT_INT|CONSTANT_CHAR){","(CONSTANT_INT|CONSTANT_CHAR)} "}"
<LocalVariable_Definition> ::= <LocalVariable_Declaration>["="<Expression>]";"
<LocalVariable_Declaration> ::= <Type>["*"] IDENTIFIER
# Statement
<Statement> ::= <Compound_Statement> | <LocalVariable_Definition> | <If_Statement> | <Iteration_Statement> |
| <Continue_Statement> | <Break_Statement>| <Return_Statement> | <Expression_Statement>
<Compound_Statement> ::= "{"{<Statement>}"}"
<If_Statement> ::= IF"("<Expression>")"<Statement>[ELSE<Statement>]
<Iteration_Statement> ::= <While_Statement> | <DoWhile_Statement> | <For_Statement>
<While_Statement> ::= WHILE"("<Expression>")"<Statement>
<DoWhile_Statement> ::= DO<Statement>WHILE"("<Expression>")"";"
<For_Statement> ::= FOR"("<Expression_Statement><Expression_Statement>[<Expression>]")"<Statement>
<Continue_Statement> ::= CONTINUE";"
<Break_Statement> ::= BREAK";"
<Return_Statement> ::= RETURN [<Expression>] ";"
<Expression_Statement> ::= [<Expression>]";"
# Expression
<Expression> ::= <Assignment_Expression>{","<Assignment_Expression>}
<Assignment_Expression> ::= [(["*"]IDENTIFIER) | (IDENTIFIER"["<Expression>"]") "="]<Conditional_Expression>
<Conditional_Expression> ::= <LogicOr_Expression>["?"<Expression>":"<Expression>]
<LogicOr_Expression> ::= <LogicAnd_Expression>{"||"<LogicAnd_Expression>}
<LogicAnd_Expression> ::= <Or_Expression>{"&&"<Or_Expression>}
<Or_Expression> ::= <Xor_Expression>{"|"<Xor_Expression>}
<Xor_Expression> ::= <And_Expression>{"^"<And_Expression>}
<And_Expression> ::= <Equality_Expression>{"&"<Equality_Expression>}
<Equality_Expression> ::= <Relational_Expression>{("==" | "!=")<Relational_Expression>}
<Relational_Expression> ::= <Shift_Expression>{("<" | "<=" | ">" | ">=")<Shift_Expression>}
<Shift_Expression> ::= <PlusMinus_Expression>{("<<" | ">>")<PlusMinus_Expression>}
<PlusMinus_Expression> ::= <MulDiv_Expression>{("+" | "-")<MulDiv_Expression>}
<MulDiv_Expression> ::= <Unary_Expression>{("*" | "/" | "%")<Unary_Expression>}
<Unary_Expression> ::= ["-" | "~" | "!"]<Primary_Expression>
<Primary_Expression> ::= <FunctionCall_Expression> | <Address_Expression> | <Dreference_Expression> | <Array_Expression> |
| <Sizeof_Expression> | <IncDecPrefix_Expression> | <IncDecPostfix_Expression> | "("<Expression>")" |
| CONSTANT_INT | CONSTANT_CHAR | CONSTANT_STRING | IDENTIFIER
<FunctionCall_Expression> ::= IDENTIFIER"("[<Expression>]")"
<Address_Expression> ::="&"IDENTIFIER ["["<Expression>"]"]
<Dreference_Expression> ::="*"IDENTIFIER
<Array_Expression> ::= IDENTIFIER"[" <Expression> "]"
<Sizeof_Expression> ::= SIZEOF "("( (<Type>["*"]) | IDENTIFIER )")"
<IncDecPrefix_Expression> ::= ("++" | "--")IDENTIFIER
<IncDecPostfix_Expression> ::= IDENTIFIER("++" | "--")