1 Brief discussion on LaTeX grammar
2 ---------------------------------
4 LaTeX syntax is relatively simple. Any command is like this:
6 \command_name [<options>]{<argument_1>}...
8 This can be expressed as a grammar in yacc/bison syntax. Capitalized words
9 are tokens (terminals) returned by lex:
11 command : LT_command options arguments
15 | /* empty: It's possible to not have arguments */
18 argument : '{' anything '}'
21 options : '[' word_list ']'
22 | /* empty: It's possible to don't have options */
25 word_list : LT_word ',' word_list
29 anything : /* Any valid token */
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:
41 \section{Hello world} {\bf Once}
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]