GithubHelp home page GithubHelp logo

Comments (43)

z22756392z avatar z22756392z commented on September 7, 2024

https://github.com/z22756392z/sp110b/wiki/homework.md

from sp110b.

stereomp3 avatar stereomp3 commented on September 7, 2024

dowhile

#include <assert.h>
#include "compiler.h"

int E();
void STMT();
void IF();
void BLOCK();

int tempIdx = 0, labelIdx = 0;

#define nextTemp() (tempIdx++)
#define nextLabel() (labelIdx++)
#define emit printf

int isNext(char *set) { //...}

int isEnd() { //...}

char *next() { //...}

char *skip(char *set) { //...}

// F = (E) | Number | Id
int F() { //...}

// E = F (op E)*
int E() { //...}

// ASSIGN = id '=' E;
void ASSIGN() { //...}

// WHILE = while (E) STMT
void WHILE() { //...}

// DO WHILE
void DO(){
  int DoBegin = nextLabel();
  int DoEnd = nextLabel();
  emit("(L%d)\n", DoBegin);
  skip("do");
  STMT();  // block call STMTS , } to end
  skip("while");
  skip("(");
  int e = E();
  emit("if not T%d goto L%d\n", e, DoEnd);
  skip(")");
  skip(";");  // 需要過濾掉,不然一開始在main() 執行的 STMTS會觸發 ASSIGN() 裡面的 skip("=") 導致錯誤
  emit("goto L%d\n", DoBegin);
  emit("(L%d)\n", DoEnd);
}


// STMT = WHILE | BLOCK | ASSIGN
void STMT() {
  if (isNext("do")){
    DO();
  }
  else if(isNext("while"))
    WHILE();
  // else if (isNext("if"))
  //   IF();
  else if (isNext("{"))
    BLOCK();
  else
    ASSIGN();
}

// STMTS = STMT*
void STMTS() {//...}

// BLOCK = { STMTS }
void BLOCK() { //...}

// PROG = STMTS
void PROG() { //...}

void parse() {
  printf("============ parse =============\n");
  tokenIdx = 0;
  PROG();
}

執行結果

============ parse =============
t0 = 0
s = t0
t1 = 1
i = t1
(L0)
t2 = s
t3 = i
t4 = t2 + t3
s = t4
t5 = i
t6 = 1
t7 = t5 + t6
i = t7
t8 = i
t9 = 10
t10 = t8 < t9
if not T10 goto L1
goto L0
(L1)

from sp110b.

zhengyucen avatar zhengyucen commented on September 7, 2024

110810548 鄭宇岑

from sp110b.

yucing avatar yucing commented on September 7, 2024

110910511 蘇郁晴
https://github.com/yucing/sp110b/wiki/e1.md

from sp110b.

Mocha777 avatar Mocha777 commented on September 7, 2024

110910513林孫全
https://github.com/Mocha777/sp110b/wiki/%E7%BF%92%E9%A1%8C1

from sp110b.

shaoan901226 avatar shaoan901226 commented on September 7, 2024

110910518 黃紹安
https://github.com/shaoan901226/sp/wiki/HOMEWORK1

from sp110b.

RyanChen-01 avatar RyanChen-01 commented on September 7, 2024

110910515 陳文吉
https://github.com/RyanChen-01/sp110b/wiki/hw1.md

from sp110b.

nakirifumiya avatar nakirifumiya commented on September 7, 2024

110910501 王澤瑋
https://github.com/nakirifumiya/sp110b/wiki/hw1

from sp110b.

jifkavnb0205 avatar jifkavnb0205 commented on September 7, 2024

110810507 李安博

from sp110b.

Lin610313 avatar Lin610313 commented on September 7, 2024

110910506林庭光
https://github.com/Lin610313/sp110b/wiki/work1.md

from sp110b.

Paouser avatar Paouser commented on September 7, 2024

110910522 劉煒辰

from sp110b.

stayjay avatar stayjay commented on September 7, 2024

110910507 王證傑
https://github.com/stayjay/sp110b/wiki/homework1

from sp110b.

qweasd049564 avatar qweasd049564 commented on September 7, 2024

資工三 110810509 蘇乾羽
https://github.com/qweasd049564/sp110b/blob/master/hw/hw1.md

from sp110b.

Sakura01210 avatar Sakura01210 commented on September 7, 2024

110910508 王冠文

from sp110b.

404HK416 avatar 404HK416 commented on September 7, 2024

110810403 蘇彥華

from sp110b.

zraiz avatar zraiz commented on September 7, 2024

資工二 110911542 邵南翔
https://github.com/zraiz/sp110b/blob/master/Homework/01/Homework01.md

from sp110b.

yumao57 avatar yumao57 commented on September 7, 2024

資工二 110910529 劉宸羽
https://github.com/yumao57/sp110b/wiki/%E7%BF%92%E9%A1%8C%E4%B8%80

from sp110b.

choco427 avatar choco427 commented on September 7, 2024

資工二110910524張詠翔

from sp110b.

Roy-Roo avatar Roy-Roo commented on September 7, 2024

資工二 110910519 羅彥翔

from sp110b.

kaifeng273 avatar kaifeng273 commented on September 7, 2024

資工二 110910528 吳俊億

from sp110b.

patrick901218 avatar patrick901218 commented on September 7, 2024

資工二 110910548 張昀翰

from sp110b.

Kenttsai1 avatar Kenttsai1 commented on September 7, 2024

110910509 蔡宗霖

from sp110b.

jiajianong avatar jiajianong commented on September 7, 2024

資工二 110910535 呂嘉融

from sp110b.

WForU avatar WForU commented on September 7, 2024

資工二 110911543 何文旺
https://github.com/WForU/sp110b/wiki/HW1.md

from sp110b.

qwezxca123 avatar qwezxca123 commented on September 7, 2024

資工二 110910533 曾旭宏

from sp110b.

wukunru avatar wukunru commented on September 7, 2024

資工二110910510吳昆儒
https://github.com/wukunru/sp110b/wiki/%E7%BF%92%E9%A1%8C1

from sp110b.

Uriel58 avatar Uriel58 commented on September 7, 2024

https://github.com/Uriel58/sp110b/wiki/do...while
資工二 110910503 林成也

from sp110b.

gakuplusq avatar gakuplusq commented on September 7, 2024

資工二 110910530 黃劭騏

from sp110b.

Selesfia avatar Selesfia commented on September 7, 2024

資工二 110910552 胡禎恩

from sp110b.

weiian000 avatar weiian000 commented on September 7, 2024

資工三 110813110 李維晏

from sp110b.

mozi5269 avatar mozi5269 commented on September 7, 2024

資工二 110910532 王昱凱

from sp110b.

derek120432 avatar derek120432 commented on September 7, 2024

資工二110910514李韋德

from sp110b.

QuiLinxinag avatar QuiLinxinag commented on September 7, 2024

資工二 110910536 邱麟翔

from sp110b.

Soober9260 avatar Soober9260 commented on September 7, 2024

資工二 110910546 施威帆

from sp110b.

po-hsiang666 avatar po-hsiang666 commented on September 7, 2024

資工二 110910544 張博翔

from sp110b.

Vialbum avatar Vialbum commented on September 7, 2024

資工二 110910547 林鈺翔

from sp110b.

OohelloworldoO avatar OohelloworldoO commented on September 7, 2024

資工二 110910539 鄭智陽
https://github.com/OohelloworldoO/sp110b/wiki/exercise-1

from sp110b.

al2698 avatar al2698 commented on September 7, 2024

資工二 110910531 姜呈諭

from sp110b.

ChiaYunn avatar ChiaYunn commented on September 7, 2024

110810535

from sp110b.

YangTiChu avatar YangTiChu commented on September 7, 2024

資工二 110910527 楊堤筑 習題1

from sp110b.

nnnnnnn1266 avatar nnnnnnn1266 commented on September 7, 2024

資工二 110910559潘其恩

from sp110b.

daniel74859641 avatar daniel74859641 commented on September 7, 2024

110910563陳威宇
https://github.com/daniel74859641/-/blob/%E7%B6%B2%E9%A0%81%E6%9C%9F%E6%9C%AB%E5%A0%B1%E5%91%8A/%E7%B3%BB%E7%B5%B1%E7%A8%8B%E5%BC%8Fhw1

from sp110b.

wei-annn avatar wei-annn commented on September 7, 2024

110910504趙唯安
https://github.com/wei-annn/sp110b/wiki/hw1.md

from sp110b.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.