use of de.neemann.digital.core.Bits in project Digital by hneemann.
the class Parser method parseSingleRow.
private LineEmitter parseSingleRow() throws IOException, ParserException {
LineEmitterSimple line = null;
while (true) {
Tokenizer.Token token = tok.next();
if (line == null)
line = new LineEmitterSimple(names.size(), tok.getLine());
switch(token) {
case NUMBER:
Value num = new Value(convToLong(tok.getIdent()));
line.add((vals, context) -> vals.add(num));
break;
case BITS:
expect(Tokenizer.Token.OPEN);
int bitCount = (int) parseInt();
expect(Tokenizer.Token.COMMA);
Expression exp = parseExpression();
line.add(new ValueAppenderBits(bitCount, exp));
expect(Tokenizer.Token.CLOSE);
break;
case IDENT:
try {
final Value value = new Value(tok.getIdent().toUpperCase());
line.add((vals, context) -> vals.add(value));
} catch (Bits.NumberFormatException e) {
throw new ParserException(Lang.get("err_notANumber_N0_inLine_N1", tok.getIdent(), tok.getLine()));
}
break;
case OPEN:
exp = parseExpression();
line.add((vals, context) -> vals.add(new Value((int) exp.value(context))));
expect(Tokenizer.Token.CLOSE);
break;
case EOF:
case EOL:
return line;
default:
throw newUnexpectedToken(token);
}
}
}