/** * Parse according to the grammar statement. statement: ID '=' expression ; * * <p>match(ID); match('='); expr() */ public void parserRuleAssignmentStatement(final AbstractSyntaxTree ast) { final LangType p1 = this.parserLookAhead(1); final LangType p2 = this.parserLookAhead(2); boolean checkRuleSymbol = p1 != null && p1.eqlt(new LangTypeTokenSymbol("<none>")); boolean checkRuleAssignment = p2 != null && p2.eql(new LangTypeToken("=")); if (checkRuleSymbol && checkRuleAssignment) { this.parserMatchType(new LangTypeTokenSymbol("<none>")); this.parserMatch(new LangTypeToken("=")); AbstractSyntaxTree continueWithAssignTree = null; final AbstractSyntaxTree assignTree = new AssignmentNode(p2); assignTree.addChildToAbstractSyntaxTree(new SymbolNode(p1)); ast.addChildToAbstractSyntaxTree(assignTree); continueWithAssignTree = assignTree; // Continue with rule for numbers this.parserRuleNumberExpression(continueWithAssignTree); } else if (checkRuleSymbol) { this.parserMatchType(new LangTypeTokenSymbol("<none>")); } else { System.out.println( "Parser rule fail - " + checkRuleSymbol + " // " + checkRuleAssignment + " $ " + p1 + "/" + p2); } // End of if - check for assignment rule }
public static Language readLanguage(final ZippyBuffer reader) throws IOException { final Language packet = new Language(); int sector; while ((sector = reader.readSector()) != 0) { switch (sector) { case 1: packet.setInput(LangType.readLangType(reader)); break; case 2: packet.setOutput(LangType.readLangType(reader)); break; } } return packet; }
/** Parse according to the grammar statement. expressionRest: +/- NUMBER {expressionRest} */ public void parserRuleNumberExpressionRest( final AbstractSyntaxTree ast, final LangType numberValLhs) { final LangType p1 = this.parserLookAhead(1); final boolean checkRulePlus = p1 != null && p1.eql(new LangTypeToken("+")); if (checkRulePlus) { final LangType plus = new LangTypeToken("+"); final AbstractSyntaxTree newNodePlus = new PlusNode(plus); final AbstractSyntaxTree valnode = new NumberNode(numberValLhs); newNodePlus.addChildToAbstractSyntaxTree(valnode); this.parserMatch(plus); final LangType numberValRhs = this.parserLookAhead(1); this.parserMatchType(new LangTypeTokenDouble(-1)); this.parserRuleNumberExpressionRest(newNodePlus, numberValRhs); ast.addChildToAbstractSyntaxTree(newNodePlus); } else { final AbstractSyntaxTree valnode = new NumberNode(numberValLhs); ast.addChildToAbstractSyntaxTree(valnode); } // End of the if - check rule for plus }
public boolean eql(final LangType obj) { if (obj == null) { lastEqlState = -2; return false; } if (this == obj) { lastEqlState = 1; return true; } // Check if obj is a super class if (!this.getClass().isAssignableFrom(obj.getClass())) { lastEqlState = -3; return false; } if (this.token().equals(obj.token())) { lastEqlState = 2; return true; } lastEqlState = -9; return false; }
public boolean eqlt(final LangType obj) { if (obj == null) { lastEqlState = -5; return false; } if (this == obj) { lastEqlState = 5; return true; } // Check if obj is a super class if (this.getClass().isAssignableFrom(obj.getClass())) { lastEqlState = -7; return true; } lastEqlState = -99; return false; }
private static String get(LangType type) { return config.getString("msgs." + type.name().toLowerCase()); }