|
@@ -145,6 +145,39 @@ static bool tAddToken4(int c, Token tce, Token tc, Token te, Token t) {
|
|
|
return fReadIf(c) ? tAddToken2(tce, tc) : tAddToken2(te, t);
|
|
|
}
|
|
|
|
|
|
+static bool tLineComment() {
|
|
|
+ while(true) {
|
|
|
+ int c = fRead();
|
|
|
+ if(c == EOF || c == '\n') {
|
|
|
+ line++;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool tMultipleLineComment() {
|
|
|
+ while(true) {
|
|
|
+ int c = fRead();
|
|
|
+ if(c == EOF) {
|
|
|
+ tError("unclosed comment at line %d", line);
|
|
|
+ return false;
|
|
|
+ } else if(c == '\n') {
|
|
|
+ line++;
|
|
|
+ } else if(c == '*' && fReadIf('/')) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool tSlash() {
|
|
|
+ if(fReadIf('/')) {
|
|
|
+ return tLineComment();
|
|
|
+ } else if(fReadIf('*')) {
|
|
|
+ return tMultipleLineComment();
|
|
|
+ }
|
|
|
+ return tAddToken2(T_DIV_SET, T_DIV);
|
|
|
+}
|
|
|
+
|
|
|
static bool tParseToken() {
|
|
|
int c = fRead();
|
|
|
if(c == EOF) {
|
|
@@ -160,7 +193,7 @@ static bool tParseToken() {
|
|
|
case '+': return tAddToken3('+', T_INCREMENT, T_ADD_SET, T_ADD);
|
|
|
case '-': return tAddToken3('-', T_DECREMENT, T_SUB_SET, T_SUB);
|
|
|
case '*': return tAddToken2(T_MUL_SET, T_MUL);
|
|
|
- case '/': return tAddToken2(T_DIV_SET, T_DIV);
|
|
|
+ case '/': return tSlash();
|
|
|
case '%': return tAddToken2(T_MOD_SET, T_MOD);
|
|
|
case '<':
|
|
|
return tAddToken4('<', T_LEFT_SHIFT_SET, T_LEFT_SHIFT, T_LESS_EQUAL,
|