c# - BNF grammar that has sections with no ending? -


i need parse simple proprietary language didn't design, can't change language. need results in c#, i've been using tinypg because it's easy use, , doesn't require external libraries run parser. tinypg generates simple ll(1) parser.

the problem i'm having related how language divides file sections. has sections different kinds of variables, setting initial values, equation definitions, etc. care sections declare variables, ignore rest. don't know rules other sections, , don't want have figure them out. may treated comments.

here's code example:

  parameter     density             real     crosssectionalarea  real   set # parameter values     t101.fo                 := "simpleeventfoi::dummy";     t101.crosssectionalarea := 1    ; # m2  equation     outsingleint = singleint;     outarrayint = arrayint; 

i care parameter , set sections, not equation section. can see, problem these sections have no end markers. can't figure out how tell grammar section ends when different keyword, new keyword may start new section. in attempts new section starting keyword gets consumed close off old section.

there many more sections have listed here, of care about, don't. seem fall 2 types, "looks parameter" don't have semicolons @ end of statements, , "looks equation" do. language not case or whitespace sensitive. sections in order. (e.g. set, equation, parameter) aside comments, whole thing written on 1 line.

currently i'm getting around using regular expression find sections i'm interested in, , feeding parser, i'm having trouble coming regular expression works in cases, doesn't accidentally pick keywords in comments. may end expanding workaround solve it's issues, nicer solve problem directly in grammar. it's possible isn't ll(1) language.

i tried following tpg code, can parse example. looks tinypg cannot distinguish keyword , id hacked id little bit.

//tiny parser generator v1.3 //copyright © herre kuijpers 2008-2012  <% @tinypg namespace="test" %>  parameter   -> @"parameter"; set         -> @"set"; equation    -> @"equation";           -> @"as";  id          -> @"\b(?!(parameter|set|equation)\b)([a-za-z]\w+)"; dot         -> @"\."; eq          -> @":="; expr        -> @"\d|""[^""]*"""; end         -> @";";  [skip] ws   -> @"\s+|#[^\r\n]+";  eqdecl      -> @"\b(?!(parameter|set|equation)\b)([^#;]+)"; equations   -> equation (eqdecl end)*;  parameters  -> parameter paramdecl*; paramdecl   -> id id;  sets        -> set setdecl*; setdecl     -> fullid eq expr end; fullid      -> id dot id;  section     -> equations | parameters | sets;  start       -> section*; 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -