public VaribleDeclarationPart(TokensList tokensList) { Token token = tokensList.GetToken(); if (token.kind != Constants.VAR) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.VAR + " but took " + token.kind.ToString()); } while (true) { token = tokensList.SeeToken(); if (token.kind == Constants.IDENTIFIER) { children.Add(new VaribleDeclaration(tokensList)); } else { break; } } token = tokensList.GetToken(); if (token.kind != Constants.ENDVAR) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.ENDVAR + " but took " + token.kind.ToString()); } }
public IfStatment(TokensList tokensList) { Token token = tokensList.GetToken(); if (token.kind != Constants.IF) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.IF + " but took " + token.kind.ToString()); } children.Add(new BoolStatment(tokensList)); token = tokensList.GetToken(); if (token.kind != Constants.THEN) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.THEN + " but took " + token.kind.ToString()); } children.Add(new StatmentPart(tokensList)); token = tokensList.SeeToken(); if (token.kind == Constants.ELSE) { token = tokensList.GetToken(); //children.Add(token); children.Add(new StatmentPart(tokensList)); } token = tokensList.GetToken(); if (token.kind != Constants.ENDIF) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.ENDIF + " but took " + token.kind.ToString()); } }
public MathExpression(TokensList tokensList) { children.Add(new Factor(tokensList)); while (true) { Boolean isOperator = false; MathOperator mathOperator = new MathOperator(tokensList, ref isOperator); if (mathOperator.getTokensList().Count > 0) { children.Add(mathOperator); } if (isOperator) { children.Add(new Factor(tokensList)); } else { break; } } if (children.Count > 3) { Token token = tokensList.SeeToken(); throw new System.Exception("Line " + token.lineNo.ToString() + " too long math expression "); } }
public WriteStatment(TokensList tokensList) { Token token = tokensList.GetToken(); if (token.kind != Constants.WRITE) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.WRITE + " but took " + token.kind.ToString()); } token = tokensList.GetToken(); if (token.kind != Constants.FROM) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.FROM + " but took " + token.kind.ToString()); } token = tokensList.SeeToken(); if (token.kind == Constants.IDENTIFIER) { children.Add(new VaribleStatment(tokensList)); } else if (token.kind == Constants.MATH) { children.Add(new MathStatment(tokensList)); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.IDENTIFIER + " or " + Constants.MATH + " but took " + token.kind.ToString()); } }
public AssignmentStatment(TokensList tokensList) { children.Add(new VaribleStatment(tokensList)); Token token = tokensList.GetToken(); if (token.kind != Constants.ASSIGN_OP) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.ASSIGN_OP + " but took " + token.kind.ToString()); } token = tokensList.SeeToken(); if (token.kind == Constants.MATH) { children.Add(new MathStatment(tokensList)); } else if (token.kind == Constants.BRACKET_L) { children.Add(new ArrayAssignment(tokensList)); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.MATH + " or " + Constants.BRACKET_L + " but took " + token.kind.ToString()); } }
public VaribleStatment(TokensList tokensList) { Token token = tokensList.GetToken(); if (token.kind == Constants.IDENTIFIER) { children.Add(token); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.IDENTIFIER + " but took " + token.kind.ToString()); } token = tokensList.SeeToken(); if (token.kind == Constants.BRACKET_L) { token = tokensList.GetToken(); if (token.kind != Constants.BRACKET_L) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.BRACKET_L + " but took " + token.kind.ToString()); } else { children.Add(token); } token = tokensList.GetToken(); if (token.kind == Constants.CONST_INT || token.kind == Constants.IDENTIFIER) { children.Add(token); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.CONST_INT + " or " + Constants.IDENTIFIER + " but took " + token.kind.ToString()); } token = tokensList.GetToken(); if (token.kind != Constants.BRACKET_R) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.BRACKET_R + " but took " + token.kind.ToString()); } else { children.Add(token); } } }
public Type(TokensList tokensList) { Token token = tokensList.SeeToken(); if (token.kind == Constants.INTARRAY) { children.Add(new ArrayType(tokensList)); } else if (token.kind == Constants.INTEGER) { children.Add(new IntegerType(tokensList)); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.INTEGER + " or " + Constants.INTARRAY + " but took " + token.kind.ToString()); } }
public Statment(TokensList tokensList) { Token token; while (true) { token = tokensList.SeeToken(); if (token.kind == Constants.IDENTIFIER) { children.Add(new AssignmentStatment(tokensList)); } else if (token.kind == Constants.READ) { children.Add(new ReadStatment(tokensList)); } else if (token.kind == Constants.WRITE) { children.Add(new WriteStatment(tokensList)); } else if (token.kind == Constants.IF) { children.Add(new IfStatment(tokensList)); } else if (token.kind == Constants.WHILE) { children.Add(new WhileStatment(tokensList)); } else if (token.kind == Constants.MATH) { children.Add(new MathStatment(tokensList)); } else { break; } token = tokensList.GetToken(); if (token.kind != Constants.SEMICOLON) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.SEMICOLON + " but took " + token.kind.ToString()); } } }
public ArrayAssignment(TokensList tokensList) { Token token = tokensList.GetToken(); if (token.kind != Constants.BRACKET_L) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.BRACKET_L + " but took " + token.kind.ToString()); } while (true) { token = tokensList.GetToken(); if (token.kind == Constants.CONST_INT) { children.Add(token); } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.CONST_INT + " but took " + token.kind.ToString()); } token = tokensList.SeeToken(); if (token.kind == Constants.COMMA) { token = tokensList.GetToken(); //children.Add(token); } else { break; } } token = tokensList.GetToken(); if (token.kind != Constants.BRACKET_R) { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.BRACKET_R + " but took " + token.kind.ToString()); } }
public MathOperator(TokensList tokensList, ref Boolean isOperator) { Token token = tokensList.SeeToken(); if (token.kind == Constants.MINUS || token.kind == Constants.PLUS || token.kind == Constants.MULT || token.kind == Constants.DIV || token.kind == Constants.MOD) { isOperator = true; token = tokensList.GetToken(); children.Add(token); } else { if (token.kind == Constants.PARANTHESIS_R) { isOperator = false; } else { throw new System.Exception("Line " + token.lineNo.ToString() + " : expected " + Constants.MATH_OPERATOR + " but took " + token.kind.ToString()); } } }