From c84b2dffddc0f31ebdd2e95ac95d0dce65eb3921 Mon Sep 17 00:00:00 2001 From: Warren Toomey Date: Fri, 26 Feb 2016 07:35:36 +1000 Subject: [PATCH] I've changed the assembler so that it groks the string literal syntax. I think it's OK, but it probably needs more testing. write_test.s was changed to exercise the string parsing. --- tools/as7 | 30 +++++++++++++++++++++++++++++- tools/write_test.s | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/as7 b/tools/as7 index 835f830..1d235b0 100755 --- a/tools/as7 +++ b/tools/as7 @@ -198,7 +198,7 @@ sub parse_statement { # Parse an expression and return either: # a single value which is a PDP-7 word -# a single value which is undef, as this was a statement +# a single value which is undef, as this was unrecognised sub parse_expression { my $expression = shift; @@ -346,6 +346,34 @@ sub parse_expression { #printf( "o>%s%s%s$}) { + print("String literal <$1 and $2>\n") if ($debug); + return((ord($1) << 9) | ord($2)); + } + + # This is a string literal preceded by a numeric literal + if (defined($word2) && ($word2=~ m{(.)>$})) { + print("String literal $word1 and $1>\n") if ($debug); + my $msb= parse_expression($word1); + my $lsb= $1; + return(($msb << 9) | ord($lsb)); + } + + # This is a n> string literal not preceded by a numeric literal + if ($word1=~ m{(.)>$}) { + print("String literal $1>\n") if ($debug); + return(ord($1)); + } + # This a defined instruction if ( defined( $inst{$word1} ) ) { #printf( "Found the instruction %s: 0%o\n", $word1, $inst{$word1} ); diff --git a/tools/write_test.s b/tools/write_test.s index 375b0bc..6a1ea8e 100644 --- a/tools/write_test.s +++ b/tools/write_test.s @@ -47,7 +47,7 @@ in: 023 out: 0 " Hello, world\n, two ASCII chars per word -hello: 0110145; 0154154; 0157054; 040; 0167157; 0162154; 0144012 +hello: ; ; 040; ; ;