pl3.l

来自「简介:PL0语言是pascal语言的一个子集。编译VC工程之前」· L 代码 · 共 48 行

L
48
字号
/*extended: identifier are allowed to use dash;multiple-line coments allowed*/
%{
#include "pl3.tab.h"
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
int	lineno = 1;
char* tname;
%}

%%
"do"		{ return DO; }
"write"		{ return WRITE; }
"read"		{ return READ; }
"procedure"	{ return PROCEDURE; }
"var"		{ return VAR; }
"const"		{ return CONST; }
"call"		{ return CALL; }
"if"		{ return IF; }
"else"		{ return ELSE; }
"then"		{ return THEN; }
"odd"		{ return ODD; }
"begin"		{ return BEGINSYM; }
"end"		{ return ENDSYM; }
"while"		{ return WHILE; }
"repeat"	{ return REPEAT; }
"until"		{ return UNTIL; }
":=" 		{ return COLEQ;}
"<="		{ return LE;}
">=" 		{ return RE;}

[0-9]+					{	yylval.val = atoi(yytext);return NUMBER;}
[a-zA-Z_][a-zA-Z0-9_]*	{	tname = (char*)malloc(strlen(yytext)+1);
							strcpy(tname, yytext);
							yylval.name = tname;return LEGAL_ID;}
[\n]					{	lineno++;}
[ \t]+					{		}
\{[^\}\n]*\}			{		}
.               		{	return yytext[0];}
%%

int yywrap()
{
  return 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?