my lex code is
/* description: Parses end executes mathematical expressions. */
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
[0-9]+("."[0-9]+)?\b return 'NUMBER'
[a-zA-Z] return 'FUNCTION'
<<EOF>> return 'EOF'
. return 'INVALID'
/lex
/* operator associations and precedence */
%start expressions
%% /* language grammar */
expressions
: e EOF
{return $1;}
;
e
| FUNCTION '('e')'
{$$=$3}
| NUMBER
{$$ = Number(yytext);}
;
i got error
Parse error on line 1:
balaji()
-^
Expecting '(', got 'FUNCTION'
what i want to pass myfun(a,b,...) and also myfun(a) in this parser.thank you for your valuable time going to spent for me.
[a-zA-Z]matches a single alphabetic character (in this case, the letterb), returningFUNCTION. When the next token is needed, it again matches a single alphabetic character (a), returning anotherFUNCTIONtoken. But of course the grammar doesn't allow two consecutiveFUNCTIONs; it's expecting a(, as it says.You probably intended
[a-zA-Z]+, although a better identifier pattern is[A-Za-z_][A-Za-z0-9_]*, which matches things likemy_function_2.