跳到主内容
paste
bin
.ca
type · paste · share
⌘
K
登录
?
账户
更多
▾
文档
系列
bin 系列
pastebin.ca
中心
Share text and code with expiry and privacy controls.
imagebin.ca
Upload and share images with direct links.
filebin.ca
Drop a file and get a shareable link.
notebin.ca
Write Markdown notes with durable links.
turl.ca
Short, reputation-checked links.
attn.ca
Notifications and alerts for your services.
voicebin.ca
Record and share short voice clips.
dnsbin.ca
Inspect DNS and debug records.
← 返回文本
›
编辑 / 分支
无标题文本
#7U534V2KG9
public / public
新版本
匿名
已创建 10 days ago
过期于 20 days
3.1 KB
语法:
text
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
新版本
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
标题(可选)
文件名
语法
text
text
bash
c
cpp
css
diff
dockerfile
go
html
ini
java
javascript
json
kotlin
lua
makefile
markdown
nginx
php
python
ruby
rust
shellscript
sql
swift
toml
typescript
xml
yaml
可见性
公开动态
访问
public
过期
30 天
10 分钟
1 小时
1 天
7 天
30 天
90 天
自定义…
自定义过期
变更备注
(可选)
任何人都能在公开动态中找到此文本。选择“未列出”即可仅通过链接分享。
创建新版本
取消
粘贴或输入…
RECURSIVE DESCENT --------------------------------- #include <stdio.h> #include <string.h> char str[50]; int pt = 0, flag = 0; void E(); void Eprime(); void T(); void Tprime(); void F(); void E() { T(); Eprime(); } void Eprime() { if (str[pt] == '+') { pt++; T(); Eprime(); } } void T() { F(); Tprime(); } void Tprime() { if (str[pt] == '*') { pt++; F(); Tprime(); } } void F() { if (str[pt] == '(') { pt++; E(); if (str[pt] == ')') pt++; else flag = 1; } else if (str[pt] == 'a') { pt++; } else { flag = 1; } } int main() { printf("Enter string: "); scanf("%s", str); E(); if (flag == 0 && pt == strlen(str)) printf("String is Accepted\n"); else printf("String is Rejected\n"); return 0; } ---------------------------------------------- E CLOSURE ---------------------------------------------- #include<stdio.h> #include<string.h> int main(){ char states[20][10],s1[20][10],in[20][10],s2[20][10],curr[10]; int i,k,n,t; printf("Enter the Number of states: "); scanf("%d",&n); printf("\nEnter the states: "); for(k=0;k<n;k++) scanf("%s",states[k]); printf("\nEnter the number of transitions: "); scanf("%d",&t); printf("Enter the Transitions:\n STATE1 -- INPUT -- STATE2\n"); for(i=0;i<t;i++) scanf("%s %s %s", s1[i],in[i],s2[i]); for(k=0;k<n;k++){ strcpy(curr,states[k]); printf("Epsilon closure of %s = { %s",curr,curr); for(i=0;i<t;i++){ if(strcmp(curr,s1[i])==0 && strcmp(in[i],"e")==0){ printf(" , %s",s2[i]); strcpy(curr,s2[i]); } } printf(" }\n"); } return 0; } --------------------------------------------------------------------- calculator -------------------------------------------------------------- **********calc.l**************** %{ #include <stdio.h> #include <stdlib.h> #include "y.tab.h" extern int yylval; %} %% [ \t]+ { ; } [0-9]+ { yylval = atoi(yytext); return NUMBER; } \n { return 0; } . { return yytext[0]; } %% int yywrap() { return 1; } **********calc.y*************** %{ #include <stdio.h> #include <stdlib.h> int flag = 0; int yylex(void); int yyerror(char *s); %} %token NUMBER %left '+' '-' %left '*' '/' %left '(' ')' %% ArithmeticExpression: E { printf("\nResult = %d\n", $1); return 0; } ; E: E '+' E { $$ = $1 + $3; } | E '-' E { $$ = $1 - $3; } | E '*' E { $$ = $1 * $3; } | E '/' E { if ($3 == 0) { yyerror("Division by zero"); flag = 1; YYABORT; } else { $$ = $1 / $3; } } | '(' E ')' { $$ = $2; } | NUMBER { $$ = $1; } ; %% int main() { printf("\nEnter any arithmetic expression:\n"); yyparse(); if (!flag) { printf("Entered arithmetic expression is valid\n"); } return 0; } int yyerror(char *s) { printf("\nEntered arithmetic expression is invalid\n"); flag = 1; return 0; }