cznic / goyacc

github.com/cznic/goyacc has moved to modernc.org/goyacc
https://godoc.org/modernc.org/goyacc
BSD 3-Clause "New" or "Revised" License
207 stars 24 forks source link

example #17

Closed geraldstanje closed 9 years ago

geraldstanje commented 9 years ago

Hi,

could you upload some examples which uses goyacc together with golex?

Thanks, Gerald

cznic commented 9 years ago

For example QL uses both goyacc and golex.

geraldstanje commented 9 years ago

isn't the yacc source generated by ebnf2y?

cznic commented 9 years ago

ql.y is generated automatically from the godocs using ebnf2y to verify the EBNF of the QL specification is structurally complete and correct.

parser.y originated as a copy of ql.y and since then it was manually edited to its present state.

geraldstanje commented 9 years ago

what did you manually add to the parser.y file? wouldnt it be less work to manually write the .y file?

cznic commented 9 years ago

a) This emphasizes the manual edits.

$ cd $GOPATH/src/github.com/cznic/ql
$ gvimdiff ql.y parser.y

b) I don't think so. The generated from EBNF parser is a nice skeleton to start with. YMMV, though.

cznic commented 9 years ago

Assuming I can close the issue, but please feel free to ask here if you want.

geraldstanje commented 9 years ago

hi, i modified the yacc file... can you give me some feedback to the general design? i still need to add tests and split the packages... https://github.com/geraldstanje/toycompiler

i would also like to add function, if statements and variables ... im not sure how to implement scoping in the code generator...any thoughts? in the following example there are 2 varDecl's. so when i see the FuncCall Node foo, i need to lookup for the varDecl a in the main scope to assign it to?

e.g. void foo(int a) { print a; }

int main() { int a = 2; foo(a); }