Class BeerParser

Parser class

Classdesc

Parser class to parse the tokens into ast

Hierarchy

  • BeerParser

Constructors

Properties

current: number
tokens: Token[]

Methods

  • Grammar for Logic And

    expression → logic_and; logic_and → equality ( "and" equality )* ;

    Returns Expr

    logic_and

  • Grammar for Assignment

    assignment → IDENTIFIER "=" assignment | logic_or ;

    Returns Expr

    assignment

  • Grammar for call

    expression → call ; call → primary ( "(" arguments? ")" )* ;

    Returns Expr

    ast.Expr

  • Parameters

    Returns boolean

    true if the current token is of the given type

  • Grammar for Comparison

    expression → comparism; comparison → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;

    Returns Expr

    comparison

  • Parameters

    • type: TokenType

      {TokenType} to consume

    • message: string

      {string} to throw if type is not found

    Returns Token

    Throws

    returns the token if found, else throws an error

  • Grammar for declearation

    declaration → classDecl | funcDecl; | varDecl | statement ;

    Returns Stmt

    ast.Stmt

  • Grammar for Equality

    expression → equality ; equality → comparison ( ( "!=" | "==" ) comparison )* ;

    Returns Expr

    ast.Expr equality

  • Grammar for Expression

    expression → assignment; assignment → IDENTIFIER "=" assignment

    Returns Expr

    current token

  • Evaluation of Expression

    expressionStmt → expression

    Returns Stmt

    ast.Stmt

  • Grammar for Factor

    expression → factor ; factor → unary ( ( "/" | "*" ) unary )* ;

    Returns Expr

    ast.Expr factor

  • Parse the call expressions using the callee

    Parameters

    • callee: Expr

      ast.Expr

    Returns Expr

  • Evaluation of for statement

    forStmt → "for" "(" ( varDecl | exprStmt | ";" ) expression? ";" expression? ")" statement ;

    Returns Stmt

    ast.Stmt

  • Implementation of for function declearations

    Parameters

    • kind: string

      The kind of function to be declared

    Returns FunctionStmt

    ast.FunctionStmt

  • Evaluation of if statement

    ifStmt → "if" "(" expression ")" statement ( "else" statement )? ;

    Returns Stmt

    ast.Stmt

  • Returns boolean

    true if the current token is at the end

  • Check if current token is in the given list of types. If so, consume it and return true.

    Parameters

    • Rest ...types: TokenType[]

      {TokenType[]} to match

    Returns boolean

  • Grammar for Logic Or

    expression → logic_or; logic_or → logic_and ( "or" logic_and )* ;

    Returns Expr

    logic_or

  • Grammar for Literal

    expression → literal; literal -> primary primary → NUMBER | STRING | "true" | "false" | "nil" ;

    Returns Expr

    equality

  • Evaluation of Print

    printStmt → expression | "print" expression

    Returns Stmt

    ast.Stmt ast of print

  • Ecaluation of statements

    statement → expressionStmt | ifStmt ; | printStmt ; | returnStmt ; | whileStmt; | BlockStmt;

    Returns Stmt

    ast.Stmt

  • Synchronize the parser after an error.

    Returns void

  • Grammar for Term

    expression → term ; term → factor ( ( "-" | "+" ) factor )* ;

    Returns Expr

    ast.Expr term

  • Grammar for Unary

    expression → unary | call ; unary → ( "!" | "-" ) Unary | primary;

    Returns Expr

    ast.Expr unary

  • Grammar for var declaration

    varDecl → "var" IDENTIFIER ( "=" expression )? ";" ;

    Returns Stmt

    ast.Stmt

  • Evaluation of while statement

    whileStmt → "while" "(" expression ")" statement ;

    Returns Stmt

    ast.Stmt

Generated using TypeDoc