TypeCobol
TypeCobol copied to clipboard
Set Assignment Statement
Description
The Set Assignment statement assigns values to variables and array elements.
Limit syntax of set to this:
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.
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
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'
For the model:
-
list<Assignment>
does not exist, useIList<Assignment>
-
syntaxeProperty<bool>
does not exist, useSyntaxProperty<bool>
- The NULL case in SourceValue seems redundant with a NULL expression. I think we should remove it from grammar and thus from model