0

I am newbie at jison, using the following grammer with jison:

/* lexical grammar */
%lex
%%

\s+                   /* skip whitespace */
[০-৯]+(?:\.[০-৯]+)? return 'NUMBER'
"*"                   return '*'
"/"                   return '/'
"-"                   return '-'
"+"                   return '+'
"^"                   return '^'
"("                   return '('
")"                   return ')'
"PI"                  return 'PI'
"E"                   return 'E'
.           return 'Invalid'
// EOF means "end of file"
<<EOF>>              return 'EOF'
// any other characters will throw an error

/lex

%left '+' '-'
%left '*' '/'
%left '^'
%left UMINUS

%start expressions

%% /* language grammar */


expressions
    : e EOF
    {return $1;}
    ;


e
: e '+' e
    {var bnte = {
'০': 0,
'১': 1,
'২': 2,
'৩': 3,
'৪': 4,
'৫': 5,
'৬': 6,
'৭': 7,
'৮': 8,
 '৯': 9
};
function bntex(input) {
 var output = [];
for (var i = 0; i < input.length; ++i) {
    if (bnte.hasOwnProperty(input[i])) {
    output.push(bnte[input[i]]);
} else {
  output.push(input[i]);
}
}
return output.join();
}

var n=parseInt(bntex($1));
var s=parseInt(bntex($3));
    | e '+' e
        {$$=n+s;}
    | e '-' e
        {$$ = n-s;}
    | e '*' e
        {$$ = n*s;}
    | e '/' e
        {$$ = n/s;}
    | e '^' e
        {$$ = Math.pow(n, s);}
    | '-' e %prec UMINUS
        {$$ = -s;}
    | '(' e ')'
     {$$ = $2;}
    | NUMBER
        {$$ = Number(yytext);}
    | E
     {$$ = Math.E;}
 | PI
     {$$ = Math.PI;}
    ;

The problem is: When I want to parse ৬৭+৮.৩ it can tokenize number and + operator but returning Null as answer

I am using js function to convert number digits but it's not working.

I hope you guys will help me to fix the problem ❤️ Please....

  • That code throws an error when you pass it through Jison, so I suppose it's not the code you actually used. It looks to me like a copy-and-paste error. But the basic problem is that you need to do the transformation from Bangla into number in the production `e: NUMBER`. If you don't do it then, it's too late because the current action for `e: NUMBER` tries to convert the character string matched by NUMBER into a number. – rici May 19 '21 at 16:03
  • tell me the procedure what should I do now? – Taslima Akhter May 20 '21 at 02:43
  • 1
    "you need to do the transformation from Bangla into number in the production e: NUMBER" – rici May 20 '21 at 02:46
  • Are there any shortcut ways to do that? – Taslima Akhter May 20 '21 at 02:51

0 Answers0