Name: SHUBHAM KUMAR SINGH B-Number: B00955182 Email: [email protected]
Project Status: Completed
val : INT
| '{' initializers '}'
initializers : initializer (',' initializer )* , ?
| empty
initializer : '[' INT temp
| val
temp: ']' '=' val | '...' INT ']' '=' val
- Programming Language Used : JavaScript
- Engine Used: Node JS
$ 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"
-
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.
- 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))