다음 yacc 코드를 시도하고 m/shift 오류 수신 중입니다. 나는이 해당 yacc를 코드에 대한이Shift Shift YACC의 충돌 감소
The Purpose of the code is to prepare the syntax for if - else with logical operators also incorporated
%{
#include<stdio.h>
#include"lex.yy.c"
int syntax_status=0;
%}
%token IF ELS id EE LE GE closep openp num openb closeb SP logicop
%start S
%%
S : S SP IF SP openp SP EXP SP closep SP openb SP closeb SP ELS SP openb SP closeb SP {syntax_status=1;}
| S SP IF SP openp SP EXP SP closep SP openb SP closeb SP {syntax_status = 1;}
|
;
EXP : EXP CMP logicop CMP
| EXP CMP
|
;
CMP : CMP id EE id
| CMP id LE id
| CMP id GE id
| CMP id EE num
| CMP id GE num
| CMP id LE num
| CMP num EE id
| CMP num GE id
| CMP num LE id
|
;
%%
int main()
{
printf("\n\n\n Enter the Syntax : ");
yyparse();
if(syntax_status==1)
{
printf("\n\n\n The Syntax is Correct ");
}
else
{
printf("\n\n\n The Syntax is Imcorrect");
}
return 0;
}
yyerror(char *s)
{
syntax_status=0;
}
렉스 프로그램에 대한 아주 새로운 M은 다음과 같다 :
%{
#include<stdio.h>
#include"y.tab.h"
%}
IF (if)
ELS (else)
iden [a-zA-Z][a-zA-Z0-9]*
num [0-9]+
space [ ]*
%%
{IF} { return IF; }
{ELS} {return ELSE;}
{iden} {return id;}
(==) {return EE;}
(<=) { return LE;}
(>=) { return GE;}
")" { return closep;}
"(" { return openp;}
{num} { return num;}
{space} { return SP; }
"{" { return openb;}
"}" { return closeb;}
"||"|"&&"|"!=" {return logicop;}
%%