mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-25 13:58:46 +01:00
examples : add C grammar (#2357)
This commit is contained in:
parent
5aec2cfaac
commit
d8d6977f48
42
grammars/c.gbnf
Normal file
42
grammars/c.gbnf
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
root ::= (declaration)*
|
||||||
|
|
||||||
|
declaration ::= dataType identifier "(" parameter? ")" "{" statement* "}"
|
||||||
|
|
||||||
|
dataType ::= "int" ws | "float" ws | "char" ws
|
||||||
|
identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
|
||||||
|
|
||||||
|
parameter ::= dataType identifier
|
||||||
|
|
||||||
|
statement ::=
|
||||||
|
( dataType identifier ws "=" ws expression ";" ) |
|
||||||
|
( identifier ws "=" ws expression ";" ) |
|
||||||
|
( identifier ws "(" argList? ")" ";" ) |
|
||||||
|
( "return" ws expression ";" ) |
|
||||||
|
( "while" "(" condition ")" "{" statement* "}" ) |
|
||||||
|
( "for" "(" forInit ";" ws condition ";" ws forUpdate ")" "{" statement* "}" ) |
|
||||||
|
( "if" "(" condition ")" "{" statement* "}" ("else" "{" statement* "}")? ) |
|
||||||
|
( singleLineComment ) |
|
||||||
|
( multiLineComment )
|
||||||
|
|
||||||
|
forInit ::= dataType identifier ws "=" ws expression | identifier ws "=" ws expression
|
||||||
|
forUpdate ::= identifier ws "=" ws expression
|
||||||
|
|
||||||
|
condition ::= expression relationOperator expression
|
||||||
|
relationOperator ::= ("<=" | "<" | "==" | "!=" | ">=" | ">")
|
||||||
|
|
||||||
|
expression ::= term (("+" | "-") term)*
|
||||||
|
term ::= factor(("*" | "/") factor)*
|
||||||
|
|
||||||
|
factor ::= identifier | number | unaryTerm | funcCall | parenExpression
|
||||||
|
unaryTerm ::= "-" factor
|
||||||
|
funcCall ::= identifier "(" argList? ")"
|
||||||
|
parenExpression ::= "(" ws expression ws ")"
|
||||||
|
|
||||||
|
argList ::= expression ("," ws expression)*
|
||||||
|
|
||||||
|
number ::= [0-9]+
|
||||||
|
|
||||||
|
singleLineComment ::= "//" [^\n]* "\n"
|
||||||
|
multiLineComment ::= "/*" ( [^*] | ("*" [^/]) )* "*/"
|
||||||
|
|
||||||
|
ws ::= ([ \t\n]+)
|
Loading…
Reference in New Issue
Block a user