• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

programming language


Commit MetaInfo

Revision8c8a6a184b8dc32a82ed5727df1e0ed3d072be1f (tree)
Time2023-07-05 22:53:04
Authordhrname <dhrname@joes...>
Commiterdhrname

Log Message

Generate parser sourcecode on JavaCC

Change Summary

Incremental Difference

--- /dev/null
+++ b/JostarParser.java
@@ -0,0 +1,994 @@
1+/* Generated By:JavaCC: Do not edit this line. JostarParser.java */
2+package c0front;
3+
4+import java.io.FileReader;
5+
6+import coins.HirRoot;
7+import coins.IoRoot;
8+import coins.SymRoot;
9+import coins.ir.IrList;
10+import coins.ir.hir.BlockStmt;
11+import coins.ir.hir.Exp;
12+import coins.ir.hir.HIR0;
13+import coins.ir.hir.Program;
14+import coins.ir.hir.Stmt;
15+import coins.ir.hir.SubpDefinition;
16+import coins.sym.IntConst;
17+import coins.sym.Param;
18+import coins.sym.PointerType;
19+import coins.sym.Subp;
20+import coins.sym.Sym0;
21+import coins.sym.Type;
22+import coins.sym.Var;
23+import coins.sym.VectorType;
24+
25+public class JostarParser implements JostarParserConstants {
26+ private SymRoot symRoot; // root of symbol information
27+ private Sym0 sym; // Sym0 object creator
28+ private HirRoot hirRoot; // root of HIR information
29+ private HIR0 hir; // HIR0 object creator
30+ private IoRoot ioRoot; // root of I/O information
31+ private int currentLine=0; // Line number of token that appeared as the first
32+ // ID of a statement. When currentLine is recorded as the line number
33+ // of a statement, then it is set to 0 so that it will be set by next ID.
34+
35+ public JostarParser(SymRoot sRoot, HirRoot hRoot, IoRoot iRoot, FileReader reader) {
36+ this(reader);
37+ symRoot = sRoot;
38+ sym = (Sym0)symRoot.sym;
39+ hirRoot = hRoot;
40+ hir = (HIR0)hirRoot.hir;
41+ ioRoot = iRoot;
42+ hirRoot.programRoot = hir.program(null, symRoot.symTableRoot, null, null);
43+ }
44+
45+ final public void program() throws ParseException {
46+ label_1:
47+ while (true) {
48+ externalDecl();
49+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
50+ case INT:
51+ case VOID:
52+ ;
53+ break;
54+ default:
55+ jj_la1[0] = jj_gen;
56+ break label_1;
57+ }
58+ }
59+ jj_consume_token(0);
60+ }
61+
62+ final public void externalDecl() throws ParseException {
63+ Subp lSubp; BlockStmt lBlockStmt; Stmt lStmt;
64+ if (jj_2_1(3)) {
65+ variableDecl();
66+ } else {
67+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
68+ case INT:
69+ case VOID:
70+ lSubp = subpDeclarator();
71+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
72+ case 20:
73+ jj_consume_token(20);
74+ lSubp.setVisibility(Sym0.SYM_EXTERN);
75+ symRoot.symTableCurrent.popSymTable();
76+ break;
77+ case 21:
78+ jj_consume_token(21);
79+ label_2:
80+ while (true) {
81+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
82+ case INT:
83+ case VOID:
84+ ;
85+ break;
86+ default:
87+ jj_la1[1] = jj_gen;
88+ break label_2;
89+ }
90+ variableDecl();
91+ }
92+ lBlockStmt = hir.blockStmt(null);
93+ label_3:
94+ while (true) {
95+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
96+ case IF:
97+ case WHILE:
98+ case RETURN:
99+ case ID:
100+ case 21:
101+ ;
102+ break;
103+ default:
104+ jj_la1[2] = jj_gen;
105+ break label_3;
106+ }
107+ lStmt = stmt();
108+ lBlockStmt.addLastStmt(lStmt);
109+ }
110+ lSubp.setVisibility(Sym0.SYM_PUBLIC);
111+ SubpDefinition lSubpDef
112+ = hir.subpDefinition(lSubp, symRoot.symTableCurrent);
113+ lSubpDef.setHirBody(lBlockStmt);
114+ ((Program)hirRoot.programRoot).addSubpDefinition(lSubpDef);
115+ symRoot.symTableCurrent.popSymTable();
116+ jj_consume_token(22);
117+ break;
118+ default:
119+ jj_la1[3] = jj_gen;
120+ jj_consume_token(-1);
121+ throw new ParseException();
122+ }
123+ break;
124+ default:
125+ jj_la1[4] = jj_gen;
126+ jj_consume_token(-1);
127+ throw new ParseException();
128+ }
129+ }
130+ }
131+
132+ final public void variableDecl() throws ParseException {
133+ Type t;
134+ t = typeId();
135+ varDecl(t);
136+ label_4:
137+ while (true) {
138+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
139+ case 23:
140+ ;
141+ break;
142+ default:
143+ jj_la1[5] = jj_gen;
144+ break label_4;
145+ }
146+ jj_consume_token(23);
147+ varDecl(t);
148+ }
149+ jj_consume_token(20);
150+ }
151+
152+ final public Type typeId() throws ParseException {
153+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
154+ case INT:
155+ jj_consume_token(INT);
156+ {if (true) return symRoot.typeInt;}
157+ break;
158+ case VOID:
159+ jj_consume_token(VOID);
160+ {if (true) return symRoot.typeVoid;}
161+ break;
162+ default:
163+ jj_la1[6] = jj_gen;
164+ jj_consume_token(-1);
165+ throw new ParseException();
166+ }
167+ throw new Error("Missing return statement in function");
168+ }
169+
170+ final public void varDecl(Type t) throws ParseException {
171+ Token id, num; Var lVar; Type lType;
172+ id = jj_consume_token(ID);
173+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
174+ case 24:
175+ jj_consume_token(24);
176+ num = jj_consume_token(NUM);
177+ jj_consume_token(25);
178+ lType = sym.vectorType(t, Long.parseLong(num.image));
179+ break;
180+ default:
181+ jj_la1[7] = jj_gen;
182+ lType = t;
183+ }
184+ lVar = sym.defineVar(id.image.intern(), lType);
185+ lVar.setVisibility(Sym0.SYM_PUBLIC);
186+ ioRoot.dbgHir.print(2, "variableDeclaration", lVar.toString() +
187+ " " + lType.toString());
188+ }
189+
190+ final public Subp subpDeclarator() throws ParseException {
191+ Type t; Token id; Subp lSubp;
192+ t = typeId();
193+ id = jj_consume_token(ID);
194+ lSubp = sym.defineSubp(id.image.intern(), t);
195+ symRoot.symTableCurrent.pushSymTable(lSubp);
196+ jj_consume_token(26);
197+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
198+ case INT:
199+ case VOID:
200+ paramDecl(lSubp);
201+ label_5:
202+ while (true) {
203+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
204+ case 23:
205+ ;
206+ break;
207+ default:
208+ jj_la1[8] = jj_gen;
209+ break label_5;
210+ }
211+ jj_consume_token(23);
212+ paramDecl(lSubp);
213+ }
214+ break;
215+ default:
216+ jj_la1[9] = jj_gen;
217+ ;
218+ }
219+ jj_consume_token(27);
220+ lSubp.closeSubpHeader();
221+ ioRoot.dbgHir.print(2, "subpDeclaration", lSubp.toString() +
222+ " " + t.toString());
223+ {if (true) return lSubp;}
224+ throw new Error("Missing return statement in function");
225+ }
226+
227+ final public void paramDecl(Subp pSubp) throws ParseException {
228+ Type t, lType; Token id;
229+ t = typeId();
230+ id = jj_consume_token(ID);
231+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
232+ case 24:
233+ jj_consume_token(24);
234+ jj_consume_token(25);
235+ //lType = sym.pointerType(t);
236+ VectorType vType = sym.vectorTypeUnfixed(t, 0);
237+ lType = sym.pointerType(vType);
238+ break;
239+ default:
240+ jj_la1[10] = jj_gen;
241+ lType = t;
242+ }
243+ Param lParam = sym.defineParam(id.image.intern(), lType);
244+ pSubp.addParam(lParam);
245+ ioRoot.dbgHir.print(2, "paramDeclaration", lParam.toString() +
246+ " " + lType.toString());
247+ }
248+
249+ final public Stmt stmt() throws ParseException {
250+ Token id; Stmt lStmt, lStmt2; Exp lExp, lExp2;
251+ if (jj_2_2(2)) {
252+ lExp = variable();
253+ jj_consume_token(28);
254+ lExp2 = expr();
255+ jj_consume_token(20);
256+ lStmt = hir.assignStmt(lExp, lExp2);
257+ } else {
258+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
259+ case IF:
260+ id = jj_consume_token(IF);
261+ jj_consume_token(26);
262+ lExp = conditionalExp();
263+ jj_consume_token(27);
264+ lStmt = stmt();
265+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
266+ case ELSE:
267+ jj_consume_token(ELSE);
268+ lStmt2 = stmt();
269+ lStmt = hir.ifStmt(lExp, lStmt, lStmt2);
270+ break;
271+ default:
272+ jj_la1[11] = jj_gen;
273+ lStmt = hir.ifStmt(lExp, lStmt, null);
274+ }
275+ currentLine = id.beginLine;
276+ break;
277+ case WHILE:
278+ jj_consume_token(WHILE);
279+ jj_consume_token(26);
280+ lExp = conditionalExp();
281+ jj_consume_token(27);
282+ lStmt = stmt();
283+ lStmt = hir.whileStmt(lExp, lStmt);
284+ break;
285+ case 21:
286+ jj_consume_token(21);
287+ BlockStmt lBlockStmt = hir.blockStmt(null);
288+ label_6:
289+ while (true) {
290+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
291+ case IF:
292+ case WHILE:
293+ case RETURN:
294+ case ID:
295+ case 21:
296+ ;
297+ break;
298+ default:
299+ jj_la1[12] = jj_gen;
300+ break label_6;
301+ }
302+ lStmt = stmt();
303+ lBlockStmt.addLastStmt(lStmt);
304+ }
305+ jj_consume_token(22);
306+ lStmt = lBlockStmt;
307+ break;
308+ case ID:
309+ lExp = callExpr();
310+ jj_consume_token(20);
311+ lStmt = hir.expStmt(lExp);
312+ break;
313+ case RETURN:
314+ id = jj_consume_token(RETURN);
315+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
316+ case ID:
317+ case NUM:
318+ case 35:
319+ case 36:
320+ lExp = expr();
321+ lStmt = hir.returnStmt(lExp);
322+ break;
323+ default:
324+ jj_la1[13] = jj_gen;
325+ lStmt = hir.returnStmt(null);
326+ }
327+ jj_consume_token(20);
328+ currentLine = id.beginLine;
329+ break;
330+ default:
331+ jj_la1[14] = jj_gen;
332+ jj_consume_token(-1);
333+ throw new ParseException();
334+ }
335+ }
336+ if (lStmt != null)
337+ ioRoot.dbgHir.print(2, "makeStmt", lStmt.toString());
338+ lStmt.setLineNumber(currentLine);
339+ currentLine = 0; // Set 0 so as it is set at ID processing.
340+ {if (true) return lStmt;}
341+ throw new Error("Missing return statement in function");
342+ }
343+
344+ final public Exp conditionalExp() throws ParseException {
345+ Exp lExp, lExp2; int op;
346+ lExp = expr();
347+ op = comparisonOperator();
348+ lExp2 = expr();
349+ lExp = hir.exp(op, lExp, lExp2);
350+ ioRoot.dbgHir.print(2, "makeConditionalExp", lExp.toString());
351+ {if (true) return lExp;}
352+ throw new Error("Missing return statement in function");
353+ }
354+
355+ final public int comparisonOperator() throws ParseException {
356+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
357+ case 29:
358+ jj_consume_token(29);
359+ {if (true) return HIR0.OP_CMP_EQ;}
360+ break;
361+ case 30:
362+ jj_consume_token(30);
363+ {if (true) return HIR0.OP_CMP_NE;}
364+ break;
365+ case 31:
366+ jj_consume_token(31);
367+ {if (true) return HIR0.OP_CMP_GT;}
368+ break;
369+ case 32:
370+ jj_consume_token(32);
371+ {if (true) return HIR0.OP_CMP_GE;}
372+ break;
373+ case 33:
374+ jj_consume_token(33);
375+ {if (true) return HIR0.OP_CMP_LT;}
376+ break;
377+ case 34:
378+ jj_consume_token(34);
379+ {if (true) return HIR0.OP_CMP_LE;}
380+ break;
381+ default:
382+ jj_la1[15] = jj_gen;
383+ jj_consume_token(-1);
384+ throw new ParseException();
385+ }
386+ throw new Error("Missing return statement in function");
387+ }
388+
389+ final public Exp expr() throws ParseException {
390+ Exp lExp, lExp2;
391+ lExp = term();
392+ label_7:
393+ while (true) {
394+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
395+ case 35:
396+ case 36:
397+ ;
398+ break;
399+ default:
400+ jj_la1[16] = jj_gen;
401+ break label_7;
402+ }
403+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
404+ case 35:
405+ jj_consume_token(35);
406+ lExp2 = term();
407+ lExp = hir.exp(HIR0.OP_ADD, lExp, lExp2);
408+ break;
409+ case 36:
410+ jj_consume_token(36);
411+ lExp2 = term();
412+ lExp = hir.exp(HIR0.OP_SUB, lExp, lExp2);
413+ break;
414+ default:
415+ jj_la1[17] = jj_gen;
416+ jj_consume_token(-1);
417+ throw new ParseException();
418+ }
419+ }
420+ {if (true) return lExp;}
421+ throw new Error("Missing return statement in function");
422+ }
423+
424+ final public Exp term() throws ParseException {
425+ Exp lExp, lExp2;
426+ lExp = factor();
427+ label_8:
428+ while (true) {
429+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
430+ case 37:
431+ case 38:
432+ ;
433+ break;
434+ default:
435+ jj_la1[18] = jj_gen;
436+ break label_8;
437+ }
438+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
439+ case 37:
440+ jj_consume_token(37);
441+ lExp2 = factor();
442+ lExp = hir.exp(HIR0.OP_MULT, lExp, lExp2);
443+ break;
444+ case 38:
445+ jj_consume_token(38);
446+ lExp2 = factor();
447+ lExp = hir.exp(HIR0.OP_DIV, lExp, lExp2);
448+ break;
449+ default:
450+ jj_la1[19] = jj_gen;
451+ jj_consume_token(-1);
452+ throw new ParseException();
453+ }
454+ }
455+ {if (true) return lExp;}
456+ throw new Error("Missing return statement in function");
457+ }
458+
459+ final public Exp factor() throws ParseException {
460+ Exp lExp; Token num;
461+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
462+ case 35:
463+ jj_consume_token(35);
464+ lExp = factor();
465+ {if (true) return lExp;}
466+ break;
467+ case 36:
468+ jj_consume_token(36);
469+ lExp = factor();
470+ {if (true) return hir.exp(HIR0.OP_NEG, lExp);}
471+ break;
472+ default:
473+ jj_la1[20] = jj_gen;
474+ if (jj_2_3(2)) {
475+ lExp = callExpr();
476+ {if (true) return lExp;}
477+ } else {
478+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
479+ case ID:
480+ lExp = variable();
481+ {if (true) return lExp;}
482+ break;
483+ case NUM:
484+ num = jj_consume_token(NUM);
485+ IntConst lConst = sym.intConst(Long.parseLong(num.image), symRoot.typeInt);
486+ {if (true) return hir.constNode(lConst);}
487+ break;
488+ default:
489+ jj_la1[21] = jj_gen;
490+ jj_consume_token(-1);
491+ throw new ParseException();
492+ }
493+ }
494+ }
495+ throw new Error("Missing return statement in function");
496+ }
497+
498+ final public Exp variable() throws ParseException {
499+ Token id; Exp lExp;
500+ id = jj_consume_token(ID);
501+ if (currentLine == 0)
502+ currentLine = id.beginLine;
503+ Sym0 lSym = (Var)symRoot.symTableCurrent.search(id.image.intern());
504+ if (!(lSym instanceof Var)) {
505+ recoveredError("undeclared variable " + id.image, id.beginLine);
506+ lSym = sym.defineVar(id.image, symRoot.typeInt);
507+ }
508+ Exp lVarNode = hir.varNode((Var)lSym);
509+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
510+ case 24:
511+ jj_consume_token(24);
512+ lExp = expr();
513+ jj_consume_token(25);
514+ if (lSym.getSymType() instanceof PointerType)
515+ lExp = hir.subscriptedExp(hir.contentsExp(lVarNode), lExp);
516+ else
517+ lExp = hir.subscriptedExp(lVarNode, lExp);
518+ break;
519+ default:
520+ jj_la1[22] = jj_gen;
521+ if (lSym.getSymType() instanceof VectorType)
522+ lExp = hir.exp(HIR0.OP_ADDR, lVarNode);
523+ else
524+ lExp = lVarNode;
525+ }
526+ ioRoot.dbgHir.print(4, "makeVariable",lExp.toString());
527+ {if (true) return lExp;}
528+ throw new Error("Missing return statement in function");
529+ }
530+
531+ final public Exp callExpr() throws ParseException {
532+ Token id; Exp lExp;
533+ id = jj_consume_token(ID);
534+ String lSubpName = id.image.intern();
535+ currentLine = id.beginLine;
536+ Subp lSubp = (Subp)symRoot.symTableCurrent.search(lSubpName, Sym0.KIND_SUBP);
537+ if (lSubp == null) {
538+ recoveredError("undeclared subprogram " + lSubpName, id.beginLine);
539+ lSubp = sym.defineSubp(lSubpName, symRoot.typeInt);
540+ }
541+ IrList lParamList = hir.irList();
542+ jj_consume_token(26);
543+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
544+ case ID:
545+ case NUM:
546+ case 35:
547+ case 36:
548+ lExp = expr();
549+ lParamList.add(lExp);
550+ label_9:
551+ while (true) {
552+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
553+ case 23:
554+ ;
555+ break;
556+ default:
557+ jj_la1[23] = jj_gen;
558+ break label_9;
559+ }
560+ jj_consume_token(23);
561+ lExp = expr();
562+ lParamList.add(lExp);
563+ }
564+ break;
565+ default:
566+ jj_la1[24] = jj_gen;
567+ ;
568+ }
569+ jj_consume_token(27);
570+ {if (true) return hir.functionExp(hir.exp(HIR0.OP_ADDR, hir.subpNode(lSubp)), lParamList);}
571+ throw new Error("Missing return statement in function");
572+ }
573+
574+ void recoveredError(String pMessage, int pLine) throws ParseException {
575+ if (pLine > 0)
576+ ioRoot.msgRecovered.put(pMessage + " line " + pLine);
577+ else
578+ ioRoot.msgRecovered.put(pMessage);
579+ }
580+
581+ private boolean jj_2_1(int xla) {
582+ jj_la = xla; jj_lastpos = jj_scanpos = token;
583+ try { return !jj_3_1(); }
584+ catch(LookaheadSuccess ls) { return true; }
585+ finally { jj_save(0, xla); }
586+ }
587+
588+ private boolean jj_2_2(int xla) {
589+ jj_la = xla; jj_lastpos = jj_scanpos = token;
590+ try { return !jj_3_2(); }
591+ catch(LookaheadSuccess ls) { return true; }
592+ finally { jj_save(1, xla); }
593+ }
594+
595+ private boolean jj_2_3(int xla) {
596+ jj_la = xla; jj_lastpos = jj_scanpos = token;
597+ try { return !jj_3_3(); }
598+ catch(LookaheadSuccess ls) { return true; }
599+ finally { jj_save(2, xla); }
600+ }
601+
602+ private boolean jj_3R_11() {
603+ if (jj_scan_token(ID)) return true;
604+ Token xsp;
605+ xsp = jj_scanpos;
606+ if (jj_3R_16()) {
607+ jj_scanpos = xsp;
608+ if (jj_3R_17()) return true;
609+ }
610+ return false;
611+ }
612+
613+ private boolean jj_3_1() {
614+ if (jj_3R_10()) return true;
615+ return false;
616+ }
617+
618+ private boolean jj_3R_15() {
619+ if (jj_scan_token(23)) return true;
620+ return false;
621+ }
622+
623+ private boolean jj_3R_10() {
624+ if (jj_3R_13()) return true;
625+ if (jj_3R_14()) return true;
626+ Token xsp;
627+ while (true) {
628+ xsp = jj_scanpos;
629+ if (jj_3R_15()) { jj_scanpos = xsp; break; }
630+ }
631+ if (jj_scan_token(20)) return true;
632+ return false;
633+ }
634+
635+ private boolean jj_3R_20() {
636+ if (jj_scan_token(24)) return true;
637+ return false;
638+ }
639+
640+ private boolean jj_3R_17() {
641+ return false;
642+ }
643+
644+ private boolean jj_3R_16() {
645+ if (jj_scan_token(24)) return true;
646+ return false;
647+ }
648+
649+ private boolean jj_3_3() {
650+ if (jj_3R_12()) return true;
651+ return false;
652+ }
653+
654+ private boolean jj_3R_14() {
655+ if (jj_scan_token(ID)) return true;
656+ Token xsp;
657+ xsp = jj_scanpos;
658+ if (jj_3R_20()) {
659+ jj_scanpos = xsp;
660+ if (jj_3R_21()) return true;
661+ }
662+ return false;
663+ }
664+
665+ private boolean jj_3_2() {
666+ if (jj_3R_11()) return true;
667+ if (jj_scan_token(28)) return true;
668+ return false;
669+ }
670+
671+ private boolean jj_3R_19() {
672+ if (jj_scan_token(VOID)) return true;
673+ return false;
674+ }
675+
676+ private boolean jj_3R_18() {
677+ if (jj_scan_token(INT)) return true;
678+ return false;
679+ }
680+
681+ private boolean jj_3R_13() {
682+ Token xsp;
683+ xsp = jj_scanpos;
684+ if (jj_3R_18()) {
685+ jj_scanpos = xsp;
686+ if (jj_3R_19()) return true;
687+ }
688+ return false;
689+ }
690+
691+ private boolean jj_3R_12() {
692+ if (jj_scan_token(ID)) return true;
693+ if (jj_scan_token(26)) return true;
694+ return false;
695+ }
696+
697+ private boolean jj_3R_21() {
698+ return false;
699+ }
700+
701+ /** Generated Token Manager. */
702+ public JostarParserTokenManager token_source;
703+ SimpleCharStream jj_input_stream;
704+ /** Current token. */
705+ public Token token;
706+ /** Next token. */
707+ public Token jj_nt;
708+ private int jj_ntk;
709+ private Token jj_scanpos, jj_lastpos;
710+ private int jj_la;
711+ /** Whether we are looking ahead. */
712+ private boolean jj_lookingAhead = false;
713+ private boolean jj_semLA;
714+ private int jj_gen;
715+ final private int[] jj_la1 = new int[25];
716+ static private int[] jj_la1_0;
717+ static private int[] jj_la1_1;
718+ static {
719+ jj_la1_init_0();
720+ jj_la1_init_1();
721+ }
722+ private static void jj_la1_init_0() {
723+ jj_la1_0 = new int[] {0x600,0x600,0x216800,0x300000,0x600,0x800000,0x600,0x1000000,0x800000,0x600,0x1000000,0x1000,0x216800,0x30000,0x216800,0xe0000000,0x0,0x0,0x0,0x0,0x0,0x30000,0x1000000,0x800000,0x30000,};
724+ }
725+ private static void jj_la1_init_1() {
726+ jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x18,0x0,0x7,0x18,0x18,0x60,0x60,0x18,0x0,0x0,0x0,0x18,};
727+ }
728+ final private JJCalls[] jj_2_rtns = new JJCalls[3];
729+ private boolean jj_rescan = false;
730+ private int jj_gc = 0;
731+
732+ /** Constructor with InputStream. */
733+ public JostarParser(java.io.InputStream stream) {
734+ this(stream, null);
735+ }
736+ /** Constructor with InputStream and supplied encoding */
737+ public JostarParser(java.io.InputStream stream, String encoding) {
738+ try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
739+ token_source = new JostarParserTokenManager(jj_input_stream);
740+ token = new Token();
741+ jj_ntk = -1;
742+ jj_gen = 0;
743+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
744+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
745+ }
746+
747+ /** Reinitialise. */
748+ public void ReInit(java.io.InputStream stream) {
749+ ReInit(stream, null);
750+ }
751+ /** Reinitialise. */
752+ public void ReInit(java.io.InputStream stream, String encoding) {
753+ try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
754+ token_source.ReInit(jj_input_stream);
755+ token = new Token();
756+ jj_ntk = -1;
757+ jj_gen = 0;
758+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
759+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
760+ }
761+
762+ /** Constructor. */
763+ public JostarParser(java.io.Reader stream) {
764+ jj_input_stream = new SimpleCharStream(stream, 1, 1);
765+ token_source = new JostarParserTokenManager(jj_input_stream);
766+ token = new Token();
767+ jj_ntk = -1;
768+ jj_gen = 0;
769+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
770+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
771+ }
772+
773+ /** Reinitialise. */
774+ public void ReInit(java.io.Reader stream) {
775+ jj_input_stream.ReInit(stream, 1, 1);
776+ token_source.ReInit(jj_input_stream);
777+ token = new Token();
778+ jj_ntk = -1;
779+ jj_gen = 0;
780+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
781+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
782+ }
783+
784+ /** Constructor with generated Token Manager. */
785+ public JostarParser(JostarParserTokenManager tm) {
786+ token_source = tm;
787+ token = new Token();
788+ jj_ntk = -1;
789+ jj_gen = 0;
790+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
791+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
792+ }
793+
794+ /** Reinitialise. */
795+ public void ReInit(JostarParserTokenManager tm) {
796+ token_source = tm;
797+ token = new Token();
798+ jj_ntk = -1;
799+ jj_gen = 0;
800+ for (int i = 0; i < 25; i++) jj_la1[i] = -1;
801+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
802+ }
803+
804+ private Token jj_consume_token(int kind) throws ParseException {
805+ Token oldToken;
806+ if ((oldToken = token).next != null) token = token.next;
807+ else token = token.next = token_source.getNextToken();
808+ jj_ntk = -1;
809+ if (token.kind == kind) {
810+ jj_gen++;
811+ if (++jj_gc > 100) {
812+ jj_gc = 0;
813+ for (int i = 0; i < jj_2_rtns.length; i++) {
814+ JJCalls c = jj_2_rtns[i];
815+ while (c != null) {
816+ if (c.gen < jj_gen) c.first = null;
817+ c = c.next;
818+ }
819+ }
820+ }
821+ return token;
822+ }
823+ token = oldToken;
824+ jj_kind = kind;
825+ throw generateParseException();
826+ }
827+
828+ static private final class LookaheadSuccess extends java.lang.Error { }
829+ final private LookaheadSuccess jj_ls = new LookaheadSuccess();
830+ private boolean jj_scan_token(int kind) {
831+ if (jj_scanpos == jj_lastpos) {
832+ jj_la--;
833+ if (jj_scanpos.next == null) {
834+ jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
835+ } else {
836+ jj_lastpos = jj_scanpos = jj_scanpos.next;
837+ }
838+ } else {
839+ jj_scanpos = jj_scanpos.next;
840+ }
841+ if (jj_rescan) {
842+ int i = 0; Token tok = token;
843+ while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
844+ if (tok != null) jj_add_error_token(kind, i);
845+ }
846+ if (jj_scanpos.kind != kind) return true;
847+ if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
848+ return false;
849+ }
850+
851+
852+/** Get the next Token. */
853+ final public Token getNextToken() {
854+ if (token.next != null) token = token.next;
855+ else token = token.next = token_source.getNextToken();
856+ jj_ntk = -1;
857+ jj_gen++;
858+ return token;
859+ }
860+
861+/** Get the specific Token. */
862+ final public Token getToken(int index) {
863+ Token t = jj_lookingAhead ? jj_scanpos : token;
864+ for (int i = 0; i < index; i++) {
865+ if (t.next != null) t = t.next;
866+ else t = t.next = token_source.getNextToken();
867+ }
868+ return t;
869+ }
870+
871+ private int jj_ntk() {
872+ if ((jj_nt=token.next) == null)
873+ return (jj_ntk = (token.next=token_source.getNextToken()).kind);
874+ else
875+ return (jj_ntk = jj_nt.kind);
876+ }
877+
878+ private java.util.List jj_expentries = new java.util.ArrayList();
879+ private int[] jj_expentry;
880+ private int jj_kind = -1;
881+ private int[] jj_lasttokens = new int[100];
882+ private int jj_endpos;
883+
884+ private void jj_add_error_token(int kind, int pos) {
885+ if (pos >= 100) return;
886+ if (pos == jj_endpos + 1) {
887+ jj_lasttokens[jj_endpos++] = kind;
888+ } else if (jj_endpos != 0) {
889+ jj_expentry = new int[jj_endpos];
890+ for (int i = 0; i < jj_endpos; i++) {
891+ jj_expentry[i] = jj_lasttokens[i];
892+ }
893+ boolean exists = false;
894+ for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
895+ int[] oldentry = (int[])(it.next());
896+ if (oldentry.length == jj_expentry.length) {
897+ exists = true;
898+ for (int i = 0; i < jj_expentry.length; i++) {
899+ if (oldentry[i] != jj_expentry[i]) {
900+ exists = false;
901+ break;
902+ }
903+ }
904+ if (exists) break;
905+ }
906+ }
907+ if (!exists) jj_expentries.add(jj_expentry);
908+ if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
909+ }
910+ }
911+
912+ /** Generate ParseException. */
913+ public ParseException generateParseException() {
914+ jj_expentries.clear();
915+ boolean[] la1tokens = new boolean[39];
916+ if (jj_kind >= 0) {
917+ la1tokens[jj_kind] = true;
918+ jj_kind = -1;
919+ }
920+ for (int i = 0; i < 25; i++) {
921+ if (jj_la1[i] == jj_gen) {
922+ for (int j = 0; j < 32; j++) {
923+ if ((jj_la1_0[i] & (1<<j)) != 0) {
924+ la1tokens[j] = true;
925+ }
926+ if ((jj_la1_1[i] & (1<<j)) != 0) {
927+ la1tokens[32+j] = true;
928+ }
929+ }
930+ }
931+ }
932+ for (int i = 0; i < 39; i++) {
933+ if (la1tokens[i]) {
934+ jj_expentry = new int[1];
935+ jj_expentry[0] = i;
936+ jj_expentries.add(jj_expentry);
937+ }
938+ }
939+ jj_endpos = 0;
940+ jj_rescan_token();
941+ jj_add_error_token(0, 0);
942+ int[][] exptokseq = new int[jj_expentries.size()][];
943+ for (int i = 0; i < jj_expentries.size(); i++) {
944+ exptokseq[i] = (int[])jj_expentries.get(i);
945+ }
946+ return new ParseException(token, exptokseq, tokenImage);
947+ }
948+
949+ /** Enable tracing. */
950+ final public void enable_tracing() {
951+ }
952+
953+ /** Disable tracing. */
954+ final public void disable_tracing() {
955+ }
956+
957+ private void jj_rescan_token() {
958+ jj_rescan = true;
959+ for (int i = 0; i < 3; i++) {
960+ try {
961+ JJCalls p = jj_2_rtns[i];
962+ do {
963+ if (p.gen > jj_gen) {
964+ jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
965+ switch (i) {
966+ case 0: jj_3_1(); break;
967+ case 1: jj_3_2(); break;
968+ case 2: jj_3_3(); break;
969+ }
970+ }
971+ p = p.next;
972+ } while (p != null);
973+ } catch(LookaheadSuccess ls) { }
974+ }
975+ jj_rescan = false;
976+ }
977+
978+ private void jj_save(int index, int xla) {
979+ JJCalls p = jj_2_rtns[index];
980+ while (p.gen > jj_gen) {
981+ if (p.next == null) { p = p.next = new JJCalls(); break; }
982+ p = p.next;
983+ }
984+ p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
985+ }
986+
987+ static final class JJCalls {
988+ int gen;
989+ Token first;
990+ int arg;
991+ JJCalls next;
992+ }
993+
994+}
--- /dev/null
+++ b/JostarParserConstants.java
@@ -0,0 +1,94 @@
1+/* Generated By:JavaCC: Do not edit this line. JostarParserConstants.java */
2+package c0front;
3+
4+
5+/**
6+ * Token literal values and constants.
7+ * Generated by org.javacc.parser.OtherFilesGen#start()
8+ */
9+public interface JostarParserConstants {
10+
11+ /** End of File. */
12+ int EOF = 0;
13+ /** RegularExpression Id. */
14+ int SPACE = 1;
15+ /** RegularExpression Id. */
16+ int INTEGER8 = 5;
17+ /** RegularExpression Id. */
18+ int INTEGER16 = 6;
19+ /** RegularExpression Id. */
20+ int INTEGER32 = 7;
21+ /** RegularExpression Id. */
22+ int INTEGER64 = 8;
23+ /** RegularExpression Id. */
24+ int INT = 9;
25+ /** RegularExpression Id. */
26+ int VOID = 10;
27+ /** RegularExpression Id. */
28+ int IF = 11;
29+ /** RegularExpression Id. */
30+ int ELSE = 12;
31+ /** RegularExpression Id. */
32+ int WHILE = 13;
33+ /** RegularExpression Id. */
34+ int RETURN = 14;
35+ /** RegularExpression Id. */
36+ int FOR = 15;
37+ /** RegularExpression Id. */
38+ int ID = 16;
39+ /** RegularExpression Id. */
40+ int NUM = 17;
41+ /** RegularExpression Id. */
42+ int LETTER = 18;
43+ /** RegularExpression Id. */
44+ int DIGIT = 19;
45+
46+ /** Lexical state. */
47+ int DEFAULT = 0;
48+ /** Lexical state. */
49+ int WithinComment = 1;
50+
51+ /** Literal token values. */
52+ String[] tokenImage = {
53+ "<EOF>",
54+ "<SPACE>",
55+ "\"/*\"",
56+ "\"*/\"",
57+ "<token of kind 4>",
58+ "\"i08\"",
59+ "\"i16\"",
60+ "\"i32\"",
61+ "\"i64\"",
62+ "\"int\"",
63+ "\"void\"",
64+ "\"if\"",
65+ "\"else\"",
66+ "\"while\"",
67+ "\"return\"",
68+ "\"for\"",
69+ "<ID>",
70+ "<NUM>",
71+ "<LETTER>",
72+ "<DIGIT>",
73+ "\";\"",
74+ "\"{\"",
75+ "\"}\"",
76+ "\",\"",
77+ "\"[\"",
78+ "\"]\"",
79+ "\"(\"",
80+ "\")\"",
81+ "\"=\"",
82+ "\"==\"",
83+ "\"!=\"",
84+ "\">\"",
85+ "\">=\"",
86+ "\"<\"",
87+ "\"<=\"",
88+ "\"+\"",
89+ "\"-\"",
90+ "\"*\"",
91+ "\"/\"",
92+ };
93+
94+}
--- /dev/null
+++ b/JostarParserTokenManager.java
@@ -0,0 +1,676 @@
1+/* Generated By:JavaCC: Do not edit this line. JostarParserTokenManager.java */
2+package c0front;
3+import java.io.FileReader;
4+import coins.HirRoot;
5+import coins.IoRoot;
6+import coins.SymRoot;
7+import coins.ir.IrList;
8+import coins.ir.hir.BlockStmt;
9+import coins.ir.hir.Exp;
10+import coins.ir.hir.HIR0;
11+import coins.ir.hir.Program;
12+import coins.ir.hir.Stmt;
13+import coins.ir.hir.SubpDefinition;
14+import coins.sym.IntConst;
15+import coins.sym.Param;
16+import coins.sym.PointerType;
17+import coins.sym.Subp;
18+import coins.sym.Sym0;
19+import coins.sym.Type;
20+import coins.sym.Var;
21+import coins.sym.VectorType;
22+
23+/** Token Manager. */
24+public class JostarParserTokenManager implements JostarParserConstants
25+{
26+
27+ /** Debug output. */
28+ public java.io.PrintStream debugStream = System.out;
29+ /** Set debug output. */
30+ public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
31+private final int jjStopStringLiteralDfa_0(int pos, long active0)
32+{
33+ switch (pos)
34+ {
35+ case 0:
36+ if ((active0 & 0xffe0L) != 0L)
37+ {
38+ jjmatchedKind = 16;
39+ return 2;
40+ }
41+ return -1;
42+ case 1:
43+ if ((active0 & 0x800L) != 0L)
44+ return 2;
45+ if ((active0 & 0xf7e0L) != 0L)
46+ {
47+ jjmatchedKind = 16;
48+ jjmatchedPos = 1;
49+ return 2;
50+ }
51+ return -1;
52+ case 2:
53+ if ((active0 & 0x83e0L) != 0L)
54+ return 2;
55+ if ((active0 & 0x7400L) != 0L)
56+ {
57+ jjmatchedKind = 16;
58+ jjmatchedPos = 2;
59+ return 2;
60+ }
61+ return -1;
62+ case 3:
63+ if ((active0 & 0x1400L) != 0L)
64+ return 2;
65+ if ((active0 & 0x6000L) != 0L)
66+ {
67+ jjmatchedKind = 16;
68+ jjmatchedPos = 3;
69+ return 2;
70+ }
71+ return -1;
72+ case 4:
73+ if ((active0 & 0x2000L) != 0L)
74+ return 2;
75+ if ((active0 & 0x4000L) != 0L)
76+ {
77+ jjmatchedKind = 16;
78+ jjmatchedPos = 4;
79+ return 2;
80+ }
81+ return -1;
82+ default :
83+ return -1;
84+ }
85+}
86+private final int jjStartNfa_0(int pos, long active0)
87+{
88+ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
89+}
90+private int jjStopAtPos(int pos, int kind)
91+{
92+ jjmatchedKind = kind;
93+ jjmatchedPos = pos;
94+ return pos + 1;
95+}
96+private int jjStartNfaWithStates_0(int pos, int kind, int state)
97+{
98+ jjmatchedKind = kind;
99+ jjmatchedPos = pos;
100+ try { curChar = input_stream.readChar(); }
101+ catch(java.io.IOException e) { return pos + 1; }
102+ return jjMoveNfa_0(state, pos + 1);
103+}
104+private int jjMoveStringLiteralDfa0_0()
105+{
106+ switch(curChar)
107+ {
108+ case 33:
109+ return jjMoveStringLiteralDfa1_0(0x40000000L);
110+ case 40:
111+ return jjStopAtPos(0, 26);
112+ case 41:
113+ return jjStopAtPos(0, 27);
114+ case 42:
115+ return jjStopAtPos(0, 37);
116+ case 43:
117+ return jjStopAtPos(0, 35);
118+ case 44:
119+ return jjStopAtPos(0, 23);
120+ case 45:
121+ return jjStopAtPos(0, 36);
122+ case 47:
123+ jjmatchedKind = 38;
124+ return jjMoveStringLiteralDfa1_0(0x4L);
125+ case 59:
126+ return jjStopAtPos(0, 20);
127+ case 60:
128+ jjmatchedKind = 33;
129+ return jjMoveStringLiteralDfa1_0(0x400000000L);
130+ case 61:
131+ jjmatchedKind = 28;
132+ return jjMoveStringLiteralDfa1_0(0x20000000L);
133+ case 62:
134+ jjmatchedKind = 31;
135+ return jjMoveStringLiteralDfa1_0(0x100000000L);
136+ case 91:
137+ return jjStopAtPos(0, 24);
138+ case 93:
139+ return jjStopAtPos(0, 25);
140+ case 101:
141+ return jjMoveStringLiteralDfa1_0(0x1000L);
142+ case 102:
143+ return jjMoveStringLiteralDfa1_0(0x8000L);
144+ case 105:
145+ return jjMoveStringLiteralDfa1_0(0xbe0L);
146+ case 114:
147+ return jjMoveStringLiteralDfa1_0(0x4000L);
148+ case 118:
149+ return jjMoveStringLiteralDfa1_0(0x400L);
150+ case 119:
151+ return jjMoveStringLiteralDfa1_0(0x2000L);
152+ case 123:
153+ return jjStopAtPos(0, 21);
154+ case 125:
155+ return jjStopAtPos(0, 22);
156+ default :
157+ return jjMoveNfa_0(0, 0);
158+ }
159+}
160+private int jjMoveStringLiteralDfa1_0(long active0)
161+{
162+ try { curChar = input_stream.readChar(); }
163+ catch(java.io.IOException e) {
164+ jjStopStringLiteralDfa_0(0, active0);
165+ return 1;
166+ }
167+ switch(curChar)
168+ {
169+ case 42:
170+ if ((active0 & 0x4L) != 0L)
171+ return jjStopAtPos(1, 2);
172+ break;
173+ case 48:
174+ return jjMoveStringLiteralDfa2_0(active0, 0x20L);
175+ case 49:
176+ return jjMoveStringLiteralDfa2_0(active0, 0x40L);
177+ case 51:
178+ return jjMoveStringLiteralDfa2_0(active0, 0x80L);
179+ case 54:
180+ return jjMoveStringLiteralDfa2_0(active0, 0x100L);
181+ case 61:
182+ if ((active0 & 0x20000000L) != 0L)
183+ return jjStopAtPos(1, 29);
184+ else if ((active0 & 0x40000000L) != 0L)
185+ return jjStopAtPos(1, 30);
186+ else if ((active0 & 0x100000000L) != 0L)
187+ return jjStopAtPos(1, 32);
188+ else if ((active0 & 0x400000000L) != 0L)
189+ return jjStopAtPos(1, 34);
190+ break;
191+ case 101:
192+ return jjMoveStringLiteralDfa2_0(active0, 0x4000L);
193+ case 102:
194+ if ((active0 & 0x800L) != 0L)
195+ return jjStartNfaWithStates_0(1, 11, 2);
196+ break;
197+ case 104:
198+ return jjMoveStringLiteralDfa2_0(active0, 0x2000L);
199+ case 108:
200+ return jjMoveStringLiteralDfa2_0(active0, 0x1000L);
201+ case 110:
202+ return jjMoveStringLiteralDfa2_0(active0, 0x200L);
203+ case 111:
204+ return jjMoveStringLiteralDfa2_0(active0, 0x8400L);
205+ default :
206+ break;
207+ }
208+ return jjStartNfa_0(0, active0);
209+}
210+private int jjMoveStringLiteralDfa2_0(long old0, long active0)
211+{
212+ if (((active0 &= old0)) == 0L)
213+ return jjStartNfa_0(0, old0);
214+ try { curChar = input_stream.readChar(); }
215+ catch(java.io.IOException e) {
216+ jjStopStringLiteralDfa_0(1, active0);
217+ return 2;
218+ }
219+ switch(curChar)
220+ {
221+ case 50:
222+ if ((active0 & 0x80L) != 0L)
223+ return jjStartNfaWithStates_0(2, 7, 2);
224+ break;
225+ case 52:
226+ if ((active0 & 0x100L) != 0L)
227+ return jjStartNfaWithStates_0(2, 8, 2);
228+ break;
229+ case 54:
230+ if ((active0 & 0x40L) != 0L)
231+ return jjStartNfaWithStates_0(2, 6, 2);
232+ break;
233+ case 56:
234+ if ((active0 & 0x20L) != 0L)
235+ return jjStartNfaWithStates_0(2, 5, 2);
236+ break;
237+ case 105:
238+ return jjMoveStringLiteralDfa3_0(active0, 0x2400L);
239+ case 114:
240+ if ((active0 & 0x8000L) != 0L)
241+ return jjStartNfaWithStates_0(2, 15, 2);
242+ break;
243+ case 115:
244+ return jjMoveStringLiteralDfa3_0(active0, 0x1000L);
245+ case 116:
246+ if ((active0 & 0x200L) != 0L)
247+ return jjStartNfaWithStates_0(2, 9, 2);
248+ return jjMoveStringLiteralDfa3_0(active0, 0x4000L);
249+ default :
250+ break;
251+ }
252+ return jjStartNfa_0(1, active0);
253+}
254+private int jjMoveStringLiteralDfa3_0(long old0, long active0)
255+{
256+ if (((active0 &= old0)) == 0L)
257+ return jjStartNfa_0(1, old0);
258+ try { curChar = input_stream.readChar(); }
259+ catch(java.io.IOException e) {
260+ jjStopStringLiteralDfa_0(2, active0);
261+ return 3;
262+ }
263+ switch(curChar)
264+ {
265+ case 100:
266+ if ((active0 & 0x400L) != 0L)
267+ return jjStartNfaWithStates_0(3, 10, 2);
268+ break;
269+ case 101:
270+ if ((active0 & 0x1000L) != 0L)
271+ return jjStartNfaWithStates_0(3, 12, 2);
272+ break;
273+ case 108:
274+ return jjMoveStringLiteralDfa4_0(active0, 0x2000L);
275+ case 117:
276+ return jjMoveStringLiteralDfa4_0(active0, 0x4000L);
277+ default :
278+ break;
279+ }
280+ return jjStartNfa_0(2, active0);
281+}
282+private int jjMoveStringLiteralDfa4_0(long old0, long active0)
283+{
284+ if (((active0 &= old0)) == 0L)
285+ return jjStartNfa_0(2, old0);
286+ try { curChar = input_stream.readChar(); }
287+ catch(java.io.IOException e) {
288+ jjStopStringLiteralDfa_0(3, active0);
289+ return 4;
290+ }
291+ switch(curChar)
292+ {
293+ case 101:
294+ if ((active0 & 0x2000L) != 0L)
295+ return jjStartNfaWithStates_0(4, 13, 2);
296+ break;
297+ case 114:
298+ return jjMoveStringLiteralDfa5_0(active0, 0x4000L);
299+ default :
300+ break;
301+ }
302+ return jjStartNfa_0(3, active0);
303+}
304+private int jjMoveStringLiteralDfa5_0(long old0, long active0)
305+{
306+ if (((active0 &= old0)) == 0L)
307+ return jjStartNfa_0(3, old0);
308+ try { curChar = input_stream.readChar(); }
309+ catch(java.io.IOException e) {
310+ jjStopStringLiteralDfa_0(4, active0);
311+ return 5;
312+ }
313+ switch(curChar)
314+ {
315+ case 110:
316+ if ((active0 & 0x4000L) != 0L)
317+ return jjStartNfaWithStates_0(5, 14, 2);
318+ break;
319+ default :
320+ break;
321+ }
322+ return jjStartNfa_0(4, active0);
323+}
324+private int jjMoveNfa_0(int startState, int curPos)
325+{
326+ //int[] nextStates; // not used
327+ int startsAt = 0;
328+ jjnewStateCnt = 4;
329+ int i = 1;
330+ jjstateSet[0] = startState;
331+ //int j; // not used
332+ int kind = 0x7fffffff;
333+ for (;;)
334+ {
335+ if (++jjround == 0x7fffffff)
336+ ReInitRounds();
337+ if (curChar < 64)
338+ {
339+ long l = 1L << curChar;
340+ do
341+ {
342+ switch(jjstateSet[--i])
343+ {
344+ case 0:
345+ if ((0x3ff000000000000L & l) != 0L)
346+ {
347+ if (kind > 17)
348+ kind = 17;
349+ jjCheckNAdd(3);
350+ }
351+ else if ((0x100002600L & l) != 0L)
352+ {
353+ if (kind > 1)
354+ kind = 1;
355+ }
356+ break;
357+ case 2:
358+ if ((0x3ff000000000000L & l) == 0L)
359+ break;
360+ if (kind > 16)
361+ kind = 16;
362+ jjstateSet[jjnewStateCnt++] = 2;
363+ break;
364+ case 3:
365+ if ((0x3ff000000000000L & l) == 0L)
366+ break;
367+ if (kind > 17)
368+ kind = 17;
369+ jjCheckNAdd(3);
370+ break;
371+ default : break;
372+ }
373+ } while(i != startsAt);
374+ }
375+ else if (curChar < 128)
376+ {
377+ long l = 1L << (curChar & 077);
378+ do
379+ {
380+ switch(jjstateSet[--i])
381+ {
382+ case 0:
383+ case 2:
384+ if ((0x7fffffe07fffffeL & l) == 0L)
385+ break;
386+ if (kind > 16)
387+ kind = 16;
388+ jjCheckNAdd(2);
389+ break;
390+ default : break;
391+ }
392+ } while(i != startsAt);
393+ }
394+ else
395+ {
396+ int i2 = (curChar & 0xff) >> 6;
397+ long l2 = 1L << (curChar & 077);
398+ do
399+ {
400+ switch(jjstateSet[--i])
401+ {
402+ default : break;
403+ }
404+ } while(i != startsAt);
405+ }
406+ if (kind != 0x7fffffff)
407+ {
408+ jjmatchedKind = kind;
409+ jjmatchedPos = curPos;
410+ kind = 0x7fffffff;
411+ }
412+ ++curPos;
413+ if ((i = jjnewStateCnt) == (startsAt = 4 - (jjnewStateCnt = startsAt)))
414+ return curPos;
415+ try { curChar = input_stream.readChar(); }
416+ catch(java.io.IOException e) { return curPos; }
417+ }
418+}
419+private int jjMoveStringLiteralDfa0_1()
420+{
421+ switch(curChar)
422+ {
423+ case 42:
424+ return jjMoveStringLiteralDfa1_1(0x8L);
425+ default :
426+ return 1;
427+ }
428+}
429+private int jjMoveStringLiteralDfa1_1(long active0)
430+{
431+ try { curChar = input_stream.readChar(); }
432+ catch(java.io.IOException e) {
433+ return 1;
434+ }
435+ switch(curChar)
436+ {
437+ case 47:
438+ if ((active0 & 0x8L) != 0L)
439+ return jjStopAtPos(1, 3);
440+ break;
441+ default :
442+ return 2;
443+ }
444+ return 2;
445+}
446+static final int[] jjnextStates = {
447+};
448+
449+/** Token literal values. */
450+public static final String[] jjstrLiteralImages = {
451+"", null, null, null, null, "\151\60\70", "\151\61\66", "\151\63\62",
452+"\151\66\64", "\151\156\164", "\166\157\151\144", "\151\146", "\145\154\163\145",
453+"\167\150\151\154\145", "\162\145\164\165\162\156", "\146\157\162", null, null, null, null, "\73",
454+"\173", "\175", "\54", "\133", "\135", "\50", "\51", "\75", "\75\75", "\41\75", "\76",
455+"\76\75", "\74", "\74\75", "\53", "\55", "\52", "\57", };
456+
457+/** Lexer state names. */
458+public static final String[] lexStateNames = {
459+ "DEFAULT",
460+ "WithinComment",
461+};
462+
463+/** Lex State array. */
464+public static final int[] jjnewLexState = {
465+ -1, -1, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
466+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
467+};
468+static final long[] jjtoToken = {
469+ 0x7ffff3ffe1L,
470+};
471+static final long[] jjtoSkip = {
472+ 0xeL,
473+};
474+static final long[] jjtoMore = {
475+ 0x10L,
476+};
477+protected SimpleCharStream input_stream;
478+private final int[] jjrounds = new int[4];
479+private final int[] jjstateSet = new int[8];
480+protected char curChar;
481+/** Constructor. */
482+public JostarParserTokenManager(SimpleCharStream stream){
483+ if (SimpleCharStream.staticFlag)
484+ throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
485+ input_stream = stream;
486+}
487+
488+/** Constructor. */
489+public JostarParserTokenManager(SimpleCharStream stream, int lexState){
490+ this(stream);
491+ SwitchTo(lexState);
492+}
493+
494+/** Reinitialise parser. */
495+public void ReInit(SimpleCharStream stream)
496+{
497+ jjmatchedPos = jjnewStateCnt = 0;
498+ curLexState = defaultLexState;
499+ input_stream = stream;
500+ ReInitRounds();
501+}
502+private void ReInitRounds()
503+{
504+ int i;
505+ jjround = 0x80000001;
506+ for (i = 4; i-- > 0;)
507+ jjrounds[i] = 0x80000000;
508+}
509+
510+/** Reinitialise parser. */
511+public void ReInit(SimpleCharStream stream, int lexState)
512+{
513+ ReInit(stream);
514+ SwitchTo(lexState);
515+}
516+
517+/** Switch to specified lex state. */
518+public void SwitchTo(int lexState)
519+{
520+ if (lexState >= 2 || lexState < 0)
521+ throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
522+ else
523+ curLexState = lexState;
524+}
525+
526+protected Token jjFillToken()
527+{
528+ final Token t;
529+ final String tokenImage;
530+ final int beginLine;
531+ final int endLine;
532+ final int beginColumn;
533+ final int endColumn;
534+ String im = jjstrLiteralImages[jjmatchedKind];
535+ tokenImage = (im == null) ? input_stream.GetImage() : im;
536+ beginLine = input_stream.getBeginLine();
537+ beginColumn = input_stream.getBeginColumn();
538+ endLine = input_stream.getEndLine();
539+ endColumn = input_stream.getEndColumn();
540+ t = Token.newToken(jjmatchedKind, tokenImage);
541+
542+ t.beginLine = beginLine;
543+ t.endLine = endLine;
544+ t.beginColumn = beginColumn;
545+ t.endColumn = endColumn;
546+
547+ return t;
548+}
549+
550+int curLexState = 0;
551+int defaultLexState = 0;
552+int jjnewStateCnt;
553+int jjround;
554+int jjmatchedPos;
555+int jjmatchedKind;
556+
557+/** Get the next Token. */
558+public Token getNextToken()
559+{
560+ //int kind;
561+ Token specialToken = null;
562+ Token matchedToken;
563+ int curPos = 0;
564+
565+ EOFLoop :
566+ for (;;)
567+ {
568+ try
569+ {
570+ curChar = input_stream.BeginToken();
571+ }
572+ catch(java.io.IOException e)
573+ {
574+ jjmatchedKind = 0;
575+ matchedToken = jjFillToken();
576+ return matchedToken;
577+ }
578+
579+ for (;;)
580+ {
581+ switch(curLexState)
582+ {
583+ case 0:
584+ jjmatchedKind = 0x7fffffff;
585+ jjmatchedPos = 0;
586+ curPos = jjMoveStringLiteralDfa0_0();
587+ break;
588+ case 1:
589+ jjmatchedKind = 0x7fffffff;
590+ jjmatchedPos = 0;
591+ curPos = jjMoveStringLiteralDfa0_1();
592+ if (jjmatchedPos == 0 && jjmatchedKind > 4)
593+ {
594+ jjmatchedKind = 4;
595+ }
596+ break;
597+ }
598+ if (jjmatchedKind != 0x7fffffff)
599+ {
600+ if (jjmatchedPos + 1 < curPos)
601+ input_stream.backup(curPos - jjmatchedPos - 1);
602+ if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
603+ {
604+ matchedToken = jjFillToken();
605+ if (jjnewLexState[jjmatchedKind] != -1)
606+ curLexState = jjnewLexState[jjmatchedKind];
607+ return matchedToken;
608+ }
609+ else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
610+ {
611+ if (jjnewLexState[jjmatchedKind] != -1)
612+ curLexState = jjnewLexState[jjmatchedKind];
613+ continue EOFLoop;
614+ }
615+ if (jjnewLexState[jjmatchedKind] != -1)
616+ curLexState = jjnewLexState[jjmatchedKind];
617+ curPos = 0;
618+ jjmatchedKind = 0x7fffffff;
619+ try {
620+ curChar = input_stream.readChar();
621+ continue;
622+ }
623+ catch (java.io.IOException e1) { }
624+ }
625+ int error_line = input_stream.getEndLine();
626+ int error_column = input_stream.getEndColumn();
627+ String error_after = null;
628+ boolean EOFSeen = false;
629+ try { input_stream.readChar(); input_stream.backup(1); }
630+ catch (java.io.IOException e1) {
631+ EOFSeen = true;
632+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
633+ if (curChar == '\n' || curChar == '\r') {
634+ error_line++;
635+ error_column = 0;
636+ }
637+ else
638+ error_column++;
639+ }
640+ if (!EOFSeen) {
641+ input_stream.backup(1);
642+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
643+ }
644+ throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
645+ }
646+ }
647+}
648+
649+private void jjCheckNAdd(int state)
650+{
651+ if (jjrounds[state] != jjround)
652+ {
653+ jjstateSet[jjnewStateCnt++] = state;
654+ jjrounds[state] = jjround;
655+ }
656+}
657+private void jjAddStates(int start, int end)
658+{
659+ do {
660+ jjstateSet[jjnewStateCnt++] = jjnextStates[start];
661+ } while (start++ != end);
662+}
663+private void jjCheckNAddTwoStates(int state1, int state2)
664+{
665+ jjCheckNAdd(state1);
666+ jjCheckNAdd(state2);
667+}
668+
669+private void jjCheckNAddStates(int start, int end)
670+{
671+ do {
672+ jjCheckNAdd(jjnextStates[start]);
673+ } while (start++ != end);
674+}
675+
676+}
--- a/Makefile
+++ b/Makefile
@@ -17,12 +17,11 @@ all : bin/jostar.exe
1717 lex.yy.cc: lex.l
1818 $(LEX) -+ $^
1919
20-
2120 bin/jostar.exe: test.c
22- java -cp "$(MAKEFILE_DIR)/coins/classes" coins.driver.Driver -o $@ -coins:target=x86_64,assembler=as test.c
21+ java -cp "$(MAKEFILE_DIR)/coins/classes" coins.driver.Driver -o $@ -coins:target=x86_64,assembler=as $^
2322
24-bin/jostar.exe: c0.jj
25- java -cp "$(MAKEFILE_DIR)/bin/javacc/javacc.jar" javacc c0.jj
23+Token.java: lex.jj
24+ java -cp "$(MAKEFILE_DIR)/bin/javacc/javacc.jar" javacc $^
2625
2726 $(OBJECTDIR)lex.o: lex.yy.cc FlexLexer.h
2827 $(CC) $(LLVM) lex.yy.cc -c -o $@
--- /dev/null
+++ b/ParseException.java
@@ -0,0 +1,198 @@
1+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
2+/* JavaCCOptions:KEEP_LINE_COL=null */
3+package c0front;
4+
5+/**
6+ * This exception is thrown when parse errors are encountered.
7+ * You can explicitly create objects of this exception type by
8+ * calling the method generateParseException in the generated
9+ * parser.
10+ *
11+ * You can modify this class to customize your error reporting
12+ * mechanisms so long as you retain the public fields.
13+ */
14+public class ParseException extends Exception {
15+
16+ /**
17+ * This constructor is used by the method "generateParseException"
18+ * in the generated parser. Calling this constructor generates
19+ * a new object of this type with the fields "currentToken",
20+ * "expectedTokenSequences", and "tokenImage" set. The boolean
21+ * flag "specialConstructor" is also set to true to indicate that
22+ * this constructor was used to create this object.
23+ * This constructor calls its super class with the empty string
24+ * to force the "toString" method of parent class "Throwable" to
25+ * print the error message in the form:
26+ * ParseException: <result of getMessage>
27+ */
28+ public ParseException(Token currentTokenVal,
29+ int[][] expectedTokenSequencesVal,
30+ String[] tokenImageVal
31+ )
32+ {
33+ super("");
34+ specialConstructor = true;
35+ currentToken = currentTokenVal;
36+ expectedTokenSequences = expectedTokenSequencesVal;
37+ tokenImage = tokenImageVal;
38+ }
39+
40+ /**
41+ * The following constructors are for use by you for whatever
42+ * purpose you can think of. Constructing the exception in this
43+ * manner makes the exception behave in the normal way - i.e., as
44+ * documented in the class "Throwable". The fields "errorToken",
45+ * "expectedTokenSequences", and "tokenImage" do not contain
46+ * relevant information. The JavaCC generated code does not use
47+ * these constructors.
48+ */
49+
50+ public ParseException() {
51+ super();
52+ specialConstructor = false;
53+ }
54+
55+ /** Constructor with message. */
56+ public ParseException(String message) {
57+ super(message);
58+ specialConstructor = false;
59+ }
60+
61+ /**
62+ * This variable determines which constructor was used to create
63+ * this object and thereby affects the semantics of the
64+ * "getMessage" method (see below).
65+ */
66+ protected boolean specialConstructor;
67+
68+ /**
69+ * This is the last token that has been consumed successfully. If
70+ * this object has been created due to a parse error, the token
71+ * followng this token will (therefore) be the first error token.
72+ */
73+ public Token currentToken;
74+
75+ /**
76+ * Each entry in this array is an array of integers. Each array
77+ * of integers represents a sequence of tokens (by their ordinal
78+ * values) that is expected at this point of the parse.
79+ */
80+ public int[][] expectedTokenSequences;
81+
82+ /**
83+ * This is a reference to the "tokenImage" array of the generated
84+ * parser within which the parse error occurred. This array is
85+ * defined in the generated ...Constants interface.
86+ */
87+ public String[] tokenImage;
88+
89+ /**
90+ * This method has the standard behavior when this object has been
91+ * created using the standard constructors. Otherwise, it uses
92+ * "currentToken" and "expectedTokenSequences" to generate a parse
93+ * error message and returns it. If this object has been created
94+ * due to a parse error, and you do not catch it (it gets thrown
95+ * from the parser), then this method is called during the printing
96+ * of the final stack trace, and hence the correct error message
97+ * gets displayed.
98+ */
99+ public String getMessage() {
100+ if (!specialConstructor) {
101+ return super.getMessage();
102+ }
103+ StringBuffer expected = new StringBuffer();
104+ int maxSize = 0;
105+ for (int i = 0; i < expectedTokenSequences.length; i++) {
106+ if (maxSize < expectedTokenSequences[i].length) {
107+ maxSize = expectedTokenSequences[i].length;
108+ }
109+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
110+ expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
111+ }
112+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
113+ expected.append("...");
114+ }
115+ expected.append(eol).append(" ");
116+ }
117+ String retval = "Encountered \"";
118+ Token tok = currentToken.next;
119+ for (int i = 0; i < maxSize; i++) {
120+ if (i != 0) retval += " ";
121+ if (tok.kind == 0) {
122+ retval += tokenImage[0];
123+ break;
124+ }
125+ retval += " " + tokenImage[tok.kind];
126+ retval += " \"";
127+ retval += add_escapes(tok.image);
128+ retval += " \"";
129+ tok = tok.next;
130+ }
131+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
132+ retval += "." + eol;
133+ if (expectedTokenSequences.length == 1) {
134+ retval += "Was expecting:" + eol + " ";
135+ } else {
136+ retval += "Was expecting one of:" + eol + " ";
137+ }
138+ retval += expected.toString();
139+ return retval;
140+ }
141+
142+ /**
143+ * The end of line string for this machine.
144+ */
145+ protected String eol = System.getProperty("line.separator", "\n");
146+
147+ /**
148+ * Used to convert raw characters to their escaped version
149+ * when these raw version cannot be used as part of an ASCII
150+ * string literal.
151+ */
152+ protected String add_escapes(String str) {
153+ StringBuffer retval = new StringBuffer();
154+ char ch;
155+ for (int i = 0; i < str.length(); i++) {
156+ switch (str.charAt(i))
157+ {
158+ case 0 :
159+ continue;
160+ case '\b':
161+ retval.append("\\b");
162+ continue;
163+ case '\t':
164+ retval.append("\\t");
165+ continue;
166+ case '\n':
167+ retval.append("\\n");
168+ continue;
169+ case '\f':
170+ retval.append("\\f");
171+ continue;
172+ case '\r':
173+ retval.append("\\r");
174+ continue;
175+ case '\"':
176+ retval.append("\\\"");
177+ continue;
178+ case '\'':
179+ retval.append("\\\'");
180+ continue;
181+ case '\\':
182+ retval.append("\\\\");
183+ continue;
184+ default:
185+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
186+ String s = "0000" + Integer.toString(ch, 16);
187+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
188+ } else {
189+ retval.append(ch);
190+ }
191+ continue;
192+ }
193+ }
194+ return retval.toString();
195+ }
196+
197+}
198+/* JavaCC - OriginalChecksum=883964498d95448a8bf0dfbf88846feb (do not edit this line) */
--- /dev/null
+++ b/SimpleCharStream.java
@@ -0,0 +1,472 @@
1+/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.1 */
2+/* JavaCCOptions:STATIC=false */
3+package c0front;
4+
5+/**
6+ * An implementation of interface CharStream, where the stream is assumed to
7+ * contain only ASCII characters (without unicode processing).
8+ */
9+
10+public class SimpleCharStream
11+{
12+/** Whether parser is static. */
13+ public static final boolean staticFlag = false;
14+ int bufsize;
15+ int available;
16+ int tokenBegin;
17+/** Position in buffer. */
18+ public int bufpos = -1;
19+ protected int bufline[];
20+ protected int bufcolumn[];
21+
22+ protected int column = 0;
23+ protected int line = 1;
24+
25+ protected boolean prevCharIsCR = false;
26+ protected boolean prevCharIsLF = false;
27+
28+ protected java.io.Reader inputStream;
29+
30+ protected char[] buffer;
31+ protected int maxNextCharInd = 0;
32+ protected int inBuf = 0;
33+ protected int tabSize = 8;
34+
35+ protected void setTabSize(int i) { tabSize = i; }
36+ protected int getTabSize(int i) { return tabSize; }
37+
38+
39+ protected void ExpandBuff(boolean wrapAround)
40+ {
41+ char[] newbuffer = new char[bufsize + 2048];
42+ int newbufline[] = new int[bufsize + 2048];
43+ int newbufcolumn[] = new int[bufsize + 2048];
44+
45+ try
46+ {
47+ if (wrapAround)
48+ {
49+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
50+ System.arraycopy(buffer, 0, newbuffer,
51+ bufsize - tokenBegin, bufpos);
52+ buffer = newbuffer;
53+
54+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
55+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
56+ bufline = newbufline;
57+
58+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
59+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
60+ bufcolumn = newbufcolumn;
61+
62+ maxNextCharInd = (bufpos += (bufsize - tokenBegin));
63+ }
64+ else
65+ {
66+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
67+ buffer = newbuffer;
68+
69+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
70+ bufline = newbufline;
71+
72+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
73+ bufcolumn = newbufcolumn;
74+
75+ maxNextCharInd = (bufpos -= tokenBegin);
76+ }
77+ }
78+ catch (Throwable t)
79+ {
80+ throw new Error(t.getMessage());
81+ }
82+
83+
84+ bufsize += 2048;
85+ available = bufsize;
86+ tokenBegin = 0;
87+ }
88+
89+ protected void FillBuff() throws java.io.IOException
90+ {
91+ if (maxNextCharInd == available)
92+ {
93+ if (available == bufsize)
94+ {
95+ if (tokenBegin > 2048)
96+ {
97+ bufpos = maxNextCharInd = 0;
98+ available = tokenBegin;
99+ }
100+ else if (tokenBegin < 0)
101+ bufpos = maxNextCharInd = 0;
102+ else
103+ ExpandBuff(false);
104+ }
105+ else if (available > tokenBegin)
106+ available = bufsize;
107+ else if ((tokenBegin - available) < 2048)
108+ ExpandBuff(true);
109+ else
110+ available = tokenBegin;
111+ }
112+
113+ int i;
114+ try {
115+ if ((i = inputStream.read(buffer, maxNextCharInd,
116+ available - maxNextCharInd)) == -1)
117+ {
118+ inputStream.close();
119+ throw new java.io.IOException();
120+ }
121+ else
122+ maxNextCharInd += i;
123+ return;
124+ }
125+ catch(java.io.IOException e) {
126+ --bufpos;
127+ backup(0);
128+ if (tokenBegin == -1)
129+ tokenBegin = bufpos;
130+ throw e;
131+ }
132+ }
133+
134+/** Start. */
135+ public char BeginToken() throws java.io.IOException
136+ {
137+ tokenBegin = -1;
138+ char c = readChar();
139+ tokenBegin = bufpos;
140+
141+ return c;
142+ }
143+
144+ protected void UpdateLineColumn(char c)
145+ {
146+ column++;
147+
148+ if (prevCharIsLF)
149+ {
150+ prevCharIsLF = false;
151+ line += (column = 1);
152+ }
153+ else if (prevCharIsCR)
154+ {
155+ prevCharIsCR = false;
156+ if (c == '\n')
157+ {
158+ prevCharIsLF = true;
159+ }
160+ else
161+ line += (column = 1);
162+ }
163+
164+ switch (c)
165+ {
166+ case '\r' :
167+ prevCharIsCR = true;
168+ break;
169+ case '\n' :
170+ prevCharIsLF = true;
171+ break;
172+ case '\t' :
173+ column--;
174+ column += (tabSize - (column % tabSize));
175+ break;
176+ default :
177+ break;
178+ }
179+
180+ bufline[bufpos] = line;
181+ bufcolumn[bufpos] = column;
182+ }
183+
184+/** Read a character. */
185+ public char readChar() throws java.io.IOException
186+ {
187+ if (inBuf > 0)
188+ {
189+ --inBuf;
190+
191+ if (++bufpos == bufsize)
192+ bufpos = 0;
193+
194+ return buffer[bufpos];
195+ }
196+
197+ if (++bufpos >= maxNextCharInd)
198+ FillBuff();
199+
200+ char c = buffer[bufpos];
201+
202+ UpdateLineColumn(c);
203+ return c;
204+ }
205+
206+ /**
207+ * @deprecated
208+ * @see #getEndColumn
209+ */
210+
211+ public int getColumn() {
212+ return bufcolumn[bufpos];
213+ }
214+
215+ /**
216+ * @deprecated
217+ * @see #getEndLine
218+ */
219+
220+ public int getLine() {
221+ return bufline[bufpos];
222+ }
223+
224+ /** Get token end column number. */
225+ public int getEndColumn() {
226+ return bufcolumn[bufpos];
227+ }
228+
229+ /** Get token end line number. */
230+ public int getEndLine() {
231+ return bufline[bufpos];
232+ }
233+
234+ /** Get token beginning column number. */
235+ public int getBeginColumn() {
236+ return bufcolumn[tokenBegin];
237+ }
238+
239+ /** Get token beginning line number. */
240+ public int getBeginLine() {
241+ return bufline[tokenBegin];
242+ }
243+
244+/** Backup a number of characters. */
245+ public void backup(int amount) {
246+
247+ inBuf += amount;
248+ if ((bufpos -= amount) < 0)
249+ bufpos += bufsize;
250+ }
251+
252+ /** Constructor. */
253+ public SimpleCharStream(java.io.Reader dstream, int startline,
254+ int startcolumn, int buffersize)
255+ {
256+ inputStream = dstream;
257+ line = startline;
258+ column = startcolumn - 1;
259+
260+ available = bufsize = buffersize;
261+ buffer = new char[buffersize];
262+ bufline = new int[buffersize];
263+ bufcolumn = new int[buffersize];
264+ }
265+
266+ /** Constructor. */
267+ public SimpleCharStream(java.io.Reader dstream, int startline,
268+ int startcolumn)
269+ {
270+ this(dstream, startline, startcolumn, 4096);
271+ }
272+
273+ /** Constructor. */
274+ public SimpleCharStream(java.io.Reader dstream)
275+ {
276+ this(dstream, 1, 1, 4096);
277+ }
278+
279+ /** Reinitialise. */
280+ public void ReInit(java.io.Reader dstream, int startline,
281+ int startcolumn, int buffersize)
282+ {
283+ inputStream = dstream;
284+ line = startline;
285+ column = startcolumn - 1;
286+
287+ if (buffer == null || buffersize != buffer.length)
288+ {
289+ available = bufsize = buffersize;
290+ buffer = new char[buffersize];
291+ bufline = new int[buffersize];
292+ bufcolumn = new int[buffersize];
293+ }
294+ prevCharIsLF = prevCharIsCR = false;
295+ tokenBegin = inBuf = maxNextCharInd = 0;
296+ bufpos = -1;
297+ }
298+
299+ /** Reinitialise. */
300+ public void ReInit(java.io.Reader dstream, int startline,
301+ int startcolumn)
302+ {
303+ ReInit(dstream, startline, startcolumn, 4096);
304+ }
305+
306+ /** Reinitialise. */
307+ public void ReInit(java.io.Reader dstream)
308+ {
309+ ReInit(dstream, 1, 1, 4096);
310+ }
311+ /** Constructor. */
312+ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
313+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
314+ {
315+ this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
316+ }
317+
318+ /** Constructor. */
319+ public SimpleCharStream(java.io.InputStream dstream, int startline,
320+ int startcolumn, int buffersize)
321+ {
322+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
323+ }
324+
325+ /** Constructor. */
326+ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
327+ int startcolumn) throws java.io.UnsupportedEncodingException
328+ {
329+ this(dstream, encoding, startline, startcolumn, 4096);
330+ }
331+
332+ /** Constructor. */
333+ public SimpleCharStream(java.io.InputStream dstream, int startline,
334+ int startcolumn)
335+ {
336+ this(dstream, startline, startcolumn, 4096);
337+ }
338+
339+ /** Constructor. */
340+ public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
341+ {
342+ this(dstream, encoding, 1, 1, 4096);
343+ }
344+
345+ /** Constructor. */
346+ public SimpleCharStream(java.io.InputStream dstream)
347+ {
348+ this(dstream, 1, 1, 4096);
349+ }
350+
351+ /** Reinitialise. */
352+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
353+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
354+ {
355+ ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
356+ }
357+
358+ /** Reinitialise. */
359+ public void ReInit(java.io.InputStream dstream, int startline,
360+ int startcolumn, int buffersize)
361+ {
362+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
363+ }
364+
365+ /** Reinitialise. */
366+ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
367+ {
368+ ReInit(dstream, encoding, 1, 1, 4096);
369+ }
370+
371+ /** Reinitialise. */
372+ public void ReInit(java.io.InputStream dstream)
373+ {
374+ ReInit(dstream, 1, 1, 4096);
375+ }
376+ /** Reinitialise. */
377+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
378+ int startcolumn) throws java.io.UnsupportedEncodingException
379+ {
380+ ReInit(dstream, encoding, startline, startcolumn, 4096);
381+ }
382+ /** Reinitialise. */
383+ public void ReInit(java.io.InputStream dstream, int startline,
384+ int startcolumn)
385+ {
386+ ReInit(dstream, startline, startcolumn, 4096);
387+ }
388+ /** Get token literal value. */
389+ public String GetImage()
390+ {
391+ if (bufpos >= tokenBegin)
392+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
393+ else
394+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
395+ new String(buffer, 0, bufpos + 1);
396+ }
397+
398+ /** Get the suffix. */
399+ public char[] GetSuffix(int len)
400+ {
401+ char[] ret = new char[len];
402+
403+ if ((bufpos + 1) >= len)
404+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
405+ else
406+ {
407+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
408+ len - bufpos - 1);
409+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
410+ }
411+
412+ return ret;
413+ }
414+
415+ /** Reset buffer when finished. */
416+ public void Done()
417+ {
418+ buffer = null;
419+ bufline = null;
420+ bufcolumn = null;
421+ }
422+
423+ /**
424+ * Method to adjust line and column numbers for the start of a token.
425+ */
426+ public void adjustBeginLineColumn(int newLine, int newCol)
427+ {
428+ int start = tokenBegin;
429+ int len;
430+
431+ if (bufpos >= tokenBegin)
432+ {
433+ len = bufpos - tokenBegin + inBuf + 1;
434+ }
435+ else
436+ {
437+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
438+ }
439+
440+ int i = 0, j = 0, k = 0;
441+ int nextColDiff = 0, columnDiff = 0;
442+
443+ while (i < len &&
444+ bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
445+ {
446+ bufline[j] = newLine;
447+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
448+ bufcolumn[j] = newCol + columnDiff;
449+ columnDiff = nextColDiff;
450+ i++;
451+ }
452+
453+ if (i < len)
454+ {
455+ bufline[j] = newLine++;
456+ bufcolumn[j] = newCol + columnDiff;
457+
458+ while (i++ < len)
459+ {
460+ if (bufline[j = start % bufsize] != bufline[++start % bufsize])
461+ bufline[j] = newLine++;
462+ else
463+ bufline[j] = newLine;
464+ }
465+ }
466+
467+ line = bufline[j];
468+ column = bufcolumn[j];
469+ }
470+
471+}
472+/* JavaCC - OriginalChecksum=8b14ac1406dc9cadaaaaa74f6bb5ffeb (do not edit this line) */
--- /dev/null
+++ b/Token.java
@@ -0,0 +1,124 @@
1+/* Generated By:JavaCC: Do not edit this line. Token.java Version 4.1 */
2+/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null */
3+package c0front;
4+
5+/**
6+ * Describes the input token stream.
7+ */
8+
9+public class Token {
10+
11+ /**
12+ * An integer that describes the kind of this token. This numbering
13+ * system is determined by JavaCCParser, and a table of these numbers is
14+ * stored in the file ...Constants.java.
15+ */
16+ public int kind;
17+
18+ /** The line number of the first character of this Token. */
19+ public int beginLine;
20+ /** The column number of the first character of this Token. */
21+ public int beginColumn;
22+ /** The line number of the last character of this Token. */
23+ public int endLine;
24+ /** The column number of the last character of this Token. */
25+ public int endColumn;
26+
27+ /**
28+ * The string image of the token.
29+ */
30+ public String image;
31+
32+ /**
33+ * A reference to the next regular (non-special) token from the input
34+ * stream. If this is the last token from the input stream, or if the
35+ * token manager has not read tokens beyond this one, this field is
36+ * set to null. This is true only if this token is also a regular
37+ * token. Otherwise, see below for a description of the contents of
38+ * this field.
39+ */
40+ public Token next;
41+
42+ /**
43+ * This field is used to access special tokens that occur prior to this
44+ * token, but after the immediately preceding regular (non-special) token.
45+ * If there are no such special tokens, this field is set to null.
46+ * When there are more than one such special token, this field refers
47+ * to the last of these special tokens, which in turn refers to the next
48+ * previous special token through its specialToken field, and so on
49+ * until the first special token (whose specialToken field is null).
50+ * The next fields of special tokens refer to other special tokens that
51+ * immediately follow it (without an intervening regular token). If there
52+ * is no such token, this field is null.
53+ */
54+ public Token specialToken;
55+
56+ /**
57+ * An optional attribute value of the Token.
58+ * Tokens which are not used as syntactic sugar will often contain
59+ * meaningful values that will be used later on by the compiler or
60+ * interpreter. This attribute value is often different from the image.
61+ * Any subclass of Token that actually wants to return a non-null value can
62+ * override this method as appropriate.
63+ */
64+ public Object getValue() {
65+ return null;
66+ }
67+
68+ /**
69+ * No-argument contructor
70+ */
71+ public Token() {}
72+
73+ /**
74+ * Constructs a new token for the specified Image.
75+ */
76+ public Token(int kind)
77+ {
78+ this(kind, null);
79+ }
80+
81+ /**
82+ * Constructs a new token for the specified Image and Kind.
83+ */
84+ public Token(int kind, String image)
85+ {
86+ this.kind = kind;
87+ this.image = image;
88+ }
89+
90+ /**
91+ * Returns the image.
92+ */
93+ public String toString()
94+ {
95+ return image;
96+ }
97+
98+ /**
99+ * Returns a new Token object, by default. However, if you want, you
100+ * can create and return subclass objects based on the value of ofKind.
101+ * Simply add the cases to the switch for all those special cases.
102+ * For example, if you have a subclass of Token called IDToken that
103+ * you want to create if ofKind is ID, simply add something like :
104+ *
105+ * case MyParserConstants.ID : return new IDToken(ofKind, image);
106+ *
107+ * to the following switch statement. Then you can cast matchedToken
108+ * variable to the appropriate type and use sit in your lexical actions.
109+ */
110+ public static Token newToken(int ofKind, String image)
111+ {
112+ switch(ofKind)
113+ {
114+ default : return new Token(ofKind, image);
115+ }
116+ }
117+
118+ public static Token newToken(int ofKind)
119+ {
120+ return newToken(ofKind, null);
121+ }
122+
123+}
124+/* JavaCC - OriginalChecksum=d9bd67d65acf7ea1169091c92534b203 (do not edit this line) */
--- /dev/null
+++ b/TokenMgrError.java
@@ -0,0 +1,140 @@
1+/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */
2+/* JavaCCOptions: */
3+package c0front;
4+
5+/** Token Manager Error. */
6+public class TokenMgrError extends Error
7+{
8+
9+ /*
10+ * Ordinals for various reasons why an Error of this type can be thrown.
11+ */
12+
13+ /**
14+ * Lexical error occurred.
15+ */
16+ static final int LEXICAL_ERROR = 0;
17+
18+ /**
19+ * An attempt was made to create a second instance of a static token manager.
20+ */
21+ static final int STATIC_LEXER_ERROR = 1;
22+
23+ /**
24+ * Tried to change to an invalid lexical state.
25+ */
26+ static final int INVALID_LEXICAL_STATE = 2;
27+
28+ /**
29+ * Detected (and bailed out of) an infinite loop in the token manager.
30+ */
31+ static final int LOOP_DETECTED = 3;
32+
33+ /**
34+ * Indicates the reason why the exception is thrown. It will have
35+ * one of the above 4 values.
36+ */
37+ int errorCode;
38+
39+ /**
40+ * Replaces unprintable characters by their escaped (or unicode escaped)
41+ * equivalents in the given string
42+ */
43+ protected static final String addEscapes(String str) {
44+ StringBuffer retval = new StringBuffer();
45+ char ch;
46+ for (int i = 0; i < str.length(); i++) {
47+ switch (str.charAt(i))
48+ {
49+ case 0 :
50+ continue;
51+ case '\b':
52+ retval.append("\\b");
53+ continue;
54+ case '\t':
55+ retval.append("\\t");
56+ continue;
57+ case '\n':
58+ retval.append("\\n");
59+ continue;
60+ case '\f':
61+ retval.append("\\f");
62+ continue;
63+ case '\r':
64+ retval.append("\\r");
65+ continue;
66+ case '\"':
67+ retval.append("\\\"");
68+ continue;
69+ case '\'':
70+ retval.append("\\\'");
71+ continue;
72+ case '\\':
73+ retval.append("\\\\");
74+ continue;
75+ default:
76+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
77+ String s = "0000" + Integer.toString(ch, 16);
78+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
79+ } else {
80+ retval.append(ch);
81+ }
82+ continue;
83+ }
84+ }
85+ return retval.toString();
86+ }
87+
88+ /**
89+ * Returns a detailed message for the Error when it is thrown by the
90+ * token manager to indicate a lexical error.
91+ * Parameters :
92+ * EOFSeen : indicates if EOF caused the lexical error
93+ * curLexState : lexical state in which this error occurred
94+ * errorLine : line number when the error occurred
95+ * errorColumn : column number when the error occurred
96+ * errorAfter : prefix that was seen before this error occurred
97+ * curchar : the offending character
98+ * Note: You can customize the lexical error message by modifying this method.
99+ */
100+ protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
101+ return("Lexical error at line " +
102+ errorLine + ", column " +
103+ errorColumn + ". Encountered: " +
104+ (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
105+ "after : \"" + addEscapes(errorAfter) + "\"");
106+ }
107+
108+ /**
109+ * You can also modify the body of this method to customize your error messages.
110+ * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
111+ * of end-users concern, so you can return something like :
112+ *
113+ * "Internal Error : Please file a bug report .... "
114+ *
115+ * from this method for such cases in the release version of your parser.
116+ */
117+ public String getMessage() {
118+ return super.getMessage();
119+ }
120+
121+ /*
122+ * Constructors of various flavors follow.
123+ */
124+
125+ /** No arg constructor. */
126+ public TokenMgrError() {
127+ }
128+
129+ /** Constructor with message and reason. */
130+ public TokenMgrError(String message, int reason) {
131+ super(message);
132+ errorCode = reason;
133+ }
134+
135+ /** Full Constructor. */
136+ public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
137+ this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
138+ }
139+}
140+/* JavaCC - OriginalChecksum=d8d7aa0d88202443ff2cfb68eb95cee4 (do not edit this line) */
--- a/lex.jj
+++ b/lex.jj
@@ -1,5 +1,6 @@
11 /*Apache License, Version 2.0
22
3+Copyright 2002-2009 coins開発グループ
34 Copyright 2023 dhrname
45
56 Apache License Version 2.0(「本ライセンス」)に基づいてライセンスされます。あなたがこのファイルを使用するためには、本ライセンスに従わなければなりません。本ライセンスのコピーは下記の場所から入手できます。
@@ -73,7 +74,11 @@ SKIP : {
7374 }
7475
7576 TOKEN : {
76- <INT: "int">
77+ <INTEGER8: "i08">
78+| <INTEGER16: "i16">
79+| <INTEGER32: "i32">
80+| <INTEGER64: "i64">
81+| <INT: "int">
7782 | <VOID: "void">
7883 | <IF: "if">
7984 | <ELSE: "else">