@@ -16,104 +16,99 @@ Token makeSymbol(vector<TokenType> expected){
1616 return makeSymbol ({}); //makesymbol advances the cursor
1717 }
1818 int intc = int (c );
19- int tup = kartyp [int (c )];
20- symIn .content = KarPP [int (c )]; // pretty print
21- switch (tup ) {
22- case LETT : case DIGIT : case DOT : //c is a KAR, so we're building a string
23- s = "" ;
24- while (isaC (c , {LETT , DIGIT , DOT })) {
25- s += c ;
26- cursor ++ ;
27- c = textIn [cursor ];
28- };
29- symIn .type = VARI ;
30- symIn .content = s ;
31- cursor -- ;
32- break ;
33- case EXCLA : case ETX : case LF : case CR : case OTHER :
34- symIn .type = EOT ;
35- return symIn ;
36- break ;
37- case PAR_L :
38- symIn .type = BEXPS ; //the special character becomes the typ
39- break ;
40- case PAR_R :
41- symIn .type = BEXPE ; //the special character becomes the typ
42- break ;
43- case TIMES : case DIV : case GT : case LT : case EQ :
44- if (! (isFirstSymbol )) { //we have a separator
45- symIn .type = TimesDiv ; //the special character becomes the typ
46- }
47- break ;
48- case QUEST :
49- symIn .type = ELV_Q ; //the special character becomes the typ
50- break ;
51- case COLON :
52- symIn .type = ELV_C ; //the special character becomes the typ
53- break ;
54- case PLUS : case MINUS :
55- if (isFirstSymbol ) {
56- symIn .type = CHS ;
57- } else if (isaC (textIn [cursor - 1 ], {TIMES , DIV , PLUS , MINUS , PAR_L , QUEST })) {
58- // we are not adding to the previous, this is a unary operator
59- symIn .type = CHS ;
60- } else symIn .type = PlusMin ;
61- break ;
62- case TEST : //c is a KAR, so we're building a string
63- // var s = "";
64- // s += c;
65- // cursor++
66- // c = textIn[cursor]
67- // while (isaC(c, LETT, DIGIT)) {
68- // s += c;
69- // cursor++
70- // c = textIn[cursor]
71- // }
72- // symIn.typ = VARI;
73- // symIn.content = s
74- break ;
75- default :
76- symIn .type = NONE ; //the special character becomes the typ
77- break ;
78- }
19+
20+ symIn .content = KarPP [int (c )]; // pretty print
21+ symIn .opcode = -1 ;
22+ KarType karTypeIn = kartyp [int (c )];
23+ switch (karTypeIn ) {
24+ case LETT : case DIGIT : case DOT : //c is a KAR, so we're building a string
25+ s = "" ;
26+ while (isaC (c , {LETT , DIGIT , DOT })) {
27+ s += c ;
28+ cursor ++ ;
29+ c = textIn [cursor ];
30+ };
31+ if (karTypeIn == DIGIT ) symIn .type = NUM ; else symIn .type = LIT ;
32+ symIn .content = s ;
33+ cursor -- ;
34+ break ;
35+ case TIMES :
36+ symIn .type = TimesDiv ; symIn .opcode = 0 ; symIn .arity = 2 ; //oMUL; //we have a separator
37+ break ;
38+ case DIV :
39+ symIn .type = TimesDiv ; symIn .opcode = 1 ; symIn .arity = 2 ; //oDIV; //we have a separator
40+ break ;
41+ case PLUS :
42+ if (isFirstSymbol ) {symIn .type = CHS ; symIn .opcode = 0 ;} //oCHS;}
43+ else if (isaC (textIn [cursor - 1 ], {TIMES , DIV , PLUS , MINUS , PAR_L , QUEST })) {
44+ // we are not adding to the previous, this is a unary operator
45+ symIn .type = CHS ; symIn .opcode = 0 ; //oCHS;
46+ } else {symIn .type = PlusMin ; symIn .opcode = 2 ;} //oSUM;}
47+ break ;
48+ case MINUS :
49+ if (isFirstSymbol ) {symIn .type = CHS ; symIn .opcode = 0 ; symIn .arity = 1 ; } //oCHS;}
50+ else if (isaC (textIn [cursor - 1 ], {TIMES , DIV , PLUS , MINUS , PAR_L , QUEST })) {
51+ // we are not adding to the previous, this is a unary operator
52+ symIn .type = CHS ; symIn .opcode = 0 ; symIn .arity = 1 ; //oCHS;
53+ } else {symIn .type = PlusMin ; symIn .opcode = 3 ;} //oMIN;}
54+ break ;
55+ case LT :
56+ symIn .type = COMPARE ; symIn .opcode = 4 ; symIn .arity = 2 ; //oLT;
57+ break ;
58+ case EQ :
59+ symIn .type = COMPARE ; symIn .opcode = 5 ; symIn .arity = 2 ; //oEQ;
60+ break ;
61+ case GT :
62+ symIn .type = COMPARE ; symIn .opcode = 6 ; symIn .arity = 2 ; //oGT;
63+ break ;
64+ case QUEST :
65+ symIn .type = ELV_Q ; symIn .opcode = 0 ; //oQUE;
66+ break ;
67+ case COLON :
68+ symIn .type = ELV_C ; symIn .opcode = -1 ; symIn .arity = 13 ;
69+ break ;
70+ default :
71+ symIn .type = tokenType [kartyp [int (c )]];
72+ symIn .opcode = -1 ;
73+ break ;
74+ }
7975 isFirstSymbol = false;
8076 cursor ++ ;
81- if (expected .empty ()) return symIn ; //default, we do not complain
82- if (count (expected .begin (), expected .end (), symIn .type ) > 0 ) return symIn ; //check on expected char is ok, no complaints
83- errorsPresent = true;
77+ if (expected .empty ()) return symIn ; //default, we do not complain
78+ if (count (expected .begin (), expected .end (), symIn .type ) > 0 ) return symIn ; //check on expected char is ok, no complaints
79+ errorsPresent = true;
8480// throw IllegalArgumentException(
8581// "SEPARATOR in line at cursor " +
8682// "$cursor < ${textIn.substring(0, cursor)} > \n" +
8783// " char=$c, symbol=${symIn.content} ==> < ${expected.contentToString()} >\n"
8884// );
89- return symIn ;
85+ return symIn ;
9086}
9187
9288void clear1 () {
93- cursor = 0 ;
94- errorsPresent = false;
95- symList .clear ();
89+ cursor = 0 ;
90+ errorsPresent = false;
91+ symList .clear ();
9692}
9793
9894vector < Token > parse1 (){
99- clear1 ();
100- cursor = 0 ;
101- errorsPresent = false;
102- reportln ("textIn = $textIn" , 0 );
103- do {
104- symIn = makeSymbol ({});
105- if (isa (symIn , {ELV_C })) { // substitute '?(' for '?'
106- symList .push_back ({BEXPE , 17 , ")" , cursor }); //todo pretty print
107- };
108- symList .push_back ({symIn .type , 17 , symIn .content , cursor });
109- if (isa (symIn , {ELV_Q })) { // substitute '?(' for '?'
110- symList .push_back ({BEXPS , 17 , "(" , cursor }); //todo
111- };
112- } while (symIn .type != EOT );
95+ clear1 ();
96+ cursor = 0 ;
97+ errorsPresent = false;
98+ do {
99+ symIn = makeSymbol ({});
113100
114- reportln (symList , 1 , 7 );
115- cout << "\n" ;
116- return symList ;
101+ // in case of a "? XXX : YYY" construct we insert parentheses around the XXX part. this isolates the expression XXX
102+ if (isa (symIn , {ELV_C })) { // substitute '?(' for '?'
103+ symList .push_back ({BEXPE , ")" , oCOL , -1 , cursor });
104+ };
105+ symList .push_back (symIn );
106+ // symList.push_back({symIn.type, symIn.content, oNONE, -1, cursor});
107+ if (isa (symIn , {ELV_Q })) { // substitute '?(' for '?'
108+ symList .push_back ({BEXPS , "(" , oQUE , -1 , cursor }); //
109+ };
110+ } while (symIn .type != EOT );
111+ return symList ;
117112}
118113
119114
0 commit comments