001 package com.croftsoft.apps.compiler.mini.node;
002
003 import java.util.*;
004
005 /*********************************************************************
006 * Parse tree node for the Mini programming language.
007 *
008 * @see
009 * MiniNode
010 *
011 * @author
012 * <A HREF="http://www.alumni.caltech.edu/~croft/">David W. Croft</A>
013 * @version
014 * 1999-04-25
015 *********************************************************************/
016
017 public class ConditionalStatementMiniNode extends AbstractMiniNode
018 implements StatementMiniNode
019 //////////////////////////////////////////////////////////////////////
020 //////////////////////////////////////////////////////////////////////
021 {
022
023 protected ComparisonMiniNode comparisonMiniNode;
024 protected StatementSequenceMiniNode thenStatementSequenceMiniNode;
025 protected StatementSequenceMiniNode elseStatementSequenceMiniNode;
026
027 //////////////////////////////////////////////////////////////////////
028 //////////////////////////////////////////////////////////////////////
029
030 public ConditionalStatementMiniNode (
031 ComparisonMiniNode comparisonMiniNode,
032 StatementSequenceMiniNode thenStatementSequenceMiniNode,
033 StatementSequenceMiniNode elseStatementSequenceMiniNode )
034 //////////////////////////////////////////////////////////////////////
035 {
036 this.comparisonMiniNode = comparisonMiniNode;
037 this.thenStatementSequenceMiniNode = thenStatementSequenceMiniNode;
038 this.elseStatementSequenceMiniNode = elseStatementSequenceMiniNode;
039 }
040
041 public ConditionalStatementMiniNode (
042 ComparisonMiniNode comparisonMiniNode,
043 StatementSequenceMiniNode thenStatementSequenceMiniNode )
044 //////////////////////////////////////////////////////////////////////
045 {
046 this ( comparisonMiniNode, thenStatementSequenceMiniNode, null );
047 }
048
049 //////////////////////////////////////////////////////////////////////
050 //////////////////////////////////////////////////////////////////////
051
052 public ComparisonMiniNode getComparisonMiniNode ( )
053 //////////////////////////////////////////////////////////////////////
054 {
055 return comparisonMiniNode;
056 }
057
058 public StatementSequenceMiniNode getThenStatementSequenceMiniNode ( )
059 //////////////////////////////////////////////////////////////////////
060 {
061 return thenStatementSequenceMiniNode;
062 }
063
064 public StatementSequenceMiniNode getElseStatementSequenceMiniNode ( )
065 //////////////////////////////////////////////////////////////////////
066 {
067 return elseStatementSequenceMiniNode;
068 }
069
070 //////////////////////////////////////////////////////////////////////
071 // MiniNode interface methods
072 //////////////////////////////////////////////////////////////////////
073
074 public void generate ( MiniNodeCodeVisitor miniNodeCodeVisitor )
075 //////////////////////////////////////////////////////////////////////
076 {
077 miniNodeCodeVisitor.generateConditionalStatement ( this );
078 }
079
080 public void checkSemantics ( Stack parentMiniNodeStack )
081 throws SemanticErrorException
082 //////////////////////////////////////////////////////////////////////
083 {
084 parentMiniNodeStack.push ( this );
085
086 comparisonMiniNode.checkSemantics ( parentMiniNodeStack );
087
088 if ( thenStatementSequenceMiniNode != null )
089 {
090 thenStatementSequenceMiniNode.checkSemantics (
091 parentMiniNodeStack );
092 }
093
094 if ( elseStatementSequenceMiniNode != null )
095 {
096 elseStatementSequenceMiniNode.checkSemantics (
097 parentMiniNodeStack );
098 }
099
100 parentMiniNodeStack.pop ( );
101 }
102
103 //////////////////////////////////////////////////////////////////////
104 //////////////////////////////////////////////////////////////////////
105 }