Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple pl/0 language compiler

License

NotificationsYou must be signed in to change notification settings

fpg2012/pl0-compiler

Repository files navigation

A simple pl/0 language compiler for learning lexical analysis, syntax analysis and sematic analysis, not finished. Homework of CSU compiler course.

input: sample2.txt

const hey = 100;var t, a0, a1, i;begin   i := 1;   a0 := 0;   a1 := 1;   while i < hey do   begin      t := a1;      a1 := a0 + a1;      a0 := t;      i := i + 1;   endend

run:

pl0_compiler sample2.txt

result:

( <3:const, const>  <12:id, hey>  <14:op, =>  <13:int, 100>  <16:semi, ;>  <4:var, var>  <12:id, t>  <15:comma, ,>  <12:id, a0>  <15:comma, ,>  <12:id, a1>  <15:comma, ,>  <12:id, i>  <16:semi, ;> (( <1:begin, begin> (( <12:id, i>  <14:op, :=> ((( <13:int, 1> ))))) <16:semi, ;> (( <12:id, a0>  <14:op, :=> ((( <13:int, 0> ))))) <16:semi, ;> (( <12:id, a1>  <14:op, :=> ((( <13:int, 1> ))))) <16:semi, ;> (( <7:while, while> ((((( <12:id, i> ))) <14:op, <> ((( <12:id, hey> ))))) <8:do, do> ( <1:begin, begin> (( <12:id, t>  <14:op, :=> ((( <12:id, a1> ))))) <16:semi, ;> (( <12:id, a1>  <14:op, :=> ((( <12:id, a0> )) <14:op, +> (( <12:id, a1> ))))) <16:semi, ;> (( <12:id, a0>  <14:op, :=> ((( <12:id, t> ))))) <16:semi, ;> (( <12:id, i>  <14:op, :=> ((( <12:id, i> )) <14:op, +> (( <13:int, 1> ))))) <16:semi, ;>  <2:end, end> ))) <2:end, end> )))add 1 0 v0add v0 0 iadd 0 0 v1add v1 0 a0add 1 0 v2add v2 0 a1l0: add i 0 v3add 100 0 v4jl v3 v4 l1add a1 0 v6add v6 0 tadd a0 0 v7add a1 0 v8add v7 v8 v7add v7 0 a1add t 0 v9add v9 0 a0add i 0 v10add 1 0 v11add v10 v11 v10add v10 0 ijeq 0 0 l0l1:

About

A simple pl/0 language compiler

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp