summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-12-18 00:37:25 +1100
committerJed Barber <jjbarber@y7mail.com>2020-12-18 00:37:25 +1100
commit9d5eccf7d6662e897eaa1b6b5f16fba0aa5a5f38 (patch)
tree5cd91230a6c9c40a0283cf37da14f0ba21d285bb
parent7b4adc611d65915eaf8c62b47975b48327a9f83f (diff)
Modified ssss.adb for variable input size
-rw-r--r--example/ssss.adb66
1 files changed, 52 insertions, 14 deletions
diff --git a/example/ssss.adb b/example/ssss.adb
index bcf2d75..2c29b2f 100644
--- a/example/ssss.adb
+++ b/example/ssss.adb
@@ -6,19 +6,20 @@
with
Ada.Text_IO,
+ Ada.Strings.Fixed,
+ Ada.Command_Line,
Packrat.No_Lex,
Packrat.Utilities;
use
- Ada.Text_IO;
+ Ada.Text_IO,
+ Ada.Strings.Fixed;
procedure Ssss is
- Input : String := "xxxx";
-
type Parser_Labels is (S, X);
package My_Rat is new Packrat.No_Lex (Parser_Labels, Character, String);
@@ -42,29 +43,66 @@ procedure Ssss is
+ function Is_Digits
+ (Str : in String)
+ return Boolean is
+ begin
+ return (for all C of Str => C in '0' .. '9');
+ end Is_Digits;
+
+
+
+
+ package Comlin renames Ada.Command_Line;
+
Result_Graph : My_Rat.Parser_Result;
+ Silent_Running : Boolean := False;
+ Input_Length : Positive := 4;
+
begin
S_Redir.Set (S'Access);
- Result_Graph := Parser.Parse (Input);
+ for I in 1 .. Comlin.Argument_Count loop
+ if Comlin.Argument (I) = "--help" then
+ Put_Line ("Simple Yet Highly Ambiguous Grammar Stress Tester");
+ New_Line;
+ Put_Line ("s ::= 'x' s s | <empty>");
+ New_Line;
+ Put_Line ("Command like switchs are --help or --silent");
+ Put_Line ("You may also provide the length of input, with the default being 4.");
+ return;
+ elsif Comlin.Argument (I) = "--silent" then
+ Silent_Running := True;
+ elsif Is_Digits (Comlin.Argument (I)) and then
+ Integer'Value (Comlin.Argument (I)) > 0
+ then
+ Input_Length := Integer'Value (Comlin.Argument (I));
+ end if;
+ end loop;
- Put_Line ("Input:");
- Put_Line (Input);
- New_Line;
- Put_Line ("Parser graph output:");
- Put_Line (My_Rat.Parse_Graphs.Debug_String (Result_Graph));
- New_Line;
+ Result_Graph := Parser.Parse (Input_Length * 'x');
- Put_Line ("Root tokens:");
- for T of Result_Graph.Root_Elements loop
- Put (My_Rat.Parser_Tokens.Debug_String (T));
- end loop;
+
+ if not Silent_Running then
+ Put_Line ("Input:");
+ Put_Line (Input_Length * 'x');
+ New_Line;
+
+ Put_Line ("Parser graph output:");
+ Put_Line (My_Rat.Parse_Graphs.Debug_String (Result_Graph));
+ New_Line;
+
+ Put_Line ("Root tokens:");
+ for T of Result_Graph.Root_Elements loop
+ Put (My_Rat.Parser_Tokens.Debug_String (T));
+ end loop;
+ end if;
end Ssss;