Title: Theory / Unimportant / CS / Programming / Lex
Tags: récupéré seen_description mid1516974248815 FromInstruction hasNotNewEffectReturnsMeaning type computer_to_instruction
On every note of this deck, unless a note says otherwise:
Page: http://dinosaur.compilertools.net/lex/index.html

Question: In case of many rules can be applied, Lex choose
Answer: the first rule
Page: http://dinosaur.compilertools.net/lex/index.html

Question: If many string match the same rule, Lex choose
Answer: longest match possible at each input point
Page: http://dinosaur.compilertools.net/lex/index.html

Name: Host language
Definition: The language in which the code to execute between the regexp is written
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: lex

Name: yylex
Definition: the program generated by lex in a the host language
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: lex

Name: input
Definition: Stream given to yylex
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: lex

Name: output
Definition: Text written by yylex
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: lex

Question: What happen to text matched by no rule ?
Answer: It is copied verbatim
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: lex

Instruction: %%
Effect: Separate definition and rule, rule and subroutine
Language: Lex
Chapter: 1

Question: lex
Answer: linear in the size of the stream (assuming no significant lookahed)
Page: http://dinosaur.compilertools.net/lex/index.html
Chapter: 1
Context: rule part of lex

Instruction: foo
%%
bar
[%%
buz]
Effect: A lex source, with definitions foo, rules bar and potentially subroutine buz
Language: lex
Chapter: 2

Instruction: regexp
Effect: omitted
Language: lex
Chapter: 1

Instruction: foo (space or tab) bar;
Effect: insert a rule for regexp foo doing action bar
Language: lex
Context: rule part of lex
Chapter: 3

Instruction: |
Effect: the action is the same than the one for next rule
Language: lex
Context: action
Chapter: 3

Variable: yytext
Meaning: the array of value matched by the rule to generate the current action
Page: http://dinosaur.compilertools.net/lex/index.html
Context: action
Language: Lex
Chapter: 4

Instruction: ECHO;
Effect: Print the matched string
Language: lex
Context: action
Chapter: 4

Variable: yyleng
Meaning: the number of character matched by the rule generated the current action
Page: http://dinosaur.compilertools.net/lex/index.html
Context: action
Language: Lex
Chapter: 4

Instruction: yymore()
Effect: In the next action, consider that the current text is the prefix of the text matched by the next ruled triggered
Language: lex
Context: action
Chapter: 4
Returns: \"[^"]*   {
                            if (yytext[yyleng-1] == '\\')
                                 yymore();
                            else
                                 ... normal user processing
                            }
match string literal, restarting in case of \"

Instruction: yyless(foo)
Effect: Return the last foo character to the stream of data.
Language: lex
Context: action
Chapter: 4
Returns: =-[a-zA-Z]   {
                              printf("Op (=-) ambiguous\n");
                              yyless(yyleng-1);
                              ... action for =- ...
                              }
or
 =-[a-zA-Z]   {
                              yyless(yyleng-2);
                              ... action for = ...
                              }
depending on how the ambiguity is resolved

Instruction: input()
Effect: the next input character
Language: lex
Context: action
Chapter: 4

Instruction: output(foo)
Effect: write the caracter foo to the output
Language: lex
Context: action
Chapter: 4

Instruction: unput(foo)
Effect: pushes the character c back onto the input stream to be read later by input()
Language: lex
Context: action
Chapter: 4

Instruction: yywrap()
Effect: macro called when input reach end of file.
Language: lex
Context: action
Chapter: 4
Returns: 1: Lex continues with the normal wrapup on end of input.
0: new input will arrive

Instruction: /foo
Effect: the regexp should be followed by foo but foo will not be taken in the string
Language: lex
Context: regexp
Chapter: 4

Typ: position
Meaning: informations related to the position of a character in an input stream
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex

Variable: p.pos_fname
Meaning: The name of the file from which the stream come
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex
Variables: p a Lexing.position

Variable: p.pos_lnum
Meaning: the line number of the position
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex
Variables: p a Lexing.position

Variable: p.pos_bol
Meaning: offset of the beginning of the line.  (number
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex
Variables: p a Lexing.position

Variable: p.pos_cnum
Meaning: offset of the position from the beginning of the line
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex
Variables: p a Lexing.position

Variable: Lexing.dummy_pos
Meaning: A position distinct from any valid position
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex

Typ: lexbuf
Meaning: the argument passed
to the scanning functions defined by the generated scanners
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
Language: Lex
Assuming: Lexer buffer
Library: Lexing