資工碩二 黃國豪 109598074
資工碩二 吳承岳 109598085
共同開發
本次作業設計一個支援部分語法的 c 語言 Scanner
參考 c4
使用 flex 作為開發工具
測試檔案為 hello.c
Run the following command to build:
$ flex prog1.l
$ gcc lex.yy.c -o prog1
Run test:
$ ./prog1 < hello.c
or
$ ./prog1 hello.c
Output shows on the screen
INT MAIN PUNCT('(') PUNCT(')')
PUNCT('{')
INT ID(i) ASSIGN NUM(0) PUNCT(';')
ID(while) PUNCT('(') ID(i) LT NUM(5) PUNCT(')')
PUNCT('{')
ID(printf) PUNCT('(') DIV PUNCT(')') PUNCT(';')
ID(i) ASSIGN ID(i) ADD NUM(1) PUNCT(';')
PUNCT('}')
ID(return) NUM(0) PUNCT(';')
PUNCT('}')