• 大小: 2.96MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-18
  • 语言: Java
  • 标签: Oberon-0  

资源简介

编译原理实验三 一、讨论Oberon-0 语言的特点 1、保留字与关键字的概念区分 保留字只要是用在程序语言的层次架构用途上,比如说IF,THEN,ELSIF,用在程序 的循环、分支、判断条件、程序块等组织上,它是程序语言中预定义的,具某些特殊意 义规范的单词。保留字侧重于强调不能被用户作为定义的名字。 关键字是一个只被用在某一部分的程序编程中,关键字在程序语言中同样有特殊的 意义特征。多用于类型定义,如在Oberon中,integer 便是用来定义变量类型的关键 字。还有其他的功能如作为程序语言中的某个特定函数的名称,如 write,read等(在 Oberon中). 不同的语言的关键字和保留字的概念区分是不一样的。例如在C,JAVA中, if,else, while 这些都是关键字的范围,而在Oberon 中是保留字的范围。在C 语言风格的程 序语言中,是将程序控制块的那些保留字也一并归为关键字的。(这些关键字不可以作 为变量,函数的名称,也就是不可以作为程序员使用的标示符)。 2、Oberon与C、Java的差别 a) 在每一一个主要的函数过程procedure 中,Oberon有begin 和end 来标志,而 在C 和java中一般是用花括号来标志。 b) 在定义变量时,Oberon 是在分号之后,也就是最后在给出具体是什么类型的,而 在C、Java中一般是在变量的前面就给出了类型,只是 Oberon会先用var说明 这是一个变量。 c) Oberon中的可用到数据结构主要有数组,类似C 中的结构体,类型选择比较少。 3 二、文法二义性讨论 该文法没有二义性。在其他的语言中出现的二义性类型中,比如表达式的parsing tree (存在两颗或以上的parsing trees)的二义性,需要用算符优先关系来确定的和if-else 的 匹配问题导致的二义性问题,都在该文法中的EBNF定义中被消除掉了。 1、对于表达式的二义性处理: simple_expression = ["+" | "-"] term {("+" | "-" | "OR") term} ; term = factor {("*" | "DIV" | "MOD" | "&") factor} ; 从中,可以看出*和 DIV、MOD 这些一定在+-之前就进行运算了。通过将表达式的将 +-和*DIV、MOD 等用不同层次的表达式进行定义,消除了这一二义性。 2、对于if-else匹配出现二义性的处理:

资源截图

代码片段和文件信息

public class Lexical
{
  /* terminals */
  public static final int Operator = 1;
  public static final int Keyword = 2; //关键字
  public static final int ReservedWord = 3;
  public static final int Identifier = 4;
  public static final int Seperator = 5;
  public static final int Number = 6;
  public static final int Comment = 7;
  public static final int WhiteSpace = 8;

  public static final int EOF = 0;
  
  public static final int legalSymbol = -1;
  public static final int IllegalInteger = -2; //no blank before identifier
  public static final int IllegalItegerRange = -3; //more than 12
  public static final int IllegalOctal = -4;
  public static final int IllegalIdentifierLength = -5;
  public static final int MismatchedComment = -6; //未匹配   
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-27 00:24  实验三\
     目录           0  2018-06-27 20:17  实验三\ex1\
     文件      235852  2018-06-27 20:16  实验三\ex1\Oberon-0.pdf
     文件          80  2018-06-27 20:17  实验三\ex1\readme.txt
     目录           0  2018-06-27 22:22  实验三\ex1\testcases\
     文件         352  2018-06-26 23:57  实验三\ex1\testcases\factorial.obr
     目录           0  2018-06-27 21:46  实验三\ex2\
     目录           0  2018-06-27 00:24  实验三\ex2\bin\
     目录           0  2018-06-27 00:24  实验三\ex2\bin\exceptions\
     文件         669  2018-06-27 21:34  实验三\ex2\bin\exceptions\IllegalIdentifierLengthException.class
     文件         633  2018-06-27 21:34  实验三\ex2\bin\exceptions\IllegalIntegerException.class
     文件         653  2018-06-27 21:34  实验三\ex2\bin\exceptions\IllegalIntegerRangeException.class
     文件         625  2018-06-27 21:34  实验三\ex2\bin\exceptions\IllegalOctalException.class
     文件         629  2018-06-27 21:34  实验三\ex2\bin\exceptions\IllegalSymbolException.class
     文件         604  2018-06-27 21:34  实验三\ex2\bin\exceptions\LexicalException.class
     文件         645  2018-06-27 21:34  实验三\ex2\bin\exceptions\MismatchedCommentException.class
     文件         374  2018-06-27 21:34  实验三\ex2\bin\exceptions\MissingLeftParenthesisException.class
     文件         349  2018-06-27 21:34  实验三\ex2\bin\exceptions\MissingOperandException.class
     文件         352  2018-06-27 21:34  实验三\ex2\bin\exceptions\MissingOperatorException.class
     文件         377  2018-06-27 21:34  实验三\ex2\bin\exceptions\MissingRightParenthesisException.class
     文件         597  2018-06-27 21:34  实验三\ex2\bin\exceptions\OberonException.class
     文件         773  2018-06-27 21:34  实验三\ex2\bin\exceptions\ParameterMismatchedException.class
     文件         601  2018-06-27 21:34  实验三\ex2\bin\exceptions\SemanticException.class
     文件         612  2018-06-27 21:34  实验三\ex2\bin\exceptions\SyntacticException.class
     文件         353  2018-06-27 21:34  实验三\ex2\bin\exceptions\TypeMismatchedException.class
     文件         735  2018-06-27 21:34  实验三\ex2\bin\Lexical.class
     文件        1745  2018-06-27 21:34  实验三\ex2\bin\Main.class
     文件       13133  2018-06-27 21:34  实验三\ex2\bin\OberonScanner.class
     文件         190  2018-06-26 19:42  实验三\ex2\build.bat
     文件          70  2018-06-26 19:39  实验三\ex2\gen.bat
     目录           0  2018-06-27 00:24  实验三\ex2\jflex\
............此处省略144个文件信息

评论

共有 条评论

相关资源