Разработка компиляторов


         

Грамматика языка С


Язык C является подмножеством языка С#. Ниже приведена грамматика С-бемоль.
program ::= { class | method } member ::= class | method | fields scope ::= ["static"] class ::= "class" ident "{" member { ";" member } "}" fields ::= scope type ident {"," ident } ";"
method ::= scope type ident "(" [arg {"," arg}] ")" block arg ::= type ident
stmt ::= ";" | decl | expr ";" | while | for | if | return | block | break | continue block ::= "{" {stmt} "}" decl ::= type ident [ = expr] {"," ident [ = expr]} ";" while ::= "while" "(" expr ")" stmt for ::= "for" "(" [expr] ";" [expr] ";" [expr] ")" stmt if ::= "if" "(" expr ")" stmt ["else" stmt] return ::= "return" expr ";" break ::= "break" ";" continue ::= "continue" ";"
primary ::= ident | int-const | float-const | char-const | string-const | "(" expr ")" | new-expr args ::= "(" [expr {"," expr } ] ")" new-expr ::= "new" type ("[" expr "]" | args) postfix ::= primary { "[" expr "]" | "." ident | args } mul-expr ::= [ mul-expr ("*" | "/" | "%") ] primary add-expr ::= [add-expr ("+" | "-") ] mul-expr rel-expr ::= add-expr [ ("<" | ">" | "<=" | ">=" | "==" | "!=") add-expr ] bool-expr ::= [ bool-expr ("&&" | "&" | "|" | "^") ] bool-expr assign-expr ::= bool-expr [ "=" bool-expr] expr ::= bool-expr
type ::= ident { "." ident } | type "[]" | "void" | "string" | "char" | "bool" | "int" | "float"



<

Содержание  Назад  Вперед