usage: python3 compile.py [-h] [--tokenize] [--parseOnly] [--tokenPath TOKENPATH] [--stackPath STACKPATH] [--ICPath ICPATH] filepath
Langwej frontend compiler.
positional arguments:
filepath Specifies the path to the .lwj file to be compiled
optional arguments:
-h, --help show this help message and exit
--tokenize Specify this flag if the program needs to be tokenized only, defaults to False
--parseOnly Specify this flag if intermediate code should not be generated, defaults to False
--tokenPath TOKENPATH
Specifies the file where tokens are written, defaults to parseTokens.txt
--stackPath STACKPATH
Specifies the file where parse stack traces are written, defaults to parseStack.txt
--ICPath ICPATH Specifies the path where intermediate code generated is written, defaults to parseIC.txt
Examples:
let x = (a + b));
^
whil (a > b) { a = a + 1); }
^
Recovery Method:
- Report the error.
- Skip the closing parenthesis and get the next token.
- Continue parsing.
Examples:
if (a > b) { a = a + 1; }} else { a = a - 1; }
^
intijur funkshun recursion () {coll recursion();}}
^
Recovery Method:
- Report the error.
- Skip the closing brace and get the next token.
- Continue parsing.
Any error that is not handled by the above recovery methods will be handled by panic mode recovery.
Recovery Method:
- Report syntax error.
Tis the next token in the input.- If parser reaches here, it means that the next token,
Tis either;or}Sis the current top of the stack.pt[S, T]corresponds to the cell in the parse table withSas the top of stack andTas the next token in the input.
if nextToken does not exist:
finish parsing
else:
while T is not ';' or '}':
skip T and get the token after T if exists
while S is not 0 and pt[S, T] is an error:
pop from stack twice
if S is 0:
skip T and finish parsing
else:
leave panic mode and continue parsing