Skip to content

segfault with ebnf #4065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project("llama.cpp" C CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)

if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
Expand Down
4 changes: 4 additions & 0 deletions common/grammar-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace grammar_parser {
static uint32_t get_symbol_id(parse_state & state, const char * src, size_t len) {
uint32_t next_id = static_cast<uint32_t>(state.symbol_ids.size());
auto result = state.symbol_ids.insert(std::make_pair(std::string(src, len), next_id));
fprintf(stderr, "added id:%d wit string:|%s|\n",next_id,std::string(src, len).c_str());
return result.first->second;
}

Expand All @@ -41,8 +42,11 @@ namespace grammar_parser {
uint32_t rule_id,
const std::vector<llama_grammar_element> & rule) {
if (state.rules.size() <= rule_id) {
fprintf(stderr, "resize id %d\n",rule_id);
state.rules.resize(rule_id + 1);
}

fprintf(stderr, "adding rule id %d\n",rule_id);
state.rules[rule_id] = rule;
}

Expand Down
1 change: 1 addition & 0 deletions grammars/cublas.gebnf

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions grammars/ebnf.ebnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
letter ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"

digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
# removed " | "\f" | "\b"
symbol ::= "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">" | "'" | "=" | "|" | "." | "," | ";" | "-" | "+" | "*" | "?" | "\n" | "\t" | "\r"

character ::= letter | digit | symbol | "_" | " "
identifier ::= letter ( letter | digit | "_" )

#| "\f" | "\b"
S ::= ( " " | "\n" | "\t" | "\r" )

terminal ::= "'" character "'" ( character "'" ) "'"

terminator ::= (";" | ".")

term ::= "(" S rhs S ")" | "[" S rhs S "]" | "{" S rhs S "}" | terminal | identifier

factor ::= term S "?" | term S "*" | term S "+" | term S "-" S term | term S

concatenation ::= ( S factor S "," ? ) +
alternation ::= ( S concatenation S "|" ? ) +

rhs ::= alternation
lhs ::= identifier

rule ::= lhs S "=" S rhs S terminator

root ::= ( S rule S ) *
48 changes: 48 additions & 0 deletions grammars/mysql.gebnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@





# Define a table definition


tablename ::= [a-zA-Z_][a-zA-Z0-9_]*

# Define column definitions
columndefinitions ::= columndefinition+

# Define a column definition
columndefinition ::= columnname " " datatype

# Define a column name
columnname ::= [a-zA-Z_][a-zA-Z0-9_]*

# Define a data type
datatype ::= "INT" | "VARCHAR" | "DATE"

# Define relationship definitions
relationshipdefinitions ::= relationshipdefinition+

# Define a relationship definition
relationshipdefinition ::= "FOREIGN KEY (" columnname ") REFERENCES " tablename " (" columnname ")"

# Define ID tokens for each table
tableidtokens ::= tableidtoken+

# Define an ID token for a table
tableidtoken ::= tablename "_id"

# Define predicates for each table ID
tableidpredicates ::= tableidpredicate+

# Define predicates for a table ID
tableidpredicate ::= tableidtoken "." columnname

# Define optional whitespace between components
ws ::= [ \t\n]+

tabledefinition ::= "CREATE TABLE " tablename " (" columndefinitions ")" "\n"

tabledefinitions ::= tabledefinition+

root ::= tabledefinitions relationshipdefinitions
Loading