Hi, I wrote a lex file, but when I try to compile it, I get this error:
l3.lex:64: parse error before `{'
I don't see any errors.
Here is my code:
Code:
%{
%}
/* regular definitions */
blank [ \t\n]
ws {blank}+
comment [\{]([^\{\n])*[\}]
letter [a-zA-Z]
digit [0-9]
id {letter}({letter}|{digit})*
digits {digit}+
optional_frac (\.{digits})?
optional_Iexp (E[+]?{digits})?
optional_Rexp (E[+|-]?{digits})?
inum {digits}({optional_Iexp})
rnum {digits}({optional_frac})({optional_Rexp})
%%
{ws} {// Do Nothing}
{comment} {// Do Nothing}
program {return(PROGRAM);}
var {return(VAR);}
array {return(ARRAY);}
of {return(OF);}
real {return(REAL);}
integer {return(INTEGER);}
function {return(FUNC);}
procedure {return(PROC);}
begin {return(BEG);}
end {return(END);}
if {return(IF);}
else {return(ELSE);}
then {return(THEN);}
while {return(WHILE);}
do {return(DO);}
or {return(ADDOP);}
not {return(NOT);}
and {return(MULOP);}
div {return(MULOP);}
mod {return(MULOP);}
{id} {install_id(); return(ID);}
{inum} {install_iNum(); return(INUM);}
{rnum} {install_rNum(); return(RNUM);}
":=" {return(ASSIGNOP);}
"=" {return(RELOP);}
"<>" {return(RELOP);}
"<" {return(RELOP);}
"<=" {return(RELOP);}
">=" {return(RELOP);}
">" {return(RELOP);}
"*" {return(MULOP);}
"/" {return(MULOP);}
. {return yytext[0];}
%%
install_id() {
pTmp=findEntry(yytext);
if ( pTmp == NULL )
pTmp=addEntry(yytext);
if ( pTmp == NULL ) {
fprintf(stderr, "Error: Could not insert %s into symbol table.\n",
yytext);
exit(1);
}
yylval.id_info.pEntry=pTmp;
}
install_iNum() {
yylval.iVal = atoi(yytext);
}
install_rNum() {
yylval.rVal = atof(yytext);
}
Can anyone see anything wrong with this code?