Closed MartinHelmut closed 3 years ago
First part: Adding a scanner to tokenize input 8cdd1c9289fc7c61954b8c38ab13e37aec6a4796
To continue with the parser, convert Tokens to Instructions.
For the following given command:
litr -t="debug" build cpp -p=1 , java -p=2 ,, run -y
Here a pseudo instructions list as example:
BEGIN_SCOPE ""
LOAD "t" "debug"
BEGIN_SCOPE "build"
BEGIN_SCOPE "cpp"
LOAD "p" "1"
EXECUTE "build.cpp"
END_SCOPE "," "cpp" // Comma clears the last scope
BEGIN_SCOPE "java"
LOAD "p" "2"
EXECUTE "build.java"
END_SCOPE "," "java"
END_SCOPE "," "build"
BEGIN_SCOPE "run"
LOAD "y" true
EXECUTE "run"
END_SCOPE "," "run"
END_SCOPE "EOS" ""
The double comma ,,
to end another scope should not be documented, as it is not an officially supported feature. Or should it?
Possible notation to describe syntax:
# Entry point:
arguments = parameters? commands?;
parameters = parameter+;
parameter = parameter_name ( "=" literal )?;
parameter_name = short_parameter | long_parameter;
short_parameter = "-" STRICT_ALPHA;
long_parameter = "--" STRICT_ALPHA;
commands = command ( "," command )?;
command = ALPHA parameters?;
# Numbers are handled as strings as well. This won't make a difference for any shell.
literal = NUMBER | STRING;
NUMBER = "-"? 0-9+ ("." 0-9+)?
STRING = '"' .* '"';
ALPHA = A-Za-z_;
STRICT_ALPHA = A-Za-z;
Legend:
|
Or()
Grouping?
Optional*
Repeat 0 to n times+
Repeat 1 to n timesFor the given command
litr -t="debug" build cpp -p=1 -p=2 , java --pog=2
the current parser produces the following instructions:
0000 DEFINE 0 't'
0002 CONSTANT 1 'debug is cool'
0004 BEGIN_SCOPE 2 'build'
0006 BEGIN_SCOPE 3 'cpp'
0008 DEFINE 4 'p'
0010 CONSTANT 5 '1'
0012 DEFINE 6 'p'
0014 CONSTANT 7 '2'
0016 EXECUTE 8 'build.cpp'
0018 CLEAR
0019 BEGIN_SCOPE 9 'java'
0021 DEFINE 10 'pog'
0023 CONSTANT 11 '2'
0025 EXECUTE 12 'build.java'
0027 CLEAR
Process finished with exit code 0
Documentation created under: https://github.com/krieselreihe/litr/wiki/Command-line-argument-parsing