Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include "y.tab.h"
- #include <stdio.h>
- #include <string.h>
- #define lexeme strcpy((char *)malloc(yyleng+1),yytext)
- %}
- int line_count = 0;
- DIGIT [0-9]
- HEX 0x[0-9a-fA-F]+
- NUMBER {DIGIT}+
- IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
- COMMENT_START "/*"
- COMMENT_END "*/"
- WHITESPACE [ \t]+
- NEWLINE "\n"
- IGNORE {WHITESPACE}
- ANY .
- %x COMMENT
- %%
- {COMMENT_START} BEGIN(COMMENT);
- <COMMENT>{COMMENT_END} BEGIN(INITIAL);
- <COMMENT><<EOF>> {
- fprintf(stderr, "Comment not Closed\n");
- exit(1);
- }
- <COMMENT>{ANY} /* ignore comments */
- {IGNORE} /* ignore whitespace */
- {NEWLINE} line_count++;
- <COMMENT>{NEWLINE} line_count++;
- ; return ';';
- \( return '(';
- \) return ')';
- \. return '.';
- \- return '-';
- \* return '*';
- \< return '<';
- = return '=';
- , return ',';
- := return L_ASSIGN;
- struct return K_STRUCT;
- end return K_END;
- method return K_METHOD;
- var return K_VAR;
- if return K_IF;
- then return K_THEN;
- else return K_ELSE;
- while return K_WHILE;
- do return K_DO;
- return return K_RETURN;
- not return K_NOT;
- or return K_OR;
- this return K_THIS;
- {IDENTIFIER} return IDENT; @{ @IDENT.name@ = lexeme; @}
- {NUMBER} return NUM; @{ @NUM.val@ = strtol(yytext, (char**)NULL, 10); @}
- {HEX} return NUM; @{ @NUM.val@ = strtol(yytext, (char**)NULL, 16); @}
- {ANY} {
- fprintf(stderr, "Syntax-Error in Line %d\n\"%s\" not know\n\n", line_count, yytext);
- exit(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement