I am new to the field of grammar and parsing.
I am trying to write the recurring descent parser that evaluates such stars:
((3 == 5 and 4 == 5) or (6 = = 6))
Everything works fine for me until I start to deal with nested brackets Basically I think I'm reaching very soon at the end of my target string.
I think the problem is due to the fact that when I "6" or the other from the second, I evaluate it and then move it to the next token. I'll extract the code to move towards the next token, but then I'm not sure how I will proceed.
My grammar, as it is, looks like this ("=>" Icon is my own marking for "translation" of a rule):
Test: If Compound Sentence Compendency Compoundcentence
Compact Centence: (CompoundSentence) PCSOPT | Compoundcentence combination string |
Sentence =>
CompoundSentence = (CompoundSentence) PCSopt | Sentence CSOpt
PCSOpt = ParenConjunction CompoundSentence PCSOpt | Epsilon
CSOpt = Combination Sentence CSOPT | APCLON
Parental combination: and | Or
combination: and | Or
sentence: subject verb prefix
topic: topic infix value | Value = & gt;
topic = value subject oppt
topic - OP = infix value subjectopt. APCLON
verb: == |! | = | & Gt; | & Lt;
Predefined: Prify process value. Value = & gt;
Valid = Value PredicateOpt
PredicateOpt = Infix Value PredicateOpt | Epislon
Infix: +, -, *, /
My code for a mixed sentence is as follows:
Private string compatibility (INMERATOR & Lt; token & gt; ts) // // CompoundSentence = (CompoundSentence) PCSopt | Sentence CSOpt string sReturnValue = ""; Switch (ts.Current.Category) {case "OPENPAREN": {// Leave behind open brackets. MoveNext (); String sCSValue = Component Santens (TS); If (ts.Current.Category! = "CLOSEPAREN") {sReturnValue = "missing brackets on" + ts.Current.OriginalString; Return sError; } Else {// close bracket ts.moveNext (); } SReturnValue = PCSOpt (sCSValue, ts); break; } Default: {string sSentenceVal = Sentence (ts); // sSentenceVal is true value - the initial sentence component // will use that value of "true" or "false" // "CSOpt", with a special combination // and the value of the current token, // to generate a New Truth Value SReturnValue = CSOPT (Assentance, TS); break; }} Return sReturnValue; } As I say, I'm new in this area, so maybe I do not understand anything fundamental.
If someone can guide me on the right track, I would appreciate it very much.
For expression, a hand-coded recursive lineage parser is a very easy thing for code.
See my
Once you create the structure of the parser, it is very easy to evaluate the expression-as-parse.
/ div>
Comments
Post a Comment