8000 GitHub - fang0jun/myCompiler: 实现解析M语言的编译器
[go: up one dir, main page]

Skip to content

fang0jun/myCompiler

Repository files navigation

实现解析M语言的编译器

目录:



词法分析器:

微信图片_20210130083253.png



句法分析器:

微信图片_20210130083210.png



语法功能添加:

Compiler_1:

  • 添加编译器识别空语句的功能 eg: read(n);;;;;;;;;;;;;;;;;;;;;
  • if-then-else语句 可以允许then后的执行语句为空 eg: if < condition> then < NULL> else < S>

M语言程序示例:

var p,m,n: int;
begin
read(m); read(n);;;;;;;;;;;;;;;;;;;;;;;
p:=0;
if m >n then else p:=2;
write(p)
end@

Compiler_2:

  • if-then-else语句 若无else条件可省略不写else eg: if < condition> then < S>

M语言程序示例:

var p,m,n: int;
begin
read(m); read(n);
p:=0;
if m >n then p:=1;
write(p)
end@

Compiler_3:

  • 添加 repeat-until 语法 (即do-while语法)

M语言程序示例:

program
var a,N:int;
begin
    a := 0;
    read(N);
    if(N = 0) then write(N)
    else repeat
        begin
            a:=a+1
        end
        until  a=N;
    write(N)
end@

Compiler_4:

  • 增加数据类型 char

M语言程序示例:

program
var charA, charB : char;
begin 
    charA := 'x';
    read(charB);
if charB>charA then write(charB) else write (charA)
end@

About

实现解析M语言的编译器

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0