./compile_yacc.sh matrix_checker.l matrix_checker.y
matrix_checker.py
is writttern in Lark. NOTE: The program cannot tell the position of semantic error.
The following are supported operators in this compiler
- addition
+
- subtraction
-
- multiplication
*
- transpose
^T
- parenthesis
(
)
All matrix are 2-dimensional matrices which are represented as [column number , row number]
.
e.g. [2, 3]
is a 2x3 matrix and [5,1]
is a 5x1 matrix.
Your output should show Syntax Error
if the input expression does not follow the grammar.
If it follows the grammar, then apply semantic check to see if the dimension on both side of each operator is correct.
Print Semantic error on col XX
followed by the location of the first operator which makes the semantic error occur in post order of AST.
If no any syntax error or semantic error, print Accepted
.
- Input
[2,1]^T*[2,1]
- Output
Accepted
- Input
([2,3]*[2, 3]^T)^T+[4,1]
- Output
Semantic error on col 19
- Input
([1,2]+[2,1]^T)*[1,3]*[1,3]^T*[3,3]
- Output
Semantic error on col 16