Class: Parser

Parser

new Parser()

Parses a token stream.
Source:

Members

<inner> tokenStream

The token stream from the Lexer
Source:

Methods

getErrors() → {Array}

Returns errors found during parsing
Source:
Returns:
Errors
Type
Array

getSymbolTable() → {Object}

Returns the Symbol Table build during parsing
Source:
Returns:
Symbol Table
Type
Object

parse(tokens)

Traverses the source code input to verify and build a token stream.
Parameters:
Name Type Description
tokens Array Token Stream from Lex
Source:

<inner> checkToken(type, displayError) → {Boolean}

Checks the next token against a series of types
Parameters:
Name Type Description
type String Type of token to match
displayError Boolean Should function display error on fail? Defaults to true
Source:
Returns:
true if token type is matched false otherwise
Type
Boolean

<inner> consume() → {Boolean}

Consumes a token in the tokenStream
Source:
Returns:
False if the tokenStream is empty otherwise true.
Type
Boolean

<inner> expectedError(expected)

Logs an error of the format "Expected x, found y"
Parameters:
Name Type Description
expected String The expected token type
Source:

<inner> lookAhead(number) → {Token}

Returns the token the number of steps ahead requested
Parameters:
Name Type Description
number Integer The number of steps to look ahead
Source:
Returns:
The token asked for
Type
Token

<inner> multiCheckToken(types) → {Boolean}

Checks the next token against a series of types
Parameters:
Name Type Description
types Array Array of types to match
Source:
Returns:
true if token matches any of the types false otherwise
Type
Boolean

<inner> nextLine()

Fast forwards to the next line
Source:

<inner> parseCharacter()

Checks for the Character production | a || b || c ... z
Source:

<inner> parseCharExpr()

Checks for the CharExpr production | "CharList"
Source:

<inner> parseCharList()

Checks for the CharList production | Char CharList || Epsilon
Source:

<inner> parseDigit()

Checks for the Digit production | 1 || 2 || 3 ... 9 || 0
Source:

<inner> parseExpr()

Checks for the Expr production
Source:

<inner> parseId()

Checks for the Id production | Char
Source:

<inner> parseIntExpr()

Checks for the IntExpr production | digit op Expr || digit
Source:

<inner> parseOp()

Checks for the Op production | + || -
Source:

<inner> parseProgram()

Checks for the Program production | Statement $
Source:

<inner> parseQuote()

Checks for the Quote sub-production | "
Source:

<inner> parseStatement()

Checks for the Statement production
Source:

<inner> parseStatementList()

Checks for the StatementList production | Statement StatementList || Epsilon
Source:

<inner> parseType()

Checks for the Type production | int || char
Source:

<inner> parseVarDecl()

Checks for the VarDecl production | Type Id
Source:

<inner> subIntExpr()

Checks for the sub-production op Expr
Source:

<inner> subStatement1()

Checks for the Statement production P(Expr)
Source:

<inner> subStatement2()

Checks for the Statement production Id = Expr
Source:

<inner> subStatement3()

Checks for the Statement production VarDecl
Source:

<inner> subStatement4()

Checks for the Statement production {StatementList}
Source:

<inner> tokenLine() → {Integer}

Get the line number of the current token
Source:
Returns:
line number
Type
Integer

<inner> tokenType() → {String}

Get the type of the current token
Source:
Returns:
token constant
Type
String