Opened 15 years ago

Last modified 15 years ago

#297 assigned defect

expressions are not statements

Reported by: Stephen Siegel Owned by: stachnik
Priority: major Milestone: 1.1
Component: ast Version: 1.1
Keywords: expression statement Cc:

Description

In the AST package, we now have ExpressionNodeIF extending StatementNodeIF. However, this does not correspond to the syntax of C or any of the other languages under consideration. According to the C99 Standard, expressions are not statements, but one of the kinds of statements is an "expression statement", which wraps an expression. In a statement such as

lab: x*(y+1);

clearly (y+1) is not a statement. Labels cannot be associated to it. This statement is not a compound statement. There is only one statement there.

Let us discuss here the ramifications of the following changes, before doing anything:

Proposed Changes:

Delete "implements StatementNodeIF" from ExpressionNodeIF.
In ast/IF, move expression package up one level, outside of the statement package.
Add a new statement node: ExpressionStatementNodeIF. It has one child, which is an ExpressionNodeIF.
Add factory method to create an ExpressionStatementNodeIF.

Implementation classes will have to be modified accordingly.

XML and XML parser will have to be changed accordingly.

Change History (6)

comment:1 by zirkel, 15 years ago

In terms of building the model from the AST, I think this change can be implemented without much difficulty. In the ModelBuilder, there is already a method called processExpression which then calls methods for processing the appropriate expression. This method could be modified slightly to handle an ExpressionStatementNodeIF.

Changes to the AST nodes would involve changing the number of children of each expression, since they no longer inherit from StatementNodeIF and thus no longer have a sequence of labels as a child. Other than that, XML parsing and printing should be the only substantial changes.

comment:2 by stachnik, 15 years ago

It shouldn't be hard to change the XML parser to do this. All it should require is changing the schema and the ExpressionNodeFactory class so ExpressionNodes inherit directly from ASTNode. I don't think this will require changing more than a few lines of code.

comment:3 by Stephen Siegel, 15 years ago

Alex: won't you have to change the schema so that expression nodes no longer inherit from statement nodes?
Will that be difficult?

in reply to:  3 comment:4 by stachnik, 15 years ago

Replying to siegel:

Alex: won't you have to change the schema so that expression nodes no longer inherit from statement nodes?
Will that be difficult?

It will require a change to the schema but it shouldn't be at all difficult. It's just a matter of changing one line from base="stn:StatementNode" to base="astnode:ASTNode". I doubt it will even require any changes to Tim M.'s xml generator since labels can't appear in expression nodes anyway.

comment:5 by Stephen Siegel, 15 years ago

OK, go ahead and make the necessary changes to the ast module. Tim Z. will have to make some changes to ast2model too probably. Send a note when this change has been committed.

comment:6 by Stephen Siegel, 15 years ago

Owner: changed from zirkel to stachnik
Status: newassigned
Note: See TracTickets for help on using tickets.