Skip to content

Nandy-006/Compiler-Construction-Project

Repository files navigation

CS F363 Compiler Construction
Programming Assignment


Team Members

  • [2019A7PS0086H] Amogh Bharadwaj
  • [2019A7PS0164H] Nandan H R
  • [2019A7PS0033H] T V Chandra Vamsi

  • Running the compiler:

    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
    

    Error Recovery for Parser:

    1. Error recovery for extra closing parenthesis (error code e0):

    Examples:

    let x = (a + b));
                   ^
    whil (a > b) { a = a + 1); }
                            ^
    

    Recovery Method:

    1. Report the error.
    2. Skip the closing parenthesis and get the next token.
    3. Continue parsing.

    2. Error recovery for extra closing brace (error code e1):

    Examples:

    if (a > b) { a = a + 1; }} else { a = a - 1; }
                             ^
    intijur funkshun recursion () {coll recursion();}}
                                                     ^
    

    Recovery Method:

    1. Report the error.
    2. Skip the closing brace and get the next token.
    3. Continue parsing.

    3. Panic Mode Recovery (error code ee):

    Any error that is not handled by the above recovery methods will be handled by panic mode recovery.

    Recovery Method:

    1. Report syntax error.
    2. T is the next token in the input.
    3. if nextToken does not exist:
          finish parsing
      else: 
          while T is not ';' or '}':
              skip T and get the token after T if exists
      
    4. If parser reaches here, it means that the next token, T is either ; or }
      S is the current top of the stack.
      pt[S, T] corresponds to the cell in the parse table with S as the top of stack and T as the next token in the input.
    5. 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
      

    About

    No description, website, or topics provided.

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

     
     
     

    Contributors