explication de la methode de parsing

This commit is contained in:
hugogogo
2021-10-15 10:39:47 +02:00
parent 3e758dc843
commit 7e53601ad5

View File

@@ -10,10 +10,10 @@
- **expensions :** - **expensions :**
- `$` *variable expension* - `$` *variable expension*
- `$?` *exit return of last executed process* - `$?` *exit return of last executed process*
- **quotes :** --> [ressource](https://linuxhandbook.com/quotes-in-bash/) - **quotes :** [ressource](https://linuxhandbook.com/quotes-in-bash/)
- `'` *(ignore any special characters)* - `'` *(ignore any special characters)*
- `"` *(ignore any special characters except '$')* - `"` *(ignore any special characters except '$')*
- **redirections & heredocs :** --> [ressource](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) / [heredocs for readability](https://www.techrepublic.com/article/use-heredoc-in-shell-scripts/) - **redirections & heredocs :** [ressource](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) / [heredocs for readability](https://www.techrepublic.com/article/use-heredoc-in-shell-scripts/)
- `<` *redirect input* - `<` *redirect input*
- `>` *redirect output* - `>` *redirect output*
- `<<` *read input until empty line --* **? doesn't update history ?** - `<<` *read input until empty line --* **? doesn't update history ?**
@@ -29,12 +29,11 @@
- `export` - `export`
- `unset` - `unset`
- ~~`exit`~~ - ~~`exit`~~
- **builtins (don't need to be) :** - **builtins (don't need to be) :** [source](https://git.42l.fr/Fabien/minishell)
- `env` - `env`
- ~~`echo`~~ - ~~`echo`~~
- `echo -n` - `echo -n`
--> [source of a minishell with an interesting README](https://git.42l.fr/Fabien/minishell)
--- ---
@@ -88,6 +87,8 @@ EXEMPLE : . .
- 'a"r'g'"1' - 'a"r'g'"1'
- 'arg"1"'arg2'arg3' - 'arg"1"'arg2'arg3'
### tentative methode 1
#### pseudo code :
``` ```
int q; // first quote int q; // first quote
int c; // count int c; // count
@@ -136,8 +137,9 @@ while (str[i])
} }
i++; i++;
} }
```
### application :
```
['][a][r][g][1][ ]['][a][r][g][2]["][ ][a][r][g][3]["] ['][a][r][g][1][ ]['][a][r][g][2]["][ ][a][r][g][3]["]
c = 0 . . . . . . . . . . . . . . . . . . c = 0 . . . . . . . . . . . . . . . . . .
c = 1 . . . . . . . . . . . . . . . . . str[i] == ' ; q == 0 c == 0 -> c++; q = ' c = 1 . . . . . . . . . . . . . . . . . str[i] == ' ; q == 0 c == 0 -> c++; q = '
@@ -175,14 +177,16 @@ c = . . . . . . . 1 . . str[i] == " ; q != " c == 2 ->
ERROR ... ERROR ...
c = . . . . . . . . 1 . str[i] != ' | " ; -> c = . . . . . . . . 1 . str[i] != ' | " ; ->
c = . . . . . . . . . 0 str[i] != ' | " ; -> c = . . . . . . . . . 0 str[i] != ' | " ; ->
```
#### erreur :
-> comment le programme sait que cette fois il doit decrementer "c" ? -> comment le programme sait que cette fois il doit decrementer "c" ?
en retenant dans l'ordre toutes les dernieres valeurs de "q" ! en retenant dans l'ordre toutes les dernieres valeurs de "q" !
-> donc plutot partir sur une recursive -> donc plutot partir sur une recursive
```
deuxieme methode : ### tentative methode 2 :
#### exemple :
``` ```
.--------------------------------------------. .--------------------------------------------.
: .--------------------------------------. : : .--------------------------------------. :
@@ -191,15 +195,25 @@ deuxieme methode :
: : : .--. : .--. : : .--. : : : : : : : .--. : .--. : : .--. : : : :
'__"__'__"__"__"__'__'__"__"__'__'__"__'__"__' '__"__'__"__"__"__'__'__"__"__'__'__"__'__"__'
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
```
-> repérer les paires de quotes ou dquotes
piege : -> piège :
```
| | | |
.--. .--. v v .--. .--. .--. v v .--.
'__"__'__"__"__"__'__'__"__"__'__'__"__'__"__' '__"__'__"__"__"__'__'__"__"__'__'__"__'__"__'
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
```
0. envoyer une copie de la str dans une fonction
1. chercher la premiere pair
2. l'effacer
3. recommencer en boucle
4. stop quand la premier quote a trouvé sa paire
5. renvoyer l'emplacement de la pair
exemple :
```
.--. .--.
1 : '__"__'__"__"__"__'__'__"__"__'__'__"__'__"__' 1 : '__"__'__"__"__"__'__'__"__"__'__'__"__'__"__'