c - Parser reducing too early -


i've got grammar looks :

start ::= groups. groups ::= groups group. groups ::= group. group(a) ::= identifier identparams curly_open assignments curly_close semicolon. group(a) ::= identifier curly_open assignments curly_close semicolon. assignments ::= assignments assignment. assignment ::= identifier assignment bool_expr semicolon. 

it parses :

name {      name = "value";      name2 = "value"; }; 

that's named config indeed. happens :

name = "value" results in assignments ::= assignments assignment. beeing reduced. expect assignments constant value, isn't case :

p assignment(0x807e778) ::= identifier(0x807e728) assignment mvalue semicolon.  p assignments((nil)) ::= assignments((nil)) assignment(0x807e778). p append 0x807e778 0x807e838 p mvalue ::= string. p assignment(0x807e750) ::= identifier(0x807e7c8) assignment mvalue semicolon. p assignments((nil)) ::= assignments(0x807e838) assignment(0x807e750). p append 0x807e750 0x807e910 p mvalue ::= string. p assignment(0x807e7f0) ::= identifier(0x807e7a0) assignment mvalue semicolon. p assignments((nil)) ::= assignments(0x807e910) assignment(0x807e7f0). p append 0x807e7f0 0x807e9e8 p group(0x807e7a0) assignments(0x807e9e8) : bind p groups ::= group(0x807e7a0). 

the lemon debug output http://pastebin.com/yhnknrpf

which results in name2 being added list. i'm puzzled this. understand reduce, not why assignents keep being set null. there ways around this, prefer proper fix.

the lemon debug output http://pastebin.com/yhnknrpf

any clues ?

lemon parser debug output on pastebin shows parses input tokens well. allows conclude complete grammar correct. unclear question how treat parsed values in reduce actions.

consider following implementation. two-level list introduced store parsed data -- list of groups in turn lists of assignments. on reduce of every assignment rule parser call action adds entry temporary list of assignments. on reduce of group rules temporary list included groups list new group entry. entire list dropped in case of syntax error. contains parsed values when parsing complete.

according program output, seems use new list or every new assignment value:

p append 0x807e778 0x807e838 p append 0x807e750 0x807e910 p append 0x807e7f0 0x807e9e8 

it explains why have last value @ end of parsing. new list assignments should initialized @ beginning of parsing first group , in action handler of groups rule next group.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -