parsing - Can I improve this GOLD Parser Grammar? -


i have parse file looks this:

versioninfo {     "editorversion" "400"     "editorbuild" "4715" } visgroups { } world {     "id" "1"     "mapversion" "525"     "classname" "worldspawn"     solid     {         "id" "2"         side         {             "id" "1"             "plane" "(-544 -400 0) (-544 -240 0) (-272 -240 0)"         }         side         {             "id" "2"             "plane" "(-544 -240 -16) (-544 -400 -16) (-272 -400 -16)"         }     } } 

i have parser written scratch, has few bugs can't track down , imagine it'll difficult maintain if format changes in future. decided use gold parsing system generate parser, instead. grammar looks this:

"start symbol" = <sectionlist>  ! sets  {section chars} = {alphanumeric} + [_] {property chars} = {printable} - ["]  ! terminals  sectionname = {section chars}+  propertypart = '"' {property chars}* '"'  ! rules  <sectionlist> ::= <section>                |  <section> <sectionlist>  <sectionbody> ::= <propertylist>                |  <sectionlist>                |  <propertylist> <sectionlist>  <section> ::= sectionname '{' '}'            |  sectionname '{' <sectionbody> '}'  <propertylist> ::= <property>                 |  <property> <propertylist>  <property> ::= propertypart propertypart 

there no errors , parses 2000-line test file fine. however, first time writing custom grammar, i'm not sure if i'm doing correctly.

are there improvements make grammar above?

below changes request change better performance

1) make grammar left recursive rules. better in terms of making shift reduce operations gold parser shift reduce lr parser.

sectionlist ::= section

           |   sectionlist section 

propertylist ::= property

            | propertylist property 

2) third rule in below section forces have propertylist before sectionlist not between different 's. make sure per requirement

sectionbody ::= propertylist

           |  sectionlist             |  propertylist sectionlist 

i can better if required , if let me know language saying " should accept , shouldn't accept this" rather sample input not give 100% picture of language. or let me know bugs felt can define language description also.

regards, v m rakesh (rakesh.vm@gmail.com)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -