编译原理课程设计---用java写的SNLCompiler(简单嵌套语言SNL的编译程序)

SNLCompiler词法分析截图SNLCompiler的语法分析截图简介:SNLCompiler是一个针对教学语言SNL(Simple Nest Language,其语法与pascal类似)的编译程序,SNLCompiler具有单步执行的功能,可以单独执行词法分析,语法分析等,并显示执行后得到的每一步的详细结果,现在仅提供了词法分析、语法分析中的递归下降法、LL(1)分析方法
摘要由CSDN通过智能技术生成

SNLCompiler界面截图

SNLCompiler词法分析截图

SNLCompiler界面截图

SNLCompiler的语法分析截图

简介:

SNLCompiler是一个针对教学语言SNL(Simple Nest Language,其语法与pascal类似)的编译程序,
SNLCompiler具有单步执行的功能,可以单独执行词法分析,语法分析等,并显示执行后得到的每一步的详细结果,现在仅提供了词法分析、语法分析中的递归下降法、LL(1)分析方法。SNLCompiler具有良好的结构,使用java语言编写,充分体现面向对象的优点,使用了大量的面向对象的设计模式(Composite、visitor、builder、facade、Simple Factory、Command的模式),具有良好的扩展性。
其中:
Composite模式(各个结点类):把结点来形成语法树.把基本的结点组合成复杂的接点,并最终形成语法树
visitor模式(SNLPrinter类):访问并打印语法树(也可以用在类型检查以及目标代码生成),把对结点的操作从结点类中分离,使结点增加一个操作变的容易
builder模式(ProgramNodeBuilder类):将复杂的语法树构建过程,细化到构建每一个结点并把这个过程隐藏,提供了插拔的构建方式
facade模式(CompilerFacade类):把Compiler各个子系统进行封装,给客户端一个简洁的界面。
Simple Factory模式(ActionFactory类):提供了一个数字与一个Action对象的简单映射,并且将这些无状态的Action对象进行缓寸,使得这些对象可以共享.
Command模式(所有Action类):把对一条文法的处理动作封装为一个对象,使用ActionFactory的高效的映射,避免了冗长的switch语句,并提高了性能。

代码部分(由于最近很忙注释不够详尽,特别是后面部分):

package edu.jlu.fuliang.cifa;

import java.io.*;
import java.util.*;

import javax.swing.JTextArea;
import edu.jlu.fuliang.Error;
import edu.jlu.fuliang.ErrorList;
import edu.jlu.fuliang.LexType;
import edu.jlu.fuliang.ReservedWord;


/*
 * 词法分析的主要的功能类,提供了单词扫描,并产生Token序列
 * 以及在扫描中及时地发现并处理错误等功能
 */
public class Scanner {
 private static final int EOF = -1;

 private BufferedReader reader;
 
 private PrintWriter out;

 private ArrayList<Token> tokenList;

 private JTextArea outputArea;

 private int lineNum, linePos;

 private String lineBuf = "";

 private ErrorList errorList;

 private ReservedWord[] reservedWord = new ReservedWord[] {
   new ReservedWord("program", LexType.PROGRAM),
   new ReservedWord("type", LexType.TYPE),
   new ReservedWord("var", LexType.VAR),
   new ReservedWord("procedure", LexType.PROCEDURE),
   new ReservedWord("begin", LexType.BEGIN),
   new ReservedWord("end", LexType.END),
   new ReservedWord("array", LexType.ARRAY),
   new ReservedWord("of", LexType.OF),
   new ReservedWord("record", LexType.RECORD),
   new ReservedWord("if", LexType.IF),
   new ReservedWord("then", LexType.THEN),
   new ReservedWord("else", LexType.ELSE),
   new ReservedWord("fi", LexType.FI),
   new ReservedWord("while", LexType.WHILE),
   new ReservedWord("do", LexType.DO),
   new ReservedWord("endwh", LexType.ENDWH),
   new ReservedWord("read", LexType.READ),
   new ReservedWord("write", LexType.WRITE),
   new ReservedWord("return", LexType.RETURN),
   new ReservedWord("integer", LexType.INTEGER),
   new ReservedWord("char", LexType.CHAR) };

 /*
  * 使用InputStream,和JTextArea类型作为参数,主要用作想在JTextArea中输出 词法分析的结果以及错误信息的Scanner实例
  */
 public Scanner(InputStream inputStream, JTextArea outputArea) {
  this(inputStream);
  this.outputArea = outputArea;
 }

 /*
  * 在控制台输出词法分析的 结果以及错误信息的Scanner实例
  */
 public Scanner(InputStream inputStream) {
  out = new PrintWriter(System.out, true);
  reader = new BufferedReader(new InputStreamReader(inputStream));
  tokenList = new ArrayList<Token>();
  errorList = new ErrorList();

  try {
   lineBuf = reader.readLine();
  } catch (IOException e) {
   e.printStackTrace();
  }
  lineBuf += '/n';
  lineNum = 1;
  linePos = 0;
 }
 /*
  * 使用OutputStream作为参数可以在文件或在控制台输出词法分析的 结果以及错误信息的Scanner实例
  */
 public Scanner(InputStream inputStream,OutputStream outputStream) {
  
     this.out = new PrintWriter(outputStream,true);
  reader = new BufferedReader(new InputStreamReader(inputStream));
  tokenList = new ArrayList<Token>();
  errorList = new ErrorList();
       
  try {
   lineBuf = reader.readLine();
  } catch (IOException e) {
   e.printStackTrace();
  }
  lineBuf += '/n';
  lineNum = 1;
  linePos = 0;
 }
 /*
  * 读取下一个单词
  */
 protected int getNextChar() {
  if (lineBuf == null)
   return EOF;
  if (linePos >= lineBuf.length()) {
   try {
    lineBuf = reader.readLine();
    if (lineBuf == null)
     return EOF;
    else {
     lineBuf += '/n';
     linePos = 0;
     lineNum++;
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  return lineBuf.charAt(linePos++);
 }

 /*
  * 回退一个单词
  */
 protected void unGetNextChar() {
  linePos--;
 }

 /*
  * 查询一个标识符是否为保留字类,如果是则返回类型该保留字的 类型,否则返回ID类型
  */
 protected int reservedLookup(String reserved) {
  for (int i = 0; i < reservedWord.length; i++) {
   if (reservedWord[i].getName().equals(reserved))
    return reservedWord[i].getLexType();
  }
  return LexType.ID;
 }
 /*
  * 扫描函数,形成一个token
  */
 protected Token scan() {
   Token curToken = new Token();
   StringBuffer buf = new StringBuffer("");
   processStartState(curToken, buf);
   curToken.setSem(buf.toString());
   if (curToken.getLex() == LexType.ID)
    curToken.setLex(reservedLookup(curToken.getSem()));
   curToken.setLineNum(lineNum);
   return curToken;
  }
 /*
  * 处理开始状态,根据读入的第一个字母决定下一个要处理的状态
  */
 private void processStartState(Token curToken, StringBuffer buf) {
  int c = getNextChar();

  if (Character.isDigit(c)) {
   buf.append((char) c);
   processNumState(curToken, buf);
  } else if (Character.isLetter(c)) {
   buf.append((char) c);
   processIDState(curToken, buf);
  } else if (c == ':') {
   buf.append((char) c);
   processAssignState(curToken, buf);
  } else if (c == '.') {
   buf.append((char) c);
   processRangeState(curToken, buf);
  } else if (c == '/'') {
   buf.append((char) c);
   processCharState(curToken, buf);
  } else if (c == '{')
   processCommentState(curToken, buf);
  else if (c == ' ' || c == '/t' || c == '/n') {
   processStartState(curToken,buf);
  } else {
   switch (c) {
   case EOF:
    curToken.setLex(LexType.ENDFILE);
    buf.append((char) c);
    break;
   case '=':
    curToken.setLex(LexType.EQ);
    buf.append((char) c);
    break;
   case '<':
    curToken.setLex(LexType.LT);
    buf.append((char) c);
    break;
   case '>':
    curToken.setLex(LexType.GT);
    buf.append((char) c);
    break;
   case '+':
    curToken.setLex(LexType.PLUS);
    buf.append((char) c);
    break;
   case '-':
    curToken.setLex(LexType.MINUS);
    buf.append((char) c);
    break;
   case '*':
    curToken.setLex(LexType.TIMES);
    buf.append((char) c);
    break;
   case '/':
    curToken.setLex(LexType.OVER);
    buf.append((char) c);
    break;
   case '(':
    curToken.setLex(LexType.LPAREN);
    buf.append((char) c);
    break;
   case ')':
    curToken.setLex(LexType.RPAREN);
    buf.append((char) c);
    break;
   case ';':
    curToken.setLex(LexType.SEMI);
    buf.append((char) c);
    break;
   case ',':
    curToken.setLex(LexType.COMMA);
    buf.append((char) c);
    break;
   case '[':
    curToken.setLex(LexType.LMIDPAREN);
    buf.append((char) c);
    break;
   case ']':
    curToken.setLex(LexType.RMIDPAREN);
    buf.append((char) c);
    break;
   default:
    curToken.setLex(LexType.ERROR);
    errorList.addError(new Error("Unexpected charactor: "
      + (char) c, lineNum));
    break;
   }
  }
 }
/*
 * 处理并识别赋值:=单词
 */
 protected void processAssignState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  if (c == '=') {
   curToken.setLex(LexType.ASSIGN);
   buf.append((char) c);
  } else {
   curToken.setLex(LexType.ERROR);
   errorList.addError(new Error("Unexpected charactor: " + (char) c,
     lineNum));
   unGetNextChar();
  }
 }
 /*
  * 处理并识别注释{...}单词
  */
 protected void processCommentState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  while (c != '}')
   c = getNextChar();
  processStartState(curToken, buf);
 }
 /*
  * 处理并识别数组下标中(子介)..单词
  */
 protected void processRangeState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  if (c == '.') {
   curToken.setLex(LexType.UNDERANGE);
   buf.append((char) c);
  } else {
   curToken.setLex(LexType.DOT);
   unGetNextChar();
  }
 }
/*
 * 处理并识别单个字符
 */
 protected void processCharState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  if (Character.isLetterOrDigit(c)) {

   int c1 = getNextChar();
   if (c1 == '/'') {
    curToken.setLex(LexType.CHARC);
    buf.append((char) c);
    buf.append((char) c1);
   } else {
    unGetNextChar();
    unGetNextChar();
    curToken.setLex(LexType.ERROR);
    errorList.addError(new Error("Unexpect charactor: " + (char) c,
      lineNum));
   }
  } else {
   unGetNextChar();
   curToken.setLex(LexType.ERROR);
   errorList.addError(new Error("Unexpected charactor: " + (char) c,
     lineNum));
  }
 }
 /*
  * 处理并识别标识符ID单词
  */
 protected void processIDState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  while (Character.isLetterOrDigit(c)) {
   buf.append((char) c);
   c = getNextChar();
  }
  unGetNextChar();
  curToken.setLex(LexType.ID);
 }
 /*
  * 处理并识别数字num单词
  */
 public void processNumState(Token curToken, StringBuffer buf) {
  int c = getNextChar();
  if (Character.isDigit(c)) {
   buf.append((char) c);
   c = getNextChar();
  }
  unGetNextChar();
  curToken.setLex(LexType.INTC);
 }
 /*
  * 获取下一个Token
  */
 public Token getNextToken() {
  return scan();
 }

 /*
  * 产生词法分析的Token序列
  */
 public void genTokenList() {
  Token token = scan();
  while (token.getLex() != LexType.ENDFILE) {
   tokenList.add(token);
   token = scan();
  }
  tokenList.add(token);
 }

 /*
  * 获取词法分析的token序列
  */
 public ArrayList<Token> getTokenList() {
  return tokenList;
 }

 /*
  * 在控制台上打印错误信息
  */
 public void printErrorInfoOnConsole() {
  genTokenList();
  int errorNum = errorList.getErrorNum();
  out.println("词法分析有:" + errorNum + " 个错误:");
  errorList.printErrors();
 }

 /*
  * 在JTextArea中打印错误信息
  */
 public void printErrorInfo() {
  genTokenList();
  int errorNum = errorList.getErrorNum();
  outputArea.append("词法分析有:" + errorNum + " 个错误:/n");
  ArrayList<Error> errors = errorList.getErrors();
  for (int i = 0; i < errorNum; i++) {
   outputArea.append("Error " + (i + 1) + " in line "
     + (errors.get(i).getLineNum()) + ": "
     + errors.get(i).getErrorInfo() + " ;/n");
  }
 }

 /*
  * 在控制台中打印Token序列
  */
 public void printTokenListOnConsole() {
  for (int i = 0; i < tokenList.size(); i++) {
   out.print(tokenList.get(i).getLineNum() + ": ");
   switch (tokenList.get(i).getLex()) {
   case LexType.ASSIGN:
   case LexType.EQ:
   case LexType.LT:
   case LexType.GT:
   case LexType.PLUS:
   case LexType.MINUS:
   case LexType.TIMES:
   case LexType.OVER:
   case LexType.LPAREN:
   case LexType.RPAREN:
   case LexType.DOT:
   case LexType.COMMA:
   case LexType.SEMI:
   case LexType.LMIDPAREN:
   case LexType.RMIDPAREN:
   case LexType.UNDERANGE:
    out.println(tokenList.get(i).getSem());
    break;
   case LexType.ID:
    out.println("ID, name = " + tokenList.get(i).getSem());
    break;
   case LexType.INTC:
    out.println("INTC, value = " + tokenList.get(i).getSem());
    break;
   case LexType.ENDFILE:
    out.println("EOF");
    break;
   case LexType.ERROR:
    out.println("EORR: " + tokenList.get(i).getSem());
    break;
   default:
    out.println("Resered word: " + tokenList.get(i).getSem());
    break;
   }
  }
 }

 /*
  * 在JTextArea中打印token序列
  */
 public void printTokenList() {
  for (int i = 0; i < tokenList.size(); i++) {
   outputArea.append(tokenList.get(i).getLineNum() + ": ");
   switch (tokenList.get(i).getLex()) {
   case LexType.ASSIGN:
   case LexType.EQ:
   case LexType.LT:
   case LexType.GT:
   case LexType.PLUS:
   case LexType.MINUS:
   case LexType.TIMES:
   case LexType.OVER:
   case LexType.LPAREN:
   case LexType.RPAREN:
   case LexType.DOT:
   case LexType.COMMA:
   case LexType.SEMI:
   case LexType.LMIDPAREN:
   case LexType.RMIDPAREN:
   case LexType.UNDERANGE:
    outputArea.append(tokenList.get(i).getSem() + "/n");
    break;
   case LexType.ID:
    outputArea.append("ID, name = " + tokenList.get(i).getSem()
      + "/n");
    break;
   case LexType.INTC:
    outputArea.append("INTC, value = " + tokenList.get(i).getSem()
      + "/n");
    break;
   case LexType.ENDFILE:
    outputArea.append("EOF/n");
    break;
   case LexType.ERROR:
    outputArea.append("EORR: " + tokenList.get(i).getSem() + "/n");
    break;
   default:
    outputArea.append("Resered word: " + tokenList.get(i).getSem()
      + "/n");
    break;
   }
  }
 }
}
package edu.jlu.fuliang.cifa;

/*
 * Token类,定义了该Token所在的行标,类型以及单词信息
 */
public class Token {
 
 private int lineNum;
 private int lex;
 private String sem;

 /*
  * 默认构造函数
  */
 public Token() {
  sem = "";
 }

 /*
  * 获取类型信息
  */
 public int getLex() {
  return lex;
 }

 /*
  * 设置类型信息
  */
 public void setLex(int lex) {
  this.lex = lex;
 }

 /*
  * 获取token所在的行标
  */
 public int getLineNum() {
  return lineNum;
 }

 /*
  * 设置Token所在的行标
  */
 public void setLineNum(int lineNum) {
  this.lineNum = lineNum;
 }

 /*
  * 获取Token的单词信息
  */
 public String getSem() {
  return sem;
 }

 /*
  * 设置Token的单词信息
  */
 public void setSem(String sem) {
  this.sem = sem;
 }
}

package edu.jlu.fuliang;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import javax.swing.tree.*;
import javax.swing.*;

import edu.jlu.fuliang.cifa.Scanner;
import edu.jlu.fuliang.yufa.LL1.ParseLL;
import edu.jlu.fuliang.yufa.Recursion.Parser;
import edu.jlu.fuliang.yufa.Recursion.Program;
import edu.jlu.fuliang.yufa.Recursion.ProgramNodeBuilder;
import edu.jlu.fuliang.yufa.Recursion.SNLPrinter;

import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

class Compiler extends JFrame {
 private JTextArea outputArea;

 private JDesktopPane desktop;

 private JTree tree;

 private DefaultMutableTreeNode root;

 private DefaultTreeModel model;

 private String filename = "";

 private int nextFrameX;

 private int nextFrameY;

 private int frameDistance;

 private Scanner scanner;

 static final int WIDTH = 600;

 static final int HEIGHT = 400;

 public Compiler() {
  outputArea = new JTextArea(10, 70);
  outputArea.setEditable(false);
  root = new DefaultMutableTreeNode("Workspace");

  tree = new JTree(root);
  model = new DefaultTreeModel(root);
  desktop = new JDesktopPane();

  JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    tree, desktop);
  innerPane.setContinuousLayout(true);
  innerPane.setOneTouchExpandable(true);

  JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
    innerPane, new JScrollPane(outputArea));

  outerPane.setContinuousLayout(true);
  outerPane.setOneTouchExpandable(true);

  Container container = getContentPane();
  container.setLayout(new GridLayout(1, 1));
  container.add(outerPane);

  JMenuBar menuBar = new JMenuBar();
  setJMenuBar(menuBar);
  JMenu fileMenu = new JMenu("文件");
  menuBar.add(fileMenu);
  JMenuItem openItem = new JMenuItem("打开");
  openItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    openFile();
   }
  });
  fileMenu.add(openItem);
  JMenuItem exitItem = new JMenuItem("退出");
  exitItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    System.exit(0);
   }
  });
  
  fileMenu.add(exitItem);
  JMenu windowMenu = new JMenu("窗口");
  menuBar.add(windowMenu);
  JMenuItem nextItem = new JMenuItem("下一个");
  nextItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    selectNextWindow();
   }
  });
  windowMenu.add(nextItem);
  JMenuItem cascadeItem = new JMenuItem("层叠");
  cascadeItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    cascadeWindows();
   }
  });
  
  windowMenu.add(cascadeItem);
  JMenuItem tileItem = new JMenuItem("平铺");
  tileItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    tileWindows();
   }
  });
  
  windowMenu.add(tileItem);
  final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem(
    "Drag Outline");
  dragOutlineItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE
        : JDesktopPane.LIVE_DRAG_MODE);
   }
  });
  
  windowMenu.add(dragOutlineItem);

  JMenu compilerMenu1 = new JMenu("单步执行");
  JMenuItem lexAnalzyMenuItem = new JMenuItem("词法分析");
  JMenu synAnalyzeMenu = new JMenu("语法分析");
  JMenuItem RDSynAnalyzeMenuItem = new JMenuItem("递归下降");
  JMenuItem LL1SynAnalyzeMenuItem = new JMenuItem("LL1分析法");
  
  compilerMenu1.add(lexAnalzyMenuItem);
  compilerMenu1.add(synAnalyzeMenu);
  
  synAnalyzeMenu.add(RDSynAnalyzeMenuItem);
  synAnalyzeMenu.add(LL1SynAnalyzeMenuItem);
  menuBar.add(compilerMenu1);

  lexAnalzyMenuItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
    outputArea.setText("");
    try {
     FileInputStream fis = new FileInputStream(filename);
     scanner = new Scanner(fis, outputArea);
    } catch (FileNotFoundException e1) {
     e1.printStackTrace();
    }
    scanner.printErrorInfo();
    scanner.printTokenList();
   }
  });
  
  RDSynAnalyzeMenuItem.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {
    outputArea.setText("");
    try {
     SNLPrinter printer = new SNLPrinter(new FileOutputStream(
       "result.txt"),new Spacing(7));

     FileInputStream fis = new FileInputStream(filename);
     scanner = new Scanner(fis, outputArea);
     ProgramNodeBuilder builder = new ProgramNodeBuilder();
     Parser parser = new Parser(scanner, builder,
       new FileOutputStream("error.txt"));
     
     Program p = (Program) builder.getTreeRoot();
     if (parser.isNoErrors()) {
      parser.PrintErrors();
      printer.visitProgram(p);
     } else {
      parser.PrintErrors();
     }
     BufferedReader br1 = new BufferedReader(
       new InputStreamReader(new FileInputStream(
         "error.txt")));
     BufferedReader br2 = new BufferedReader(
       new InputStreamReader(new FileInputStream(
         "result.txt")));
     String buf = null;
     while ((buf = br1.readLine()) != null) {
      outputArea.append(buf + "/n");
     }
     while ((buf = br2.readLine()) != null) {
      outputArea.append(buf + "/n");
     }
                    br1.close();
                    br2.close();
    } catch (IOException ex) {
     ex.printStackTrace();
    }
   }
  });
  
  LL1SynAnalyzeMenuItem.addActionListener(new ActionListener() {
   
   public void actionPerformed(ActionEvent e) {
    outputArea.setText("");
    try {
     SNLPrinter printer = new SNLPrinter(new FileOutputStream(
       "result.txt"),new Spacing(7));
     FileInputStream fis = new FileInputStream(filename);
     scanner = new Scanner(fis, outputArea);
     ParseLL parser = new ParseLL(scanner);
     Program p = (Program) parser.ParseProcess();
     if (parser.isNoErrors()) {
      printer.visitProgram(p);
     } else {
      parser.PrintErrors();
     }
     BufferedReader br = new BufferedReader(
       new InputStreamReader(new FileInputStream(
         "result.txt")));
     String buf = null;
     while ((buf = br.readLine()) != null) {
      outputArea.append(buf + "/n");
     }

    } catch (IOException ex) {
     ex.printStackTrace();
    }

   }
  });
  
  setSize(800, 600);
  setVisible(true);
 }

 public void createInternalFrame(Component c, String t) {
  final JInternalFrame iframe = new JInternalFrame(t, true, true, true);

  iframe.getContentPane().add(c);
  desktop.add(iframe);

  iframe.setFrameIcon(new ImageIcon("document.gif"));

  iframe.addVetoableChangeListener(new VetoableChangeListener() {
   public void vetoableChange(PropertyChangeEvent event)
     throws PropertyVetoException {
    String name = event.getPropertyName();
    Object value = event.getNewValue();

    if (name.equals("closed") && value.equals(Boolean.TRUE)) {
     int result = JOptionPane.showInternalConfirmDialog(iframe,
       "OK to close?");

     if (result != JOptionPane.YES_OPTION)
      throw new PropertyVetoException("User canceled close",
        event);
    }
   }
  });

  int width = desktop.getWidth() / 2;
  int height = desktop.getHeight() / 2;
  iframe.reshape(nextFrameX, nextFrameY, width, height);

  iframe.show();

  try {
   iframe.setSelected(true);
  } catch (PropertyVetoException e) {
  }

  if (frameDistance == 0)
   frameDistance = iframe.getHeight();
  iframe.getContentPane().getHeight();

  nextFrameX += frameDistance;
  nextFrameY += frameDistance;
  if (nextFrameX + width > desktop.getWidth())
   nextFrameX = 0;
  if (nextFrameY + height > desktop.getHeight())
   nextFrameY = 0;
 }

 public void cascadeWindows() {
  JInternalFrame[] frames = desktop.getAllFrames();
  int x = 0;
  int y = 0;

  int width = desktop.getWidth() / 2;
  int height = desktop.getHeight() / 2;

  for (int i = 0; i < frames.length; i++) {
   if (!frames[i].isIcon()) {
    try {
     frames[i].setMaximum(false);
     frames[i].reshape(x, y, width, height);

     x += frameDistance;
     y += frameDistance;

     if (x + width > desktop.getWidth())
      x = 0;
     if (y + height > desktop.getHeight())
      y = 0;
    } catch (PropertyVetoException e) {
    }
   }
  }
 }

 public void tileWindows() {
  JInternalFrame[] frames = desktop.getAllFrames();

  int frameCount = 0;
  for (int i = 0; i < frames.length; i++) {
   if (!frames[i].isIcon())
    frameCount++;
  }

  int rows = (int) Math.sqrt(frameCount);
  int cols = frameCount / rows;
  int extra = frameCount % rows;

  int width = desktop.getWidth() / cols;
  int height = desktop.getHeight() / rows;
  int r = 0;
  int c = 0;
  for (int i = 0; i < frames.length; i++) {
   if (!frames[i].isIcon()) {
    try {
     frames[i].setMaximum(false);
     frames[i].reshape(c * width, r * height, width, height);
     r++;
     if (r == rows) {
      r = 0;
      c++;
      if (c == cols - extra) {

       rows++;
       height = desktop.getHeight() / rows;
      }
     }
    } catch (PropertyVetoException e) {

    }
   }
  }
 }

 public void selectNextWindow() {
  JInternalFrame[] frames = desktop.getAllFrames();
  for (int i = 0; i < frames.length; i++) {
   if (frames[i].isSelected()) {

    try {
     int next = (i + 1) % frames.length;
     while (next != i && frames[next].isIcon())
      next = (next + 1) % frames.length;
     if (next == i)
      return;
     frames[next].setSelected(true);
     frames[next].toFront();
     return;
    } catch (PropertyVetoException e) {
    }
   }
  }
 }

 public void openFile() {

  JFileChooser chooser = new JFileChooser();
  chooser.setCurrentDirectory(new File("."));
  chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
   public boolean accept(File f) {
    String fname = f.getName().toLowerCase();
    return fname.endsWith(".txt") || fname.endsWith(".txt")
      || f.isDirectory();
   }

   public String getDescription() {
    return "Text Files";
   }
  });
  int r = chooser.showOpenDialog(this);

  if (r == JFileChooser.APPROVE_OPTION) {
   filename = chooser.getSelectedFile().getPath();
   StringTokenizer token = new StringTokenizer(filename, "//");
   ArrayList<DefaultMutableTreeNode> files = new ArrayList<DefaultMutableTreeNode>();
   int i = 1;
   files.add(root);
   while (token.hasMoreTokens()) {
    files.add(new DefaultMutableTreeNode(token.nextElement()));
    i++;
    model.insertNodeInto(files.get(i - 1), files.get(i - 2), 0);
   }
   try {
    URL fileUrl = new URL("file:" + filename);
    createInternalFrame(createEditorPane(fileUrl), filename);

   } catch (MalformedURLException e) {
   }
  }
 }

 public Component createEditorPane(URL u) {

  JEditorPane editorPane = new JEditorPane();
  editorPane.setEditable(false);
  editorPane.addHyperlinkListener(new HyperlinkListener() {
   public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
     createInternalFrame(createEditorPane(event.getURL()), event
       .getURL().toString());
   }
  });
  try {
   editorPane.setPage(u);
  } catch (IOException e) {
   editorPane.setText("Exception: " + e);
  }
  return new JScrollPane(editorPane);
 }

 public static void main(String[] args) {
  Compiler compiler = new Compiler();
  compiler.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
}

package edu.jlu.fuliang;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;

import edu.jlu.fuliang.cifa.Scanner;
import edu.jlu.fuliang.yufa.Recursion.*;

public class CompilerFacade {
 private Scanner scanner;
 private Parser parser;
 
 public CompilerFacade(){
  
 }
 
 public void LexAnalyze(String fileName){
  try {
   FileInputStream fis = new FileInputStream(fileName);
      scanner = new Scanner(fis);
      scanner.printErrorInfo();
   scanner.printTokenList();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  }
 }
 
 public void recursiveSynAnalyze(String fileName){
  SNLPrinter printer;
  try {
   printer = new SNLPrinter(new FileOutputStream(
   "result.txt"),new Spacing(7));
  
  if(scanner == null){
           FileInputStream fis = new FileInputStream(fileName);
           scanner = new Scanner(fis);
  }
          ProgramNodeBuilder builder = new ProgramNodeBuilder();
          Parser parser = new Parser(scanner, builder,
           new FileOutputStream("error.txt"));
          Program p = (Program) builder.getTreeRoot();
          if (parser.isNoErrors()) {
           parser.PrintErrors();
           printer.visitProgram(p);
         }   
          else {
       parser.PrintErrors();
           }
         BufferedReader br1 = new BufferedReader(
         new InputStreamReader(new FileInputStream(
     "error.txt")));
        BufferedReader br2 = new BufferedReader(
         new InputStreamReader(new FileInputStream(
     "result.txt")));
   } catch (FileNotFoundException e) {
   e.printStackTrace();
   }
 }
}

package edu.jlu.fuliang;

/*
 * Error类定义了整个SNLCompiler中错误的显示信息
 * 以及出现错误所在的行,便于错误的统一管理。
 */
public class Error {
 private String errorInfo;

 private int lineNum;

 /*
  * 使用一个类型为String表示信息,一个int表示出现错误的行来 创建一个错误实例
  */
 public Error(String errorInfo, int lineNum) {
  this.errorInfo = errorInfo;
  this.lineNum = lineNum;
 }

 /*
  * 获取错误的信息
  */
 public String getErrorInfo() {
  return errorInfo;
 }

 /*
  * 获取错误出现的行标
  */
 public int getLineNum() {
  return lineNum;
 }
}
package edu.jlu.fuliang;

import java.util.ArrayList;

/*
 * ErrorList主要是保存SNLCompiler在各个过程中出现的错误
 * 可能会带了一定的内存开销,在实用的编译器中并不可取,但在教
 * 学类的SNLCompiler,使用这个类主要是为错误的统一处理,以
 * 及错误信息的打印提供了方便,因为他将各个过程中出现的错误的
 * 打印工作分离开了,便于在不同方式下打印的移植(例如既像在控制
 * 台打印,又想在文本域内显示,或者二者之间的移植)
 */
public class ErrorList {
 private ArrayList<Error> errorList;

 /*
  * 默认的构造函数
  */
 public ErrorList() {
  errorList = new ArrayList<Error>();
 }

 /*
  * 向错误列表中添加错误信息
  */
 public void addError(Error err) {
  errorList.add(err);
 }

 /*
  * 获取错误列表
  */
 public ArrayList<Error> getErrors() {
  return errorList;
 }

 public void clearError() {
  errorList.clear();
 }

 /*
  * 打印错误信息
  */
 public void printErrors() {
  for (int i = 0; i < errorList.size(); i++) {
   System.out.println("Error " + (i + 1) + " in line "
     + (errorList.get(i).getLineNum()) + ": "
     + errorList.get(i).getErrorInfo() + " ;");
  }
 }

 /*
  * 获取错误的数目
  */
 public int getErrorNum() {
  return errorList.size();
 }

}
package edu.jlu.fuliang;

/*
 * 定义了Token的各种类型常量
 */
public class LexType {
 public final static int ENDFILE = -1;

 public final static int ERROR = -2;

 public final static int PROGRAM = -3;

 public final static int PROCEDURE = -4;

 public final static int TYPE = -5;

 public final static int VAR = -6;

 public final static int IF = -7;

 public final static int THEN = -8;

 public final static int ELSE = -9;

 public final static int FI = -10;

 public final static int DO = -11;

 public final static int WHILE = -12;

 public final static int ENDWH = -13;

 public final static int BEGIN = -14;

 public final static int END = -15;

 public final static int READ = -16;

 public final static int WRITE = -17;

 public final static int ARRAY = -18;

 public final static int OF = -19;

 public final static int RECORD = -20;

 public final static int RETURN = -21;

 public final static int INTEGER = -22;

 public final static int CHAR = -23;

 public final static int ID = -24;

 public final static int INTC = -25;

 public final static int CHARC = -26;

 public final static int ASSIGN = -27;

 public final static int EQ = -28;

 public final static int LT = -29;

 public final static int GT = -30;

 public final static int PLUS = -31;

 public final static int MINUS = -32;

 public final static int TIMES = -33;

 public final static int OVER = -34;

 public final static int LPAREN = -35;

 public final static int RPAREN = -36;

 public final static int DOT = -37;

 public final static int COLON = -38;

 public final static int SEMI = -39;

 public final static int COMMA = -40;

 public final static int LMIDPAREN = -41;

 public final static int RMIDPAREN = -42;

 public final static int UNDERANGE = -43;
}
package edu.jlu.fuliang;

/*
 * 保留字类,为保留字单独设置一个类,包含了自身的类型,
 * 和名字
 */
public class ReservedWord {
 private int lexType;

 private String name;

 public ReservedWord(String name, int lexType) {
  this.lexType = lexType;
  this.name = name;
 }

 /*
  * 获取类型信息
  */
 public int getLexType() {
  return lexType;
 }

 /*
  * 设置类型信息
  */
 public void setLexType(int lex) {
  this.lexType = lex;
 }

 /*
  * 获取保留字的名字
  */
 public String getName() {
  return name;
 }

 /*
  * 设置保留字的名字
  */
 public void setName(String name) {
  this.name = name;
 }
}

package edu.jlu.fuliang;

public class Spacing {
 public final int INDENT_AMT;// 缩进的字数

 public String spc = " ";
    public String brunch = "|---->";
 public int indentLevel;// 缩紧的层次

 public Spacing(int indentAmount) {
  INDENT_AMT = indentAmount;
 }

 public String toString() {
  return spc;
 }

 public void updateSpc(int numIndentLvls) {
   if(spc.length() >= brunch.length())
   spc = spc.substring(0,spc.length()-brunch.length());
  
     indentLevel += numIndentLvls;
  if (numIndentLvls < 0){
   spc = spc.substring(0,indentLevel * INDENT_AMT);
      spc += brunch;
  }
  else if (numIndentLvls > 0) {
   StringBuffer buf = new StringBuffer(spc);
   for (int i = 0; i < numIndentLvls * INDENT_AMT; ++i)
    buf.append(" ");
   buf.append(brunch);
   spc = buf.toString();
  }
 }
}

package edu.jlu.fuliang.yufa.LL1;

import edu.jlu.fuliang.yufa.Recursion.*;

public interface Action {
 public abstract void execute(Stack<Integer> signStack,
   Stack<Node> synTreeStack);

}
package edu.jlu.fuliang.yufa.LL1;

public class ActionFactory {
 //用来保存Action无状态的对象(无数据成员),并提供数与
 //Action对象的映射,不会造成内存开销,同时对象可以共享
 
 public Action[] actionsCache = new Action[] {
   null, new Process1Action(),
   new Process2Action(), new Process3Action(),
   new Process4Action(), new Process5Action(),
   new Process6Action(),new Process7Action(),
   new Process8Action(), new Process9Action(),
   new Process10Action(), new Process11Action(),
   new Process12Action(), new Process13Action(),
   new Process14Action(), new Process15Action(),
   new Process16Action(), new Process17Action(),
   new Process18Action(), new Process19Action(),
   new Process20Action(), new Process21Action(),
   new Process22Action(), new Process23Action(),
   new Process24Action(), new Process25Action(),
   new Process26Action(), new Process27Action(),
   new Process28Action(), new Process29Action(),
   new Process30Action(), new Process31Action(),
   new Process32Action(), new Process33Action(),
   new Process34Action(), new Process35Action(),
   new Process36Action(),
   new Process37Action(), new Process38Action(),
   new Process39Action(), new Process40Action(),
   new Process41Action(), new Process42Action(),
   new Process43Action(), new Process44Action(),
   new Process45Action(), new Process46Action(),
   new Process47Action(), new Process48Action(),
   new Process49Action(), new Process50Action(),
   new Process51Action(), new Process52Action(),
   new Process53Action(), new Process54Action(),
   new Process55Action(), new Process56Action(),
   new Process57Action(), new Process58Action(),
   new Process59Action(), new Process60Action(),
   new Process61Action(), new Process62Action(),
   new Process63Action(), new Process64Action(),
   new Process65Action(), new Process66Action(),
   new Process67Action(), new Process68Action(),
   new Process69Action(), new Process70Action(),
   new Process71Action(), new Process72Action(),
   new Process73Action(), new Process74Action(),
   new Process75Action(), new Process76Action(),
   new Process77Action(), new Process78Action(),
   new Process79Action(), new Process80Action(),
   new Process81Action(), new Process82Action(),
   new Process83Action(), new Process84Action(),
   new Process85Action(), new Process86Action(),
   new Process87Action(), new Process88Action(),
   new Process89Action(), new Process90Action(),
   new Process91Action(), new Process92Action(),
   new Process93Action(), new Process94Action(),
   new Process95Action(), new Process96Action(),
   new Process97Action(), new Process98Action(),
   new Process99Action(), new Process100Action(),
   new Process101Action(), new Process102Action(),
   new Process103Action(), new Process104Action()
   };

 public Action createActionInstance(int i) {
  return actionsCache[i];
 }
}
package edu.jlu.fuliang.yufa.LL1;

public class NontmlType {
 public final static int Program = 1;

 public final static int ProgramHead = 2;

 public final static int ProgramName = 3;

 public final static int DeclarePart = 4;

 public final static int TypeDec = 5;

 public final static int TypeDeclaration = 6;

 public final static int TypeDecMore = 7;

 public final static int TypeDecList = 8;

 public final static int staticTypeDecMore = 9;

 public final static int TypeId = 10;

 public final static int TypeName = 11;

 public final static int BaseType = 12;

 public final static int StructureType = 13;

 public final static int ArrayType = 14;

 public final static int Low = 15;

 public final static int Top = 16;

 public final static int RecType = 17;

 public final static int FieldDecList = 18;

 public final static int FieldDecMore = 19;

 public final static int IdList = 20;

 public final static int IdMore = 21;

 public final static int VarDec = 22;

 public final static int VarDeclaration = 23;

 public final static int VarDecList = 24;

 public final static int VarDecMore = 25;

 public final static int VarIdList = 26;

 public final static int VarIdMore = 27;

 public final static int ProcDec = 28;

 public final static int ProcDeclaration = 29;

 public final static int ProcDecMore = 30;

 public final static int ProcName = 31;

 public final static int ParamList = 32;

 public final static int ParamDecList = 33;

 public final static int ParamMore = 34;

 public final static int Param = 35;

 public final static int FormList = 36;

 public final static int FidMore = 37;

 public final static int ProcDecPart = 38;

 public final static int ProcBody = 39;

 public final static int ProgramBody = 40;

 public final static int StmList = 41;

 public final static int StmMore = 42;

 public final static int Stm = 43;

 public final static int AssCall = 44;

 public final static int AssignmentRest = 45;

 public final static int ConditionalStm = 46;

 public final static int StmL = 47;

 public final static int LoopStm = 48;

 public final static int InputStm = 49;

 public final static int InVar = 50;

 public final static int OutputStm = 51;

 public final static int ReturnStm = 52;

 public final static int CallStmRest = 53;

 public final static int ActParamList = 54;

 public final static int ActParamMore = 55;

 public final static int RelExp = 56;

 public final static int OtherRelE = 57;

 public final static int Exp = 58;

 public final static int OtherTerm = 59;

 public final static int Term = 60;

 public final static int OtherFactor = 61;

 public final static int Factor = 62;

 public final static int Variable = 63;

 public final static int VariMore = 64;

 public final static int FieldVar = 65;

 public final static int FieldVarMore = 66;

 public final static int CmpOp = 67;

 public final static int AddOp = 68;

 public final static int MultOp = 69;
}
package edu.jlu.fuliang.yufa.LL1;

import edu.jlu.fuliang.Error;
import edu.jlu.fuliang.ErrorList;
import edu.jlu.fuliang.LexType;
import edu.jlu.fuliang.cifa.Scanner;
import edu.jlu.fuliang.cifa.Token;
import edu.jlu.fuliang.yufa.Recursion.*;

public class ParseLL {
 private int LL1Table[][] = new int[106][45];

 private Scanner scanner;

 private Stack<Integer> signStack;

 private Stack<Node> synTreeStack;

 private ErrorList errorList;

 public ParseLL(Scanner scanner) {
  for (int i = 0; i < 106; i++)
   for (int j = 0; j < 42; j++) {
    LL1Table[i][j] = 0;
   }
  this.scanner = scanner;
  signStack = new Stack<Integer>();
  synTreeStack = new Stack<Node>();
  errorList = new ErrorList();
  createLL1Table();
 }
 
 public void PrintErrors() {
  int errorNum = errorList.getErrorNum();
  System.out.println("语法分析有:" + errorNum + " 个错误:");
  errorList.printErrors();
 }
 
    public boolean isNoErrors(){
     return errorList.getErrorNum() == 0 ? true : false ;
    }
   
 protected void createLL1Table() {
  LL1Table[NontmlType.Program][-LexType.PROGRAM] = 1;

  LL1Table[NontmlType.ProgramHead][-LexType.PROGRAM] = 2;

  LL1Table[NontmlType.ProgramName][-LexType.ID] = 3;

  LL1Table[NontmlType.DeclarePart][-LexType.TYPE] = 4;
  LL1Table[NontmlType.DeclarePart][-LexType.VAR] = 4;
  LL1Table[NontmlType.DeclarePart][-LexType.PROCEDURE] = 4;
  LL1Table[NontmlType.DeclarePart][-LexType.BEGIN] = 4;

  LL1Table[NontmlType.TypeDec][-LexType.VAR] = 5;
  LL1Table[NontmlType.TypeDec][-LexType.PROCEDURE] = 5;
  LL1Table[NontmlType.TypeDec][-LexType.BEGIN] = 5;

  LL1Table[NontmlType.TypeDec][-LexType.TYPE] = 6;

  LL1Table[NontmlType.TypeDeclaration][-LexType.TYPE] = 7;

  LL1Table[NontmlType.TypeDecList][-LexType.ID] = 8;

  LL1Table[NontmlType.TypeDecMore][-LexType.VAR] = 9;
  LL1Table[NontmlType.TypeDecMore][-LexType.PROCEDURE] = 9;
  LL1Table[NontmlType.TypeDecMore][-LexType.BEGIN] = 9;

  LL1Table[NontmlType.TypeDecMore][-LexType.ID] = 10;

  LL1Table[NontmlType.TypeId][-LexType.ID] = 11;

  LL1Table[NontmlType.TypeName][-LexType.INTEGER] = 12;
  LL1Table[NontmlType.TypeName][-LexType.CHAR] = 12;

  LL1Table[NontmlType.TypeName][-LexType.ARRAY] = 13;
  LL1Table[NontmlType.TypeName][-LexType.RECORD] = 13;

  LL1Table[NontmlType.TypeName][-LexType.ID] = 14;

  LL1Table[NontmlType.BaseType][-LexType.INTEGER] = 15;

  LL1Table[NontmlType.BaseType][-LexType.CHAR] = 16;

  LL1Table[NontmlType.StructureType][-LexType.ARRAY] = 17;

  LL1Table[NontmlType.StructureType][-LexType.RECORD] = 18;

  LL1Table[NontmlType.ArrayType][-LexType.ARRAY] = 19;

  LL1Table[NontmlType.Low][-LexType.INTC] = 20;

  LL1Table[NontmlType.Top][-LexType.INTC] = 21;

  LL1Table[NontmlType.RecType][-LexType.RECORD] = 22;

  LL1Table[NontmlType.FieldDecList][-LexType.INTEGER] = 23;
  LL1Table[NontmlType.FieldDecList][-LexType.CHAR] = 23;

  LL1Table[NontmlType.FieldDecList][-LexType.ARRAY] = 24;

  LL1Table[NontmlType.FieldDecMore][-LexType.END] = 25;

  LL1Table[NontmlType.FieldDecMore][-LexType.INTEGER] = 26;
  LL1Table[NontmlType.FieldDecMore][-LexType.CHAR] = 26;
  LL1Table[NontmlType.FieldDecMore][-LexType.ARRAY] = 26;

  LL1Table[NontmlType.IdList][-LexType.ID] = 27;

  LL1Table[NontmlType.IdMore][-LexType.SEMI] = 28;

  LL1Table[NontmlType.IdMore][-LexType.COMMA] = 29;

  LL1Table[NontmlType.VarDec][-LexType.PROCEDURE] = 30;
  LL1Table[NontmlType.VarDec][-LexType.BEGIN] = 30;

  LL1Table[NontmlType.VarDec][-LexType.VAR] = 31;

  LL1Table[NontmlType.VarDeclaration][-LexType.VAR] = 32;

  LL1Table[NontmlType.VarDecList][-LexType.INTEGER] = 33;
  LL1Table[NontmlType.VarDecList][-LexType.CHAR] = 33;
  LL1Table[NontmlType.VarDecList][-LexType.ARRAY] = 33;
  LL1Table[NontmlType.VarDecList][-LexType.RECORD] = 33;
  LL1Table[NontmlType.VarDecList][-LexType.ID] = 33;

  LL1Table[NontmlType.VarDecMore][-LexType.PROCEDURE] = 34;
  LL1Table[NontmlType.VarDecMore][-LexType.BEGIN] = 34;

  LL1Table[NontmlType.VarDecMore][-LexType.INTEGER] = 35;
  LL1Table[NontmlType.VarDecMore][-LexType.CHAR] = 35;
  LL1Table[NontmlType.VarDecMore][-LexType.ARRAY] = 35;
  LL1Table[NontmlType.VarDecMore][-LexType.RECORD] = 35;
  LL1Table[NontmlType.VarDecMore][-LexType.ID] = 35;

  LL1Table[NontmlType.VarIdList][-LexType.ID] = 36;

  LL1Table[NontmlType.VarIdMore][-LexType.SEMI] = 37;

  LL1Table[NontmlType.VarIdMore][-LexType.COMMA] = 38;

  LL1Table[NontmlType.ProcDec][-LexType.BEGIN] = 39;

  LL1Table[NontmlType.ProcDec][-LexType.PROCEDURE] = 40;

  LL1Table[NontmlType.ProcDeclaration][-LexType.PROCEDURE] = 41;

  LL1Table[NontmlType.ProcDecMore][-LexType.BEGIN] = 42;

  LL1Table[NontmlType.ProcDecMore][-LexType.PROCEDURE] = 43;

  LL1Table[NontmlType.ProcDecMore][-LexType.DOT] = 42;
  
  LL1Table[NontmlType.ProcName][-LexType.ID] = 44;

  LL1Table[NontmlType.ParamList][-LexType.RPAREN] = 45;

  LL1Table[NontmlType.ParamList][-LexType.INTEGER] = 46;
  LL1Table[NontmlType.ParamList][-LexType.CHAR] = 46;
  LL1Table[NontmlType.ParamList][-LexType.ARRAY] = 46;
  LL1Table[NontmlType.ParamList][-LexType.RECORD] = 46;
  LL1Table[NontmlType.ParamList][-LexType.ID] = 46;
  LL1Table[NontmlType.ParamList][-LexType.VAR] = 46;

  LL1Table[NontmlType.ParamDecList][-LexType.INTEGER] = 47;
  LL1Table[NontmlType.ParamDecList][-LexType.CHAR] = 47;
  LL1Table[NontmlType.ParamDecList][-LexType.ARRAY] = 47;
  LL1Table[NontmlType.ParamDecList][-LexType.RECORD] = 47;
  LL1Table[NontmlType.ParamDecList][-LexType.ID] = 47;
  LL1Table[NontmlType.ParamDecList][-LexType.VAR] = 47;

  LL1Table[NontmlType.ParamMore][-LexType.RPAREN] = 48;

  LL1Table[NontmlType.ParamMore][-LexType.SEMI] = 49;

  LL1Table[NontmlType.Param][-LexType.INTEGER] = 50;
  LL1Table[NontmlType.Param][-LexType.CHAR] = 50;
  LL1Table[NontmlType.Param][-LexType.ARRAY] = 50;
  LL1Table[NontmlType.Param][-LexType.RECORD] = 50;
  LL1Table[NontmlType.Param][-LexType.ID] = 50;

  LL1Table[NontmlType.Param][-LexType.VAR] = 51;

  LL1Table[NontmlType.FormList][-LexType.ID] = 52;

  LL1Table[NontmlType.FidMore][-LexType.SEMI] = 53;
  LL1Table[NontmlType.FidMore][-LexType.RPAREN] = 53;

  LL1Table[NontmlType.FidMore][-LexType.COMMA] = 54;

  LL1Table[NontmlType.ProcDecPart][-LexType.TYPE] = 55;
  LL1Table[NontmlType.ProcDecPart][-LexType.VAR] = 55;
  LL1Table[NontmlType.ProcDecPart][-LexType.PROCEDURE] = 55;
  LL1Table[NontmlType.ProcDecPart][-LexType.BEGIN] = 55;

  LL1Table[NontmlType.ProcBody][-LexType.BEGIN] = 56;

  LL1Table[NontmlType.ProgramBody][-LexType.BEGIN] = 57;

  LL1Table[NontmlType.StmList][-LexType.ID] = 58;
  LL1Table[NontmlType.StmList][-LexType.IF] = 58;
  LL1Table[NontmlType.StmList][-LexType.WHILE] = 58;
  LL1Table[NontmlType.StmList][-LexType.RETURN] = 58;
  LL1Table[NontmlType.StmList][-LexType.READ] = 58;
  LL1Table[NontmlType.StmList][-LexType.WRITE] = 58;

  LL1Table[NontmlType.StmMore][-LexType.END] = 59;
  LL1Table[NontmlType.StmMore][-LexType.ENDWH] = 59;
  LL1Table[NontmlType.StmMore][-LexType.ELSE] = 59;
  LL1Table[NontmlType.StmMore][-LexType.FI] = 59;

  LL1Table[NontmlType.StmMore][-LexType.SEMI] = 60;

  LL1Table[NontmlType.Stm][-LexType.IF] = 61;

  LL1Table[NontmlType.Stm][-LexType.WHILE] = 62;

  LL1Table[NontmlType.Stm][-LexType.READ] = 63;

  LL1Table[NontmlType.Stm][-LexType.WRITE] = 64;

  LL1Table[NontmlType.Stm][-LexType.RETURN] = 65;

  LL1Table[NontmlType.Stm][-LexType.ID] = 66;

  LL1Table[NontmlType.AssCall][-LexType.ASSIGN] = 67;
  LL1Table[NontmlType.AssCall][-LexType.LMIDPAREN] = 67;
  LL1Table[NontmlType.AssCall][-LexType.DOT] = 67;

  LL1Table[NontmlType.AssCall][-LexType.LPAREN] = 68;

  LL1Table[NontmlType.AssignmentRest][-LexType.ASSIGN] = 69;
  LL1Table[NontmlType.AssignmentRest][-LexType.LMIDPAREN] = 69;
  LL1Table[NontmlType.AssignmentRest][-LexType.DOT] = 69;

  LL1Table[NontmlType.ConditionalStm][-LexType.IF] = 70;

  LL1Table[NontmlType.LoopStm][-LexType.WHILE] = 71;

  LL1Table[NontmlType.InputStm][-LexType.READ] = 72;

  LL1Table[NontmlType.InVar][-LexType.ID] = 73;

  LL1Table[NontmlType.OutputStm][-LexType.WRITE] = 74;

  LL1Table[NontmlType.ReturnStm][-LexType.RETURN] = 75;

  LL1Table[NontmlType.CallStmRest][-LexType.LPAREN] = 76;

  LL1Table[NontmlType.ActParamList][-LexType.RPAREN] = 77;

  LL1Table[NontmlType.ActParamList][-LexType.ID] = 78;
  LL1Table[NontmlType.ActParamList][-LexType.INTC] = 78;
  LL1Table[NontmlType.ActParamList][-LexType.LPAREN] = 78;

  LL1Table[NontmlType.ActParamMore][-LexType.RPAREN] = 79;

  LL1Table[NontmlType.ActParamMore][-LexType.COMMA] = 80;

  LL1Table[NontmlType.RelExp][-LexType.LPAREN] = 81;
  LL1Table[NontmlType.RelExp][-LexType.INTC] = 81;
  LL1Table[NontmlType.RelExp][-LexType.ID] = 81;

  LL1Table[NontmlType.OtherRelE][-LexType.LT] = 82;
  LL1Table[NontmlType.OtherRelE][-LexType.EQ] = 82;

  LL1Table[NontmlType.Exp][-LexType.LPAREN] = 83;
  LL1Table[NontmlType.Exp][-LexType.INTC] = 83;
  LL1Table[NontmlType.Exp][-LexType.ID] = 83;

  LL1Table[NontmlType.OtherTerm][-LexType.LT] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.EQ] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.THEN] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.DO] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.RPAREN] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.END] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.SEMI] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.COMMA] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.ENDWH] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.ELSE] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.FI] = 84;
  LL1Table[NontmlType.OtherTerm][-LexType.RMIDPAREN] = 84;

  LL1Table[NontmlType.OtherTerm][-LexType.PLUS] = 85;
  LL1Table[NontmlType.OtherTerm][-LexType.MINUS] = 85;

  LL1Table[NontmlType.Term][-LexType.LPAREN] = 86;
  LL1Table[NontmlType.Term][-LexType.INTC] = 86;
  LL1Table[NontmlType.Term][-LexType.ID] = 86;

  LL1Table[NontmlType.OtherFactor][-LexType.PLUS] = 87;
  LL1Table[NontmlType.OtherFactor][-LexType.MINUS] = 87;
  LL1Table[NontmlType.OtherFactor][-LexType.LT] 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值