• 大小: 41KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-09-03
  • 语言: Java
  • 标签: java  

资源简介

通过java实现词法分析器。 解压: 1) src文件夹:实现代码 2)data文件夹:测试代码 3)README:说明文档

资源截图

代码片段和文件信息

package com.Lexical_Analyzer;

/**
 * 输入单词以获取单词所对应的种别
 */
public class GetKind{

    public int symbol(){ //常数
        return 10;
    }

    public int constant(){ //标识符
        return 11;
    }

    public int getkind(String word){
        int kind=0;
        switch(word){
            case “begin“:
                kind = 1;
                break;
            case “end“:
                kind=2;
                break;
            case “integer“:
                kind=3;
                break;
            case “if“:
                kind=4;
                break;
            case “then“:
                kind=5;
                break;
            case “else“:
                kind=6;
                break;
            case “function“:
                kind=7;
                break;
            case “read“:
                kind=8;
                break;
            case “write“:
                kind=9;
                break;
          /*  case “=“:
                kind=12;
                break;
            case “<>“:
                kind=13;
                break;
            case “<=“:
                kind=14;
                break;
            case “<“:
                kind=15;
                break;
            case “>=“:
                kind=16;
                break;
            case “>“:
                kind=17;
                break;
            case “_“:
                kind=18;
                break;
            case “*“:
                kind=19;
                break;
            case “=“:
                kind=20;
                break;
            case “(“:
                kind=21;
                break;
            case “)“:
                kind=22;
                break;
            case “;“:
                kind=23;
                break;*/
            default:
                kind=0;
                break;
        }
        return kind;
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-09 10:53  LexicalAnalyzer\
     目录           0  2018-07-09 10:46  LexicalAnalyzer\data\
     文件        1386  2018-06-28 21:46  LexicalAnalyzer\data\test.dyd
     文件          47  2018-06-28 21:46  LexicalAnalyzer\data\test.err
     文件         178  2018-06-27 14:41  LexicalAnalyzer\data\test.pas
     文件       42658  2018-07-09 10:52  LexicalAnalyzer\README.docx
     目录           0  2018-07-09 10:46  LexicalAnalyzer\src\
     目录           0  2018-07-09 10:45  LexicalAnalyzer\src\com\
     目录           0  2018-06-30 15:03  LexicalAnalyzer\src\com\Lexical_Analyzer\
     文件        2011  2018-06-30 15:03  LexicalAnalyzer\src\com\Lexical_Analyzer\GetKind.java
     文件        9722  2018-06-28 21:46  LexicalAnalyzer\src\com\Lexical_Analyzer\LexicalAnalyzer.java

评论

共有 条评论