/*
 * Title: CMinusParserDemo
 * Author: Matthew Boyette
 * Date: 11/08/2016
 * 
 * This is a test program demonstrating a syntactical analyzer class for the C-Minus language.
 */

import java.util.List;
import api.util.Support;
import api.util.cminus.CMinusLexer;
import api.util.cminus.CMinusParser;
import api.util.cminus.CMinusSemantics;
import api.util.datastructures.Token;
import edu.princeton.cs.algs4.StdOut;

public class CMinusSemanticsDemo
{
    public static void main(String[] args)
    {
        final boolean SILENT = true;

        if ( args.length > 0 ) // Allow user to select multiple files sequentially using command-line arguments. Each argument is a separate file name.
        {
            for ( int i = 0; i < args.length; i++ )
            {
                CMinusSemantics.errorFlag = false;
                CMinusSemantics.seenMain  = false;

                CMinusSemanticsDemo.run(args[i], SILENT);
            }
        }
        else // Allow user to select a file using a GUI.
        {
            String fileName = Support.getFilePath(null, true, !SILENT);

            CMinusSemanticsDemo.run(fileName, SILENT);
        }
    }

    public static void run(final String fileName, final boolean silent)
    {
        // Create an instance of the lexical analyzer.
        CMinusLexer<CMinusLexer.TokenType> lexer = new CMinusLexer<CMinusLexer.TokenType>();

        // Get the Tokens recognized by the lexer.
        List<Token<CMinusLexer.TokenType>> tokens = lexer.lexFile(fileName, silent, true, true);

        if ( !silent )
        {
            StdOut.println();
        }

        // Create symbol tables.
        CMinusSemantics.SymTab<CMinusSemantics.SymTabRec> symbolTables = new CMinusSemantics.SymTab<CMinusSemantics.SymTabRec>();

        // Create an instance of the parser; pass the tokens and the symbol tables to it.
        CMinusParser parser = new CMinusParser(tokens, symbolTables, silent);

        if ( parser.getResult().contentEquals("ACCEPT") )
        {
            // Create an instance of the semantic analyzer; pass the tokens and the symbol tables to it.
            CMinusSemantics semantics = new CMinusSemantics(tokens, symbolTables, silent);

            StdOut.println(semantics.getResult());
        }
        else
        {
            StdOut.println(parser.getResult());
        }
    }
}

@@ -12,22 +12,25 @@
 : CMinus
-Parser
+Semantics
 Demo%0A * 
@@ -72,16 +72,29 @@
 /08/2016
+ - 04/04/2017
 %0A * %0A * 
@@ -137,18 +137,15 @@
  a s
-yntactical
+emantic
  ana
@@ -389,46 +389,8 @@
 ken;
-%0Aimport edu.princeton.cs.algs4.StdOut;
 %0A%0Apu
@@ -757,93 +757,108 @@
     
-CMinusSemantics.errorFlag = false;%0A                CMinusSemantics.seenMain  = false;
+if ( i %3E 0 )%0A                %7B%0A                    CMinusSemantics.reinitialize();%0A                %7D
 %0A%0A  

Update CMinusSemanticsDemo.java