public void nextToken() { if (indiceToken == lexBuf.Count - 1) { if (codeToParse == string.Empty) { } lexCode(); } indiceToken++; if (indiceToken >= lexBuf.Count) { throw new Exception(); } currentToken = lexBuf.ElementAt(indiceToken); }
public void nextTokenIfEquals(Token.TokenValue value) { if (currentTokenEquals(value)) { nextToken(); } else { throw new SyntaxError(lineNumber, colNumber, value); } }
private static byte tokenPriority(Token.TokenValue tok) { switch (tok) { case Token.TokenValue.AND: return 9; case Token.TokenValue.OR: return 8; case Token.TokenValue.GT: case Token.TokenValue.LT: case Token.TokenValue.GEQ: case Token.TokenValue.LEQ: case Token.TokenValue.EQBOOL: return 7; case Token.TokenValue.NEG: return 6; case Token.TokenValue.PLUS: case Token.TokenValue.MINUS: return 4; case Token.TokenValue.TIMES: case Token.TokenValue.DIV: return 3; default: return 0; } }
public void previousToken() { indiceToken--; if (indiceToken < 0) { throw new Exception(); } currentToken = lexBuf.ElementAt(indiceToken); }
public bool isAnAssignOperator(Token.TokenValue op) { switch (op) { case Token.TokenValue.EQ: case Token.TokenValue.PLUSEQ: case Token.TokenValue.MINUSEQ: case Token.TokenValue.TIMESEQ: case Token.TokenValue.DIVEQ: case Token.TokenValue.PLUSPLUS: case Token.TokenValue.MINUSMINUS: case Token.TokenValue.TIMESTIMES: return true; default: return false; } }
private BinaryOperatorExpression balanceBinaryExpression(SimpleExpression exp, Token.TokenValue op, BinaryOperatorExpression binExp) { if (tokenPriority(op) >= tokenPriority(binExp.op)) { return new BinaryOperatorExpression(op, exp, binExp); } if (binExp.e1 is BinaryOperatorExpression) { return new BinaryOperatorExpression(binExp.op, balanceBinaryExpression(exp, op, (BinaryOperatorExpression)binExp.e1), binExp.e2); } return new BinaryOperatorExpression(binExp.op, new BinaryOperatorExpression(op, exp, binExp.e1), binExp.e2); }
public UnaryOperatorExpression(Token.TokenValue operatorToken, SimpleExpression expr) { op = operatorToken; exp = expr; }
public VariableUpdate(PathExpression varPath, Token.TokenValue opUpdate) { this.variable = varPath; this.op = opUpdate; }
public bool startParse() { /*if (lexBuf.Count == 0) { return true; }*/ if (codeToParse == string.Empty) { return true; } lexCode(); currentToken = lexBuf.ElementAt(indiceToken); try { while (!currentTokenEquals(Token.TokenValue.EOF)) { switch (currentToken.type) { case Token.TokenValue.NPC: script.addNpc(parseNpc()); break; default: return false; } } } catch (BaseException e) { //Print.Printer.printError("[Exception]"); //IrisPrinter.Printer.printError(e.ExceptionToString()); System.Windows.MessageBox.Show(e.ExceptionToString()); return false; } return true; }
public BinaryOperatorExpression(Token.TokenValue opValue, SimpleExpression left, SimpleExpression right) { this.op = opValue; this.e1 = left; this.e2 = right; }
/*public bool nextTokenEquals(Token.TokenValue value) { if (indiceToken + 1 >= lexBuf.Count) { //erreur return false; //throw new Exception(); } return (lexBuf.ElementAt(indiceToken + 1).type == value); }*/ public bool currentTokenEquals(Token.TokenValue value) { /*if (indiceToken >= lexBuf.Count) { //erreur return false; }*/ return (currentToken.type == value); }
public bool startParse() { if (codeToParse == string.Empty || codeToParse == null) { return true; } lexCode(); currentToken = lexBuf.ElementAt(indiceToken); try { while (!currentTokenEquals(Token.TokenValue.EOF)) { switch (currentToken.type) { case Token.TokenValue.CHARACTER: script.addCharacter(parseCharacter()); break; case Token.TokenValue.IMAGE: script.addImage(parseImage()); break; case Token.TokenValue.SOUND: script.addSound(parseSound()); break; case Token.TokenValue.BACKGROUND: script.addBackground(parseBackground()); break; default: return false; } } } catch (BaseException e) { System.Windows.MessageBox.Show(e.ExceptionToString()); return false; } fileStream.Close(); return true; }
public LiteralExpression(Token val) { this.value = val; }
public bool currentTokenEquals(Token.TokenValue value) { return (currentToken.type == value); }
public void nextToken() { if (indiceToken == lexBuf.Count - 1) { lexCode(); } indiceToken++; if (indiceToken >= lexBuf.Count) { //erreur //return; throw new Exception(); } currentToken = lexBuf.ElementAt(indiceToken); }
public bool startParse() { if (codeToParse == string.Empty || codeToParse == null) { return true; } lexCode(); currentToken = lexBuf.ElementAt(indiceToken); try { while (!currentTokenEquals(Token.TokenValue.EOF)) { switch (currentToken.type) { case Token.TokenValue.NPC: script.addNpc(parseNpc()); break; default: return false; } } } catch (BaseException e) { System.Windows.MessageBox.Show(e.ExceptionToString()); return false; } fileStream.Close(); return true; }
public static string tokenstring(Token tok) { return tokenstring(tok); }