TypeCobol icon indicating copy to clipboard operation
TypeCobol copied to clipboard

Set Assignment Statement

Open laabidiHend opened this issue 2 years ago • 3 comments

Description

The Set Assignment statement assigns values to variables and array elements.

Limit syntax of set to this: image

Technical This implies: To write the ANTLR grammar To write the CUP grammar Building the Set Assignment Statement CodeElement Building the Set Assignment Node Creating the corresponding Sql Object Making corresponding CodeElement, Node and SqlObject classes visitable Write test unit

How to test automatically Standard program tests.

laabidiHend avatar Jun 23 '22 09:06 laabidiHend

public class SetAssignmentStatement : SqlStatementElement 
{
           public list<Assignment> Assigmnents { get; }
	   public SetAssignment(list<Assignment> assigmnents) : base(CodeElementType.SetAssignmentStatement, StatementType.SetAssignmentStatement)
	   {
		 Assigmnents = assigmnents	;
	   }
		
		
}

public class Assignment : SqlObject
{
    public IList<TargetVariable> Targets { get; }
    public IList<SourceValue> Values { get; }

} 		
		

public class TargetVariable : SqlObject 
{
	public SqlVariable sqlVariable { get; }
	public TargetVariable (SqlVariable sql_Variable)
	{
		sqlVariable = sql_Variable;
	 }
}


public class SourceValue : SqlObject 		
{
	public SqlExpression Expression { get; }
	public syntaxeProperty<bool> IsNull { get; }
	public syntaxeProperty<bool> IsDefault { get; }
	public SourceValue(SqlExpression expression, syntaxeProperty<bool> isNull ,syntaxeProperty<bool> isDefault)
	{
		Expression = expression;
		IsNull = isNull;
		sDefault = isDefault;
	}
}

And for the ANTLR part :

//TODO Complete TargetVariable , sqlVarible ans sqlExpression
sqlVariable: hostVariable;
targetVariable: sqlVariable;
sqlConstant: SQL_DecimalFloatingPointLiteral | SQL_BinaryStringLiteral | SQL_GraphicStringLiteral | AlphanumericLiteral | HexadecimalAlphanumericLiteral | IntegerLiteral | DecimalLiteral | FloatingPointLiteral | datetime_constant;
sqlExpression: sqlVarible | column_name | sqlConstant;
sourceValueSpecifications: sqlExpression | SQL_NULL | SQL_DEFAULT;
assignmentStatement: SQL_SET assignmnentClause (SQL_CommaSeparator assignmnentClause)*;
assignmentClause: simpleAssignmentClause | multipleAssignmentClause;
simpleAssignmentClause: targetVariable EqualOperator sourceValueSpecifications ;
multipleAssignmentClause: LeftParenthesisSeparator targetVariable (SQL_CommaSeparator targetVariable)* RightParenthesisSeparator EqualOperator sourceValueSpecificationsClause;
sourceValueSpecificationsClause: LeftParenthesisSeparator sourceValueSpecificationsClauses rightParenthesisSeparator;
sourceValueSpecificationsClauses: repeatedSourceValue | (SQL_VALUE  ( sourceValueSpecifications | (LeftParenthesisSeparator repeatedSourceValue rightParenthesisSeparator)));
repeatedSourceValue: sourceValueSpecifications (SQL_CommaSeparator sourceValueSpecifications)*;
//TODO Add arrays and row-subselect

laabidiHend avatar Jun 23 '22 09:06 laabidiHend

For the ANTLR part:

  • typos
    • sqlVarible -> sqlVariable (x2)
    • ans -> and
    • assignmnentClause -> assignmentClause
    • rightParenthesisSeparator -> RightParenthesisSeparator (x2)
  • You forgot SQL_NULL constant in sqlExpression definition
  • In sourceValueSpecificationsClauses, the exxpected keyword is SQL_VALUES not SQL_VALUE
  • As explained before, some names should be shortened, simply remove the word 'Specifications'

fm-117 avatar Jun 23 '22 11:06 fm-117

For the model:

  • list<Assignment> does not exist, use IList<Assignment>
  • syntaxeProperty<bool> does not exist, use SyntaxProperty<bool>
  • The NULL case in SourceValue seems redundant with a NULL expression. I think we should remove it from grammar and thus from model

fm-117 avatar Jun 23 '22 12:06 fm-117