Exemplo n.º 1
0
        private static void ProcessDataWords(AsmParser parser, AsmSection output)
        {
            do {
                if (parser.IsEndOfLine) {
                    throw new TokenException("expected data words", parser.LastReadToken);
                }

                var token = parser.PeekToken();

                if (token.Type == TokenType.String) {
                    token = parser.ReadToken(TokenType.String);
                    foreach (var ch in token.StringValue) {
                        output.EmitWord(ch);
                    }
                } else {
                    var val = parser.ReadUshort();
                    output.EmitWord(val);
                }

                if (parser.IsEndOfLine) break;

                var commaPreview = parser.PeekToken();
                if (commaPreview.Type != TokenType.Comma) break;
                parser.ReadToken(TokenType.Comma);
            } while (true);
        }
Exemplo n.º 2
0
        private static void ProcessDataBytes(AsmParser parser, AsmSection output)
        {
            do {
                if (parser.IsEndOfLine) {
                    throw new TokenException("expected data bytes", parser.LastReadToken);
                }

                var token = parser.PeekToken();

                if (token.Type == TokenType.String) {
                    token = parser.ReadToken(TokenType.String);
                    foreach (var ch in token.StringValue) {
                        if (ch > 255) {
                            throw new TokenException("unicode character cannot be translated to byte", token);
                        }
                        output.EmitByte((byte)ch);
                    }
                } else {
                    var val = parser.ReadByte();
                    output.EmitByte(val);
                }

                if (parser.IsEndOfLine) break;

                var commaPreview = parser.PeekToken();
                if (commaPreview.Type != TokenType.Comma) break;
                parser.ReadToken(TokenType.Comma);
            } while (true);
        }