Package jminusminus

Class Parser

java.lang.Object
jminusminus.Parser

public class Parser extends Object
A recursive descent parser that, given a lexical analyzer (a LookaheadScanner), parses a j-- compilation unit (program file), taking tokens from the LookaheadScanner, and produces an abstract syntax tree (AST) for it.
  • Constructor Details

    • Parser

      public Parser(LookaheadScanner scanner)
      Constructs a parser from the given lexical analyzer.
      Parameters:
      scanner - the lexical analyzer with which tokens are scanned.
  • Method Details

    • errorHasOccurred

      public boolean errorHasOccurred()
      Returns true if a parser error has occurred up to now, and false otherwise.
      Returns:
      true if a parser error has occurred up to now, and false otherwise.
    • compilationUnit

      public JCompilationUnit compilationUnit()
      Parses a compilation unit (a program file) and returns an AST for it.
           compilationUnit ::= [ PACKAGE qualifiedIdentifier SEMI ]
                               { IMPORT  qualifiedIdentifier SEMI }
                               { typeDeclaration }
                               EOF
       
      Returns:
      an AST for a compilation unit.