- A stack is maintained by the lexer to keep track of indentations. A count is accumulated for the number of whitespace characters before the first token. If the count changes from the previous line count, a stack operation is performed. If count increases, another value is added to the stack. If count decreases, the topmost value is popped from the stack.
- A stack is maintained by the lexer to keep track of indentations. A count is accumulated for the number of whitespace characters before the first token. If the count changes from the previous line count, a stack operation is performed. If count increases, another value is added to the stack. If count decreases, the topmost value is popped from the stack.
- The file: src/main/jflex/chocopy/pa1/ChocoPy.jflex, lines from 100 to 182, contain the code for the stack.
- The file: src/main/jflex/chocopy/pa1/ChocoPy.jflex, lines from 100 to 182, contain the code for the stack.
@ -13,8 +11,11 @@
## Challenges:
## Challenges:
- Shift-reduce errors while parsing the grammar. One approach to fix is to change the grammar. We chose to fix this issue by adding a precedence as in the case of expr by adding right precedence for if and else.
- Shift-reduce errors while parsing the grammar. One approach to fix is to change the grammar. We chose to fix this issue by adding a precedence as in the case of expr by adding right precedence for if and else.
- Handling errors was another challenge. This required debugging and small changes to program flow.
- '-' can either be a minus operator or a negative sign, and these two have different precedence. We solved this by assigning '-' the correct precedence at the production rule where we know whether it is a minus operator or a negative sign.
- Understanding the giving code was a small challenge and took some time before we could start coding.
- Handling errors was another challenge. This required debugging and small changes to program flow. It's also a collaborative effort between group members that completed different part of the project.
- Understanding the giving code was a small challenge since some parts are compiled into binary and it become harder for us to debug through the source code, therefore it took us some time before we could start coding.
- Differences between ChocoPy and Python sometimes get us confused. For example, ChocoPy doesn't allow a function body without any statements and global (unscoped) statements in between (class/function/variable) definitions. This made us fail tests that we didn't thought we should. We then thoroughly read the reference manual and make our implementation conform to the manual whenever we can.
## Improvements:
## Improvements:
- Added more tests to rigorously check program flow and indentation.
- Added more tests to rigorously check program flow and indentation.