切換
舊版
前往
大廳
主題

[創作|作業][Lex]編譯器Prob3B:Scientific Notation

極巨龍神塔奇 | 2018-11-26 16:02:10 | 巴幣 0 | 人氣 343

Scientific Notation
描述
Your task is to use Lex and regular expression to find out all the input lines that satisfy the definition of normalized scientific notation. Please print each line that satisfies the normalized scientific notation with a newline character.
定義
mE ^ n, m ∈ R, 1 ≦ |m| < 10, n ∈ Z
A scientific notation is made up by normalized significand(m) and Exponentiation(n).
The definition of normalized significand is m, m ∈ R, 1 ≦ |m| < 10.
The definition of Exponentiation is n, n ∈ Z.
Here are some examples
(ex) 3.14E159 ✔ (ex) 31.4E159 ❌
(ex) 3.14E+159 ✔ (ex) +3.14E+159 ✔
(ex) +3.14E159 ✔ (ex) 31.4E1.59 ❌
範例輸入:
3.14E159
3.14E+159
+3.14E159
+3.14E+159
31.4E159
31.4E1.59
31.4E+159
31.4E-159
+31.4E+159
-31.4E-159
範例輸出:
3.14E159
3.14E+159
+3.14E159
+3.14E+159


%option noyywrap

sn    ^[+-]?[1-9](\.[0-9]+)?[eE][+-]?[0-9]+\n

%%

{sn} {ECHO;printf("\n");}
.
\n

%%

int main(int argc,char *argv[])
{
   yylex();
   return(0);
}
送禮物贊助創作者 !
0
留言

創作回應

更多創作