我得到了我的法文件的文件下面的错误,我不知道这是为什么发生的每个错误是 关于每个令牌返回给解析器野牛分析器错误
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文件就足够了?
我删除了Flex标签,因为这与UI框架无关并添加了gnu-flex标签;这是用于词法分析器的。 – JeffryHouser