Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %top{
- #include "alphabet.h"
- #include "context.h"
- #include <stdio.h>
- #define lastchar yytext[yyleng - 1]
- #define YY_BUF_SIZE 66000
- struct alphabet* alphabet;
- struct context* current;
- struct stack* contexts;
- void operand_action(struct expression*);
- void operator_action(int);
- void change_context();
- void restore_context();
- int is_comment = 0;
- struct expression* get_result();
- }
- %s SEPA CHARA SEP EXP EXPO COMMENT ALPH SOURCE COMMENT_CODE CODE
- upper [A-Z]
- lower [a-z]
- letter {upper}|{lower}
- special "#"|"$"|"*"|"@"
- digit [0-9]
- symbol {letter}|{special}|{digit}
- sep "\n"|"\r"|"\t"|" "
- comentariu ";".+{sep}
- name ({letter}|{digit}|"_")+
- element {symbol}
- elementary "L"|"R"|{element}|"L(""!"?{element}")"|"R(""!"?"
- mt_call "["{name}"]"|"["{elementary}"]"
- set "{"{symbol}(","{symbol})*"}"
- transition {set}" -> "{mt}+";"
- mt_trans "("{transition}*")"
- mt ({name}"@")?({mt_call}|{mt_trans})|"&"{name}
- mt_decl {name}" ::= "{mt}+";;"{sep}
- code {mt_decl}
- nocom {symbol}+{sep}+
- alphab_ad {symbol}{sep}+
- alphab "alphabet :: "{alphab_ad}+";"
- %option noinput
- %option nounput
- %option noyymore
- %%
- alphabet BEGIN(ALPH);
- "^[alphabet]" BEGIN(COMMENT_CODE);
- <ALPH>" :: " {/*At first we read the first bracket of the alphabet*/
- BEGIN(CHARA);
- }
- <CHARA>{symbol} {/*Then we read one symbol at a time*/
- printf("Simbol din alfabet: %c\n", lastchar);
- BEGIN(SEPA);
- }
- <SEPA>{ /*We read the separator that follows a symbol and change the state.*/
- " " BEGIN(CHARA);
- " ;"{sep} BEGIN(COMMENT_CODE);
- ";"{sep} BEGIN(COMMENT_CODE);
- {sep} BEGIN(COMMENT_CODE);
- }
- <COMMENT_CODE>{
- {comentariu} printf("Comentariu %s\n", yytext); BEGIN(COMMENT);
- {mt_decl} printf("Cod in COMMENT_CODE: %s\n", yytext); BEGIN(CODE);
- }
- <COMMENT>{
- . ECHO;
- "\n" printf("\n"); BEGIN(COMMENT_CODE);
- }
- <CODE>{
- }
- %%
- int main(void)
- {
- FILE* f = fopen("RE", "rt");
- yyrestart(f);
- yylex();
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement