摘要: 包 lexer 是词法分析器的代码的扩展。类 Tag 定义了各个词法单元对应的常量。 1: package lexer; 2: public class Tag { 3: public final static int 4: AND = 256 , BASIC = 257 , BREAK = 258 , DO = 259 , ELSE = 260... 阅读全文
posted @ 2014-01-17 22:26 姜楠 阅读(818) 评论(0) 推荐(1) 编辑
摘要: 程序的执行从类Main的方法main开始。方法main创建了一个词法分析器和一个语法分析器,然后调用语法分析器中的方法program。 1: package main; 2: import java.io.*; 3: import lexer.*; 4: import praser.*; 5: public class Main{ 6: public s... 阅读全文
posted @ 2014-01-17 19:57 姜楠 阅读(504) 评论(0) 推荐(0) 编辑
摘要: 这个语言的一个程序由一个块组成,该块中包含可选的声明和语句。语法符号basic表示基本类型。program –> blockblock –> { decls stmts }decls -> desls decl | εdecl -> type id;type -> type [num] | basicstmts -> stmts stmt | ε把复制当做一个语句(而不是表达式中的运算符)可以简化翻译工作。stmt -> loc=bool; | if(bool) stmt | if(bool) stmt else stmt | while(bool) 阅读全文
posted @ 2014-01-17 19:48 姜楠 阅读(1534) 评论(0) 推荐(0) 编辑