Question: In this programming assignment, you will be building a lexical analyzer for small programming language, called Simple Perl-Like (SPL), and a program to test it.
In this programming assignment, you will be building a lexical analyzer for small programming language, called Simple Perl-Like (SPL), and a program to test it. This assignment will be followed by two other assignments to build a parser and an interpreter to the SPL language. Although, we are not concerned about the syntax definitions of the language in this assignment, we intend to introduce it ahead of Programming Assignment 2 in order to determine the language terminals: reserved words, constants, identifier(s), and operators. The syntax definitions of the SPL language are given below using EBNF notations. However, the details of the meanings (i.e. semantics) of the language constructs will be given later on.
Prog ::= StmtList
StmtList ::= Stmt ;{ Stmt; }
Stmt ::= AssignStme | WriteLnStmt | IfStmt
WriteLnStmt ::= WRITELN (ExprList)
IfStmt ::= IF (Expr) { StmtList } [ ELSE { StmtList } ]
AssignStmt ::= Var = Expr
Var ::= NIDENT | SIDENT
ExprList ::= Expr { , Expr }
Expr ::= RelExpr [(-eq|==) RelExpr ]
RelExpr ::= AddExpr [ ( -lt | -gt | < | > ) AddExpr ]
AddExpr :: MultExpr { ( + | - | .) MultExpr }
MultExpr ::= ExponExpr { ( * | / | **) ExponExpr }
ExponExpr ::= UnaryExpr { ^ UnaryExpr }
UnaryExpr ::= [( - | + )] PrimaryExpr
PrimaryExpr ::= IDENT | SIDENT | NIDENT | ICONST | RCONST | SCONST | (Expr)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
