H1 Solutions
My version of calc is here.
Tests
The tests used for grading are here.
Tests named test??.calc produce correct output. Tests named
bad??.calc produce errors. The first bad tests contain references to undefined variables, other bad tests contain syntax errors.
Comments
Lex/yacc comments:
- "sqrt(" is two tokens
'sqrt' and '('.
- Use [ \t]+ ; to strip white spaces. Some students had
problems in their scanner because they failed to strip out white
spaces properly.
- Precedence and associativity section caused many problems. Check
solution for an acceptable way to handle
these.
- Many students failed to check if a variable is defined.
C++/STL comments:
- Using map<char*,double> is probably not what is needed. It uses address as the key, which makes no
sense unless you are writing a cache simulator or something like
that. The proper way is map<string,double>.
- Having map<string,double> for variable values and
map<string,bool> to keep track which variable is
defined is a poor programming practice. Use map::find() to
check if a variable is already defined. map::operator[]()
inserts its arguments into the map and pollutes your symbol table.
Alexei Kudriavtsev
Last modified: Tue Jan 29 10:32:38 EST 2002