lexでhelloをこんにちはに変換するプログラムを作りたい

前提

vscodeを用いてc言語でプログラミングを書いています。

実現したいこと

「hello」を入力したら「こんにちは」に変換されるプログラムを作りたいです。

(注意)以下のようなプログラム

入力:ahello hello HELLO helloa ! ’hello’ ’hi hello world’
出力:ahello こんにちは HELLO helloa ! ’hello’ ’hi hello world’

発生している問題・エラーメッセージ

1.こんにちはが表示されない
2.’hello'は反応させたくないのに反応してしまっている
3.'hi hello world’も2と同様

ahello hello HELLO helloa ! ’hello’ ’hi hello world’ ahello HELLO helloa ! ’’ ’hi world’

該当のソースコード

c

%{ #define YY_SKIP_YYWRAP #define yywrap() 1%} %%hello { printf ("こんにちは", yytext);}[a-z]+ { printf ("%s", yytext);}'.'{ printf ("%s", yytext);}%% int main(void){ yylex(); return 0;}

コメントを投稿

0 コメント