Use your Go compiler to implement LL(1) grammar analysis in Go:
The nonterminal symbols are the set of symbols that appear on the left-hand side of the productions.
The terminal symbols are the set of symbols that appear in the right-hand-side of at least one production, but do not appear as the left-hand side of any production.
Print a report to stderr. Start by printing a line containing only "Start Symbol", followed by a blank line, followed by a line containing the start symbol, followed by a blank line. Next print a line containing only "Nonterminals", followed by a blank line, followed by a line containing the nonterminals, in any order, separated by a (single) space, followed by a blank line. Next print a line containing only "Terminals", followed by a blank line, followed by a line containing the terminals, in any order, separated by a (single) space, followed by a blank line.
A sample input grammar is available in ~cs712/public/tests/phase4/hw1.grm.
In order to allow reading from stdin, I recommend adding support for the Scanln function from the standard Go fmt package. You can treat this function as if it was a predefined function, but you should modify your parser to allow an import at the top of the file (import . "fmt"). (You do not need to implement the import, but you must be able to parse it.)
Here is Go code to show how the productions might be read:
package main; import . "fmt" func main() { var left string; var right1 string; var right2 string; var right3 string; var right4 string; var right5 string; var right6 string; var right7 string; var right8 string; var right9 string; var right10 string; var n int; n = getProduction(&left, &right1, &right2, &right3, &right4, &right5, &right6, &right7, &right8, &right9, &right10) for n > 0 { println(left, `->`, right1, right2, right3, right4, right5, right6, right7, right8, right9, right10); n = getProduction(&left, &right1, &right2, &right3, &right4, &right5, &right6, &right7, &right8, &right9, &right10) } } func getProduction(left, right1, right2, right3, right4, right5, right6, right7, right8, right9, right10 *string) int { *left = ``; *right1 = ``; *right2 = ``; *right3 = ``; *right4 = ``; *right5 = ``; *right6 = ``; *right7 = ``; *right8 = ``; *right9 = ``; *right10 = ``; Scanln(left, right1, right2, right3, right4, right5, right6, right7, right8, right9, right10); if len(*left) == 0 { return 0; } if len(*right1) == 0 { return 1; } if len(*right2) == 0 { return 2; } if len(*right3) == 0 { return 3; } if len(*right4) == 0 { return 4; } if len(*right5) == 0 { return 5; } if len(*right6) == 0 { return 6; } if len(*right7) == 0 { return 7; } if len(*right8) == 0 { return 8; } if len(*right9) == 0 { return 9; } if len(*right10) == 0 { return 10; } return 11; }
Note that this code requires that you also implement the "len" built-in function for strings.
This is just a suggestion. If you can find an easier, standard Go way to read lines from stdin, go ahead and do it your way.
You can add other features to your Go system, but your Go program to do the grammar analysis must be able to be compiled by gccgo.
To get full credit, your code must be adequately documented and structured. If I can't easily read and understand your code, you may lose points. This includes both your compiler and your Go code for the LL(1) grammar analysis.
You must give me back the system in the same form that I gave it to you. I must be able to install it and run it in the exact same way as when it was delivered to you. I would also like you to keep the source code organized in the same directory hierarchy. If you fail to do this, a significant deduction will be made to your grade.
Note that there is a script, distribute.sh, in ugo/bin, which will generate a tar file for you. This tar file is what I require you to submit to me for grading.
Your Go code should be placed in a single file called "LL1.go".
To turn in this assignment, type:
~cs712/bin/submit phase4 ugo.tar LL1.go
Submissions can be checked by typing:
~cs712/bin/scheck phase4
The assignment is due on Sunday December 10. There is a grace period to 8am on Monday December 11 when no late penalty will be assigned. Submissions between 8am December 11 and 8am December 12 will have a late penalty of 10 points. Submissions between 8am December 12 and 8am December 13 will have a late penalty of 30 points. No program may be turned in after 8am on Wednesday December 13.
Remember: you are expected to do your own work on this assignment.
Comments and questions should be directed to pjh@cs.unh.edu