我在我的 lex 文件文件中收到以下错误我不知道为什么会发生每个错误都与返回给解析器的每个令牌有关
lexical.l: In function âyylexâ:
lexical.l:29: error: expected expression before â;â token
lexical.l:30: error: âCALLâ undeclared (first use in this function)
lexical.l:30: error: (Each undeclared identifier is reported only once
lexical.l:30: error: for each function it appears in.)
lexical.l:31: error: âIDâ undeclared (first use in this function)
lexical.l:32: error: âNUMâ undeclared (first use in this function)
lexical.l:36: error: âRELOPâ undeclared (first use in this function)
lexical.l:37: error: âADDOPâ undeclared (first use in this function)
lexical.l:38: error: âMULOPâ undeclared (first use in this function)
lexical.l:39: error: âASSIGNâ undeclared (first use in this function)
lexical.l:40: error: âANDâ undeclared (first use in this function)
lexical.l:41: error: âORâ undeclared (first use in this function)
lexical.l:42: error: âNOTâ undeclared (first use in this function)
这是我的 lex 文件,用于向解析器发送令牌
%{
#include <stdio.h>
#include"bison.tab.h"
void showToken(char*);
%}
%option yylineno
%option noyywrap
digit [0-9]
letter [a-zA-Z]
whitespace [ \t]
%%
"else" {return ELSE;}
"real" {return REAL;}
"integer" {return INTEGER;}
"write" {return XWRITE;}
"while" {return WHILE;}
"end" {return END;}
"do" {return DO;}
"if" {return IF;}
"then" {return THEN;}
"program" {return XPROGRAM;}
"function" {return FUNCTION;}
"return" {return XRETURN;}
"read" {return XREAD;}
"var" {return VAR;}
"for" {return FOR;}
"begin" {return BEGIN;}
"call" {return CALL;}
{letter}({letter}|{digit})* {return ID;}
{digit}{digit}*(("."{digit}{digit}*)?) {return NUM;}
{digit}{digit}*({letter}|{digit})* printf("Lexical Error");
[(),:;.] return yytext[0];
^[\t ]+ ;
(==|<>|<|<=|>|>=) {return RELOP;}
(\+|-) {return ADDOP;}
(\*|\/) {return MULOP;}
(=) {return ASSIGN;}
(&&) {return AND;}
(\|\|) {return OR;}
(!) {return NOT;}
{whitespace}+ ;
"/*".*"*/" ;
. {
printf("Lexical Error");
exit(0);
}
%%
void showToken(char* name){
printf("<%s,%s>",name,yytext);
}
返回的令牌应该是大写字母还是无关紧要?我应该在此处包含解析器文件还是仅包含 tab.c 文件就足够了?