An interpreter written in C++ to handle a simple pascal like programming language. This was created for a programming assignment as apart of the CS 280 course at NJIT
It uses the following EBNF:
- Prog ::= PROGRAM IDENT ; DeclPart CompoundStmt .
- DeclPart ::= VAR DeclStmt; { DeclStmt ; }
- DeclStmt ::= IDENT {, IDENT } : Type [:= Expr]
- Type ::= INTEGER | REAL | BOOLEAN | STRING
- Stmt ::= SimpleStmt | StructuredStmt
- SimpleStmt ::= AssignStmt | WriteLnStmt | WriteStmt
- StructuredStmt ::= IfStmt | CompoundStmt
- CompoundStmt ::= BEGIN Stmt {; Stmt } END
- WriteLnStmt ::= WRITELN (ExprList)
- WriteStmt ::= WRITE (ExprList)
- IfStmt ::= IF Expr THEN Stmt [ ELSE Stmt ]
- AssignStmt ::= Var := Expr
- Var ::= IDENT
- ExprList ::= Expr { , Expr }
- Expr ::= LogOrExpr ::= LogAndExpr { OR LogAndExpr }
- LogAndExpr ::= RelExpr {AND RelExpr }
- RelExpr ::= SimpleExpr [ ( = | < | > ) SimpleExpr ]
- SimpleExpr :: Term { ( + | - ) Term }
- Term ::= SFactor { ( * | / | DIV | MOD ) SFactor }
- SFactor ::= [( - | + | NOT )] Factor
- Factor ::= IDENT | ICONST | RCONST | SCONST | BCONST | (Expr)
Table of Operators Precedence
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | Unary +, -, not | Unary plus, minus, and not (complement) | Right-to-Left |
2 | *, /, div, mod | Multiplication, Division, integer division, and modulus | Left-to-Right |
3 | +, - | Addition, and Subtraction, | Left-to-Right |
4 | <, >, = | Less than, greater than, and equality | (No Cascading) |
5 | and | Logical Anding | Left-to-Right |
6 | or | Logical Oring | Left-to-Right |
The language has four types: integer, real, boolean, and string