]> git.lyx.org Git - lyx.git/blob - development/attic/lyx3/lyx3.y
Customization: correct some color names.
[lyx.git] / development / attic / lyx3 / lyx3.y
1 Brief discussion on LaTeX grammar
2 ---------------------------------
3
4 LaTeX syntax is relatively simple. Any command is like this:
5
6   \command_name [<options>]{<argument_1>}...
7
8 This can be expressed as a grammar in yacc/bison syntax. Capitalized words
9 are tokens (terminals) returned by lex:
10
11 command    :    LT_command options arguments
12  
13 arguments  :    argument
14            |    argument arguments
15            |    /* empty: It's possible to not have arguments */
16            ;
17
18 argument   :    '{'  anything '}'
19            ;
20            
21 options    :     '[' word_list ']'
22            |     /* empty: It's possible to don't have options */
23            ;
24
25 word_list  :     LT_word ',' word_list
26            |     LT_word
27            ;
28
29 anything   :     /* Any valid token */
30            |     command
31            |     LT_punctuation
32            |     LT_accent
33            |     LT_etc
34            ;
35
36 This is quite simple and can be easily parsed by any LALR parser as a yacc
37 or bison generated one. BUT the difficulty comes because the number of
38 arguments depends on the value of LT_command, and that the symbols '{' and
39 '}' have more uses that to separate arguments. This expression:
40
41           \section{Hello world} {\bf Once}
42
43 is ambiguos since the parser would interpret the last group as a second
44 argument. Maybe the simpler approach is declaring a grammar for each of the
45 commands that LyX will to understand. Another is that if the parser knows
46 the identity of a command should know also how many arguments should expect.
47 [Aren't these two suggestions almost identical? I mean, if we tell the parser
48 what parameters each command take, we also have a grammar for each of the
49 commands, LyX will understand... Asger]
50
51 AAS