Skip to content

Latest commit

 

History

History
executable file
·
71 lines (48 loc) · 2.18 KB

File metadata and controls

executable file
·
71 lines (48 loc) · 2.18 KB

Name: SHUBHAM KUMAR SINGH B-Number: B00955182 Email: [email protected]

Project 1

Project Status: Completed

Modified Context Free Grammer (Left Factored)

    val : INT
        | '{' initializers '}'

    initializers : initializer (',' initializer )* , ?
        | empty

    initializer : '[' INT temp
        | val

    temp: ']' '=' val | '...' INT ']' '=' val

Test Report

Test Report

Programming Details

  • Programming Language Used : JavaScript
  • Engine Used: Node JS

Commands Used To Run Project

$ cd $HOME/i571c/prj1-sol
$ ./make.sh                                       # Run this bash script to execute all test
$ ./make.sh $HOME/i571c/extras/tests/complex.test # Run this script with
  • For getting JSON of AST / Lexeme, we need to configure environment variable OUT_TYPE as
# for getting json ast 
$ export OUT_TYPE="ast"

# for getting lexemes
$ export OUT_TYPE="tokens"

Projects Files Description

  • parser/ : This folder contains two files, Parser.js and ASTParser.js. Parser.js uses the cfg grammer to generate and validate the input expresssion. Whereas, ASTParser.js generates syntax tree and returns json for the same.

  • lexer/ : This folder contains code for generating lexemes from the given input. It contains two files, Token.js and Lexer.js . Token.js represents a token in a source code of a program while Lexer.js uses RegEx to extract tokens from the given expression.

  • ast/ : This folder contains AST.js file which is used to generate tree strcture of the given input.

Documetation about some of the functions - (function name | filename )

  • scan() | Lexer.js : This function is used to generate tokens from the given input and return Json array of tokens.
// if you want to get JSON on tokens generated using Lexer, use the below syntax
const _lex = require(./lexer/Lexer)
const input = "{1, 2, 3, [6...9]=1}"
console.log(_lex.scan(input))

Reference

Ruslan's Blog

Ruslan's GitHub