I am trying to write a recursive original parser in PHP for the following EBNF:
< Pre> EXP :: = & lt; Period & gt; {(+ | -) & lt; Period & gt; } TERM :: = & lt; Factor & gt; {(* | / /) & Lt; Factor & gt; } FACTOR :: = (& lt; EXP & gt;) | & Lt; Digit & gt; Digit :: = 0 | 1 | 2 | 3
I followed this way which I had suggested on a similar question. (I did search before posting)
For the most part, how do I work and I understand grammar. I think the problem is within my syntax, I'm new to PHP, so I'm referring to. I am currently receiving the following error with my code:
WARNING: Incorrect parameter count for XP ... at 101 I have tried to see this error and did not have much luck. I've read some posts about people who went wrong in typed type, but I do not have any parameters for that function. Is there something about PHP that I'm missing here?
Below is my code, I think the argument is correct because I was away from the pars tree for grammar. $ Input will come from a form box on an HTML page. When I found that it is not created in PHP4, then I also picked the str_split function from a different post.
& lt; Html & gt; & Lt; Body & gt; & Lt ;? Php if (! Function_exists ("exp")) {function exp () {term (); While ($ token == "+" | $ token == "-") {if ($ token == "+") {match ("+"); Period (); } If ($ token == "-") {match ("-"); Period (); }}} // end exp} if (! Function_exists ("term")) {function term () {factor (); While ($ token == "*" | $ Tokens == "/") {if ($ Tokens == "*") {match ("*"); Factor (); } If ($ token == "/") {match ("/"); Factor (); }}}}}}}}}}}}} / End term} if (function_exists ("factor")} {function factor () {if ($ token == "(") {match ("("); exp (); if ($ token == ")") match (")"); } And if ($ token == 0 | 1 | 2 | 3) {if ($ token == 0) match (0); If ($ token == 1) match (1); If ($ token == 2) match (2); If ($ token == 3) match (3); } And error (); } // end factor} if (! Function_exists ("match")) {function match ($ expected) {if ($ token == $ expected) nextToken (); Other error (); } // end match} if (! Function_exists ("next_Token")) {function nextToken () {$ next ++; $ Token = $ tokenset [$ next]; If ($ token == "$"); Legal (); }} If (Function_exists ("Error")) {function error () {dumb "illegal token stream, try again"; }} If (Function_exists ("legal")) {function legal () {echo "legal token stream, congratulations!"; }} If (Function_exists ('str_split')) {function str_split ($ string, $ split_length = 1) {$ array = explosion ("\ r \ n", chunk_split ($ string, $ split_length)); Array_pop ($ array); Return $ array; }} $ TokenStr = str_split ($ input); $ Next = 0; $ Token = $ tokens [0]; Exp (); ? & Gt; & Lt; / Body & gt; & Lt; / Html & gt; So basically I want to know what is the cause of this error and why I am on the right path and in the matter of making this parser.
I appreciate any comments, suggestions, criticisms, water balloons and tomatoes. Thanks for taking the time to read your post. Have a great day / night.
is a built-in PHP function. You can not define it under that name.
You should not have any reason to use , if (! Function_exists (' idiom in common PHP applications. (This is often used as a workaround When a script collision or similar functions are declared at different locations.)
Another syntax problem I've seen is using your bitwd or being logical or or just or .
while ($ token == "*" | $ Tokens == "/") {
Comments
Post a Comment