}
return new int[] { i, j };
} }
package compile2; import java.io.*; import java.util.*;
public class main {
public static void scan(String infile,String outfile, Stack
throws Exception {
expression)
java.io.File file = new java.io.File(infile); Scanner input = new Scanner(file);
java.io.PrintWriter output = new PrintWriter(outfile); int count = 0; word[count].push(\while (input.hasNext()) { }
public static void main(String[] args) throws Exception {
String infile = \String outfile = \Stack[] word = new Stack[5];
Stack[] expression = new Stack[word.length]; for (int i = 0; i < word.length; i++){ }
scan(infile, outfile, word, expression);
word[i] = new Stack
static String[] key_word = { \
\
\\
static String[] cal_word = { \
String tmp = input.next(); int i = 0;
while (i < tmp.length()) {
if (tmp.charAt(i) <= '9' && tmp.charAt(i) >= '1') {//检查十进制数字 }
if (i + 2 < tmp.length())// 检查十六进制数字
if (tmp.charAt(i) == '0' && tmp.charAt(i + 1) == 'x') { }
if (tmp.charAt(i) == '0') {
i++;
String num = \
while (tmp.charAt(i) <= '7' && tmp.charAt(i) >= '0') { }
output.println(\word[count].push(\
num += tmp.charAt(i); i++;
if (i == tmp.length())
break;
i += 2; String num = \
while ((tmp.charAt(i) <= '9' && tmp.charAt(i) >= '0') || }
output.println(\word[count].push(\expression[count].push(num);
i++;
if (i == tmp.length())
break;
(tmp.charAt(i) <= 'f' && tmp.charAt(i) >= 'a')) { num += tmp.charAt(i);
String num = \
while (tmp.charAt(i) <= '9' && tmp.charAt(i) >= '0') { }
output.println(\word[count].push(\expression[count].push(num);
num += tmp.charAt(i); i++;
if (i == tmp.length())
break;
if (i + 1 < tmp.length())// 检查八进制数字
}
expression[count].push(num);
// 检查关键字和变量 if (i < tmp.length()) { }
// 检查运算符以及';' if (i < tmp.length()) {
if (i + 1 < tmp.length()) {
if (tmp.charAt(i + 1) == '=') {
for (int j = 0; j < cal_word.length; j++) {
if (cal_word[j].equals(\
+ tmp.charAt(i + 1))) {
+ \
output.println(\word[count].push(cal_word[j]); expression[count].push(\
if (i < tmp.length() && tmp.charAt(i) >= 'a' }
&& tmp.charAt(i) <= 'z') { String tmp_word = \
while (tmp.charAt(i) >= 'a' && tmp.charAt(i) <= 'z') { }
boolean is_keyword = false;
for (int j = 0; j < key_word.length; j++) { }
if (!is_keyword) { }
output.println(\word[count].push(\
expression[count].push(tmp_word); if (tmp_word.equals(key_word[j])) { }
output.println(\word[count].push(key_word[j]); expression[count].push(key_word[j]); is_keyword = true; break;
tmp_word += tmp.charAt(i); i++;
if (i == tmp.length())
break;
}
}
}
}
}
}
}
}
}
if (word[count].peek() == \ } i += 2; break;
word[count].pop(); word[count].push(\count++;
word[count].push(\
for (int j = 0; j < cal_word.length; j++) { }
if (cal_word[j].equals(\ }
output.println(\word[count].push(cal_word[j]); expression[count].push(cal_word[j]); if (word[count].peek() == \ } i++; break;
word[count].pop(); word[count].push(\count++;
word[count].push(\
input.close(); output.close();
八、思考题
1、 如果使用递归下降分析法来进行语法分析,为什么文法必须先转化为LL(1)文法
再做递归下降分析?
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新医药卫生南昌大学编译原理实验--语法分析(含代码) (2)全文阅读和word下载服务。
相关推荐: