/*
PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations.
Copyright (C) 2008 Brandon Malone, Frank Hadlock
This file is part of the PseudoCode Interpreted Language.
PseudoCode Interpreted Language is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
PseudoCode Interpreted Language is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with
PseudoCode Interpreted Language. If not, see
.
*/
/*
* SyntaxAnalyzerPanel.java
*
* Created on March 2, 2008, 8:04 PM
*/
package syntacticanalysis;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import lex.Analyzer;
/**
*
* @author Brandon
*/
public class SyntaxAnalyzerPanel extends javax.swing.JPanel {
/**
* Creates new form SyntaxAnalyzerPanel
*/
public SyntaxAnalyzerPanel() {
initComponents();
dynamicmvc.View view = new dynamicmvc.View();
add(view);
this.tbGrammarFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\PCILGrammar.txt");
this.tbNewGrammarFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\NewPCILGrammar.txt");
this.tbParseTableFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\pcilTriples.txt");
this.tbNewParseTableFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\newPcilTriples.txt");
this.tbSourceTokenFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\tokens.txt");
this.tbPostfixTokenFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\postfixTokens.txt");
this.tbPseudocodeFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\Euclid.txt");
analyze();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jFileChooser1 = new javax.swing.JFileChooser();
jLabel1 = new javax.swing.JLabel();
btnGrammarFileBrowse = new javax.swing.JButton();
tbGrammarFile = new javax.swing.JTextField();
btnAnalyze = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
btnBrowseNewGrammarFile = new javax.swing.JButton();
tbNewGrammarFile = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
btnBrowseParseTable = new javax.swing.JButton();
tbParseTableFile = new javax.swing.JTextField();
tbNewParseTableFile = new javax.swing.JTextField();
btnBrowseNewParseTableFile = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
btnBrowseSourceTokenFile = new javax.swing.JButton();
tbSourceTokenFile = new javax.swing.JTextField();
tbPostfixTokenFile = new javax.swing.JTextField();
btnBrowsePostfixTokenFile = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
btnBrowsePseudocodeFile = new javax.swing.JButton();
tbPseudocodeFile = new javax.swing.JTextField();
setBorder(javax.swing.BorderFactory.createTitledBorder("Syntax Analyzer"));
jLabel1.setText("Grammar File");
btnGrammarFileBrowse.setText("Browse");
btnGrammarFileBrowse.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnGrammarFileBrowseMouseClicked(evt);
}
});
btnAnalyze.setText("Analyze");
btnAnalyze.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnAnalyzeMouseClicked(evt);
}
});
jLabel2.setText("New Grammar File");
btnBrowseNewGrammarFile.setText("Browse");
btnBrowseNewGrammarFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseNewGrammarFileMouseClicked(evt);
}
});
jLabel3.setText("Parse Table File");
btnBrowseParseTable.setText("Browse");
btnBrowseParseTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseParseTableMouseClicked(evt);
}
});
btnBrowseNewParseTableFile.setText("Browse");
btnBrowseNewParseTableFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseNewParseTableFileMouseClicked(evt);
}
});
jLabel4.setText("New Parse Table File");
jLabel5.setText("Source Token File");
btnBrowseSourceTokenFile.setText("Browse");
btnBrowseSourceTokenFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseSourceTokenFileMouseClicked(evt);
}
});
btnBrowsePostfixTokenFile.setText("Browse");
btnBrowsePostfixTokenFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowsePostfixTokenFileMouseClicked(evt);
}
});
jLabel6.setText("Postfix Token File");
jLabel7.setText("Pseudocode File");
btnBrowsePseudocodeFile.setText("Browse");
btnBrowsePseudocodeFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowsePseudocodeFileMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(419, 419, 419)
.addComponent(btnAnalyze, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(tbSourceTokenFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBrowseSourceTokenFile))
.addGroup(layout.createSequentialGroup()
.addComponent(tbGrammarFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnGrammarFileBrowse))
.addGroup(layout.createSequentialGroup()
.addComponent(tbNewGrammarFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBrowseNewGrammarFile))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(tbNewParseTableFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
.addComponent(tbParseTableFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnBrowseParseTable)
.addComponent(btnBrowseNewParseTableFile)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(tbPseudocodeFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
.addComponent(tbPostfixTokenFile, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnBrowsePostfixTokenFile, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnBrowsePseudocodeFile, javax.swing.GroupLayout.Alignment.TRAILING))))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(btnGrammarFileBrowse)
.addComponent(tbGrammarFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btnBrowseNewGrammarFile)
.addComponent(tbNewGrammarFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(btnBrowseParseTable)
.addComponent(tbParseTableFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnBrowseNewParseTableFile)
.addComponent(jLabel4)
.addComponent(tbNewParseTableFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(btnBrowseSourceTokenFile)
.addComponent(tbSourceTokenFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnBrowsePostfixTokenFile)
.addComponent(jLabel6)
.addComponent(tbPostfixTokenFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(btnBrowsePseudocodeFile)
.addComponent(tbPseudocodeFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
.addComponent(btnAnalyze)
.addContainerGap())
);
}// //GEN-END:initComponents
private void btnBrowsePseudocodeFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowsePseudocodeFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbPseudocodeFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowsePseudocodeFileMouseClicked
private void btnBrowsePostfixTokenFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowsePostfixTokenFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbPostfixTokenFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowsePostfixTokenFileMouseClicked
private void btnBrowseSourceTokenFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseSourceTokenFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbSourceTokenFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseSourceTokenFileMouseClicked
private void btnBrowseNewParseTableFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseNewParseTableFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbNewParseTableFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseNewParseTableFileMouseClicked
private void btnBrowseParseTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseParseTableMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbParseTableFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseParseTableMouseClicked
private void btnBrowseNewGrammarFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseNewGrammarFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbNewGrammarFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseNewGrammarFileMouseClicked
private void btnAnalyzeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAnalyzeMouseClicked
analyze();
}//GEN-LAST:event_btnAnalyzeMouseClicked
private void analyze() {
try {
// TODO add your handling code here:
String pseudocodeFilePath = tbPseudocodeFile.getText();
String sourceTokenFilePath = tbSourceTokenFile.getText();
Analyzer a = new Analyzer();
a.analyze(pseudocodeFilePath, sourceTokenFilePath);
Grammar g = Grammar.createFromFile(tbGrammarFile.getText());//, this.tbParseTableFile.getText());
SyntaxAnalyzer s = new SyntaxAnalyzer(g);
ArrayList postfixTokens = s.analyze(tbSourceTokenFile.getText());
PostfixToken.writeToFile(postfixTokens, tbPostfixTokenFile.getText());
ArrayList functions = s.findFunctions(postfixTokens);
//dynamicmvc.DynamicController c = new dynamicmvc.DynamicController();
//c.interpret(postfixTokens);
//g.toFile(tbNewGrammarFile.getText());
//g.parseTableToFile(tbNewParseTableFile.getText());
} catch (Exception ex) {
//javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception:\n" + ex.getMessage());
ex.printStackTrace();
}
}
private void btnGrammarFileBrowseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnGrammarFileBrowseMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbGrammarFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnGrammarFileBrowseMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAnalyze;
private javax.swing.JButton btnBrowseNewGrammarFile;
private javax.swing.JButton btnBrowseNewParseTableFile;
private javax.swing.JButton btnBrowseParseTable;
private javax.swing.JButton btnBrowsePostfixTokenFile;
private javax.swing.JButton btnBrowsePseudocodeFile;
private javax.swing.JButton btnBrowseSourceTokenFile;
private javax.swing.JButton btnGrammarFileBrowse;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField tbGrammarFile;
private javax.swing.JTextField tbNewGrammarFile;
private javax.swing.JTextField tbNewParseTableFile;
private javax.swing.JTextField tbParseTableFile;
private javax.swing.JTextField tbPostfixTokenFile;
private javax.swing.JTextField tbPseudocodeFile;
private javax.swing.JTextField tbSourceTokenFile;
// End of variables declaration//GEN-END:variables
}