Lhogho
0.0.028
|
Go to the source code of this file.
Macros | |
#define | GET_CHAR ch=*source |
get current character More... | |
#define | VAR vars[count] |
shortens access to vars array More... | |
#define | LINK |
#define | RELINK |
Tokentypes | |
#define | TOKEN_END 0 |
no more tokens available More... | |
#define | TOKEN_WORD 1 |
normal word token More... | |
#define | TOKEN_DIRTY_WORD 2 |
word token with unhandled backslashs or bars More... | |
#define | TOKEN_OPEN 3 |
open square bracket token More... | |
#define | TOKEN_CLOSE 4 |
close square bracket token More... | |
#define | TOKEN_LINEEND 5 |
end of line token More... | |
#define | TOKEN_SPACE 6 |
whitespace token More... | |
#define | TOKEN_ERROR 7 |
error occured More... | |
Parse modes | |
#define | MODE_ENTRY 0 |
entry mode More... | |
#define | MODE_SPACE 1 |
space mode More... | |
#define | MODE_WORD 2 |
word mode More... | |
#define | MODE_BARRED 3 |
barred mode More... | |
#define | MODE_BACKSLASHED 4 |
backslashed mode More... | |
#define | MODE_TILDE 5 |
tilde mode More... | |
#define | MODE_SEMITILDE 6 |
semitilde mode More... | |
#define | MODE_SEMICOLON 7 |
semicolon mode More... | |
#define | MODE_TILDESPACE 8 |
tildespace mode More... | |
#define | MODE_LESS 9 |
less mode More... | |
#define | MODE_GREATER 10 |
greater mode More... | |
#define | MAX_MODE 11 |
greatest mode + 1 More... | |
Microprogram defines (basic) | |
#define | PAT_TILDE 0x000001 |
push tilde More... | |
#define | PAT_PUSH 0x000002 |
push last character More... | |
#define | PAT_NEXT 0x000004 |
goto next character More... | |
#define | PAT_DIRTY 0x000008 |
set dirty flag More... | |
#define | PAT_MUTATED 0x000010 |
set mutated flag More... | |
#define | PAT_RETURN_TO_WORD 0x000020 |
next return will return to word mode More... | |
#define | PAT_RETURN_TO_SELF 0x000040 |
next return will return to current mode More... | |
#define | PAT_GOTO 0x000080 |
follows 4bit go-to-mode More... | |
#define | PAT_TOKEN 0x000100 |
follows 4bit token_id More... | |
#define | PAT_RETURN 0x000200 |
return to stack-to-mode More... | |
#define | PAT_ERROR_POS 0x000400 |
remember current position as error position More... | |
#define | PAT_ERROR 0x000800 |
generate error More... | |
#define | PAT_RETURN_TO_CALLER 0x001000 |
next return will return to the caller of this mode More... | |
#define | PAT_NEXT2 0x002000 |
goto next next character More... | |
Microprogram defines (compound) | |
#define | PAT_SHIFT 16 |
shift factor More... | |
#define | PAT_TOKEN_END PAT_TOKEN+(TOKEN_END<<PAT_SHIFT) |
microprogram for end token More... | |
#define | PAT_TOKEN_SPACE PAT_TOKEN+(TOKEN_SPACE<<PAT_SHIFT) |
microprogram for space token More... | |
#define | PAT_TOKEN_WORD PAT_TOKEN+(TOKEN_WORD<<PAT_SHIFT) |
microprogram for word token More... | |
#define | PAT_TOKEN_LINE PAT_TOKEN+(TOKEN_LINEEND<<PAT_SHIFT) |
microprogram for line end token More... | |
#define | PAT_TOKEN_OPEN PAT_TOKEN+(TOKEN_OPEN<<PAT_SHIFT) |
microprogram for open token More... | |
#define | PAT_TOKEN_CLOSE PAT_TOKEN+(TOKEN_CLOSE<<PAT_SHIFT) |
microprogram for close token More... | |
#define | PAT_GOTO_SPACE PAT_GOTO+(MODE_SPACE<<PAT_SHIFT) |
microprogram for goto space mode More... | |
#define | PAT_GOTO_WORD PAT_GOTO+(MODE_WORD<<PAT_SHIFT) |
microprogram for goto word mode More... | |
#define | PAT_GOTO_BACKSLASHED PAT_GOTO+(MODE_BACKSLASHED<<PAT_SHIFT) |
microprogram for goto backslashed mode More... | |
#define | PAT_GOTO_BARRED PAT_GOTO+(MODE_BARRED<<PAT_SHIFT) |
microprogram for goto barred mode More... | |
#define | PAT_GOTO_SEMICOLON PAT_GOTO+(MODE_SEMICOLON<<PAT_SHIFT) |
microprogram for goto semicolon mode More... | |
#define | PAT_GOTO_TILDE PAT_GOTO+(MODE_TILDE<<PAT_SHIFT) |
microprogram for goto tilde mode More... | |
#define | PAT_GOTO_TILDESPACE PAT_GOTO+(MODE_TILDESPACE<<PAT_SHIFT) |
microprogram for goto tildespace mode More... | |
#define | PAT_GOTO_SEMITILDE PAT_GOTO+(MODE_SEMITILDE<<PAT_SHIFT) |
microprogram for goto semitilde mode More... | |
#define | PAT_GOTO_LESS PAT_GOTO+(MODE_LESS<<PAT_SHIFT) |
microprogram for goto less mode More... | |
#define | PAT_GOTO_GREATER PAT_GOTO+(MODE_GREATER<<PAT_SHIFT) |
microprogram for goto greater mode More... | |
Special characters | |
When a chracter is barrable and is actually barred then its code is changed. For example codes for space and barred space are different for Lhogho, but should appear the same for users. Barrable characters are ()+- | |
#define | MAX_ELEMS 128 |
maximal number of elements in a statement More... | |
char_t | debar [32] |
table for a->|a| conversions More... | |
atom_t | build_syntax_subtree (atom_t function, atom_t source) |
parses sublist of commands More... | |
void | init_parser () |
initializes parser More... | |
atom_t | tokenize (atom_t input, int method) |
tokenizes into a list More... | |
atom_t | trim_shell_comment (atom_t word) |
trims shell comment (if any) More... | |
atom_t | purify (atom_t word) |
purifies a word More... | |
atom_t | parentheses (atom_t input) |
processes parentheses More... | |
atom_t | define_user_function (atom_t source, atom_t input, atom_t parent) |
creates var atom for a user-defined function More... | |
atom_t | preparse (atom_t input, atom_t parent, int level) |
extracts all TO ... END definitions More... | |
atom_t | parse (atom_t input, atom_t parent, int top_level) |
parses a list into a tree More... | |
atom_t | build_syntax_tree (atom_t func) |
parses body of user-defined function More... | |
#define PAT_TOKEN_SPACE PAT_TOKEN+(TOKEN_SPACE<<PAT_SHIFT) |
#define PAT_TOKEN_WORD PAT_TOKEN+(TOKEN_WORD<<PAT_SHIFT) |
#define PAT_TOKEN_LINE PAT_TOKEN+(TOKEN_LINEEND<<PAT_SHIFT) |
#define PAT_TOKEN_OPEN PAT_TOKEN+(TOKEN_OPEN<<PAT_SHIFT) |
#define PAT_TOKEN_CLOSE PAT_TOKEN+(TOKEN_CLOSE<<PAT_SHIFT) |
#define PAT_GOTO_SPACE PAT_GOTO+(MODE_SPACE<<PAT_SHIFT) |
#define PAT_GOTO_BACKSLASHED PAT_GOTO+(MODE_BACKSLASHED<<PAT_SHIFT) |
#define PAT_GOTO_BARRED PAT_GOTO+(MODE_BARRED<<PAT_SHIFT) |
#define PAT_GOTO_SEMICOLON PAT_GOTO+(MODE_SEMICOLON<<PAT_SHIFT) |
#define PAT_GOTO_TILDE PAT_GOTO+(MODE_TILDE<<PAT_SHIFT) |
#define PAT_GOTO_TILDESPACE PAT_GOTO+(MODE_TILDESPACE<<PAT_SHIFT) |
#define PAT_GOTO_SEMITILDE PAT_GOTO+(MODE_SEMITILDE<<PAT_SHIFT) |
#define PAT_GOTO_GREATER PAT_GOTO+(MODE_GREATER<<PAT_SHIFT) |
#define LINK |
#define RELINK |
function | var atom for the parse context |
source | word or list containing the source |
Parses a list of commands (like these in IF or REPEAT) and build an abstract syntax tree:
TO
... ENDs
and create them as subfunctionsDefinition at line 2356 of file parser.c.
void init_parser | ( | ) |
input | word, subword or list to be tokenized |
method | method of tokenization |
Tokenizes a word, a subword or a list into a list. If possible makes all words as subwords. Backslashes and bars in words are preserved (i.e. words are not purified). Comments and line continuations are ignored.
If the method is TOKENIZE_DATA then the input is tokenized as if it contains Logo data. If the method is TOKENIZE_COMMANDS then the input is tokenized as if it contains Logo commands. If the method is TOKENIZE_READWORD then the input is tokenized as expected by READWORD function.
If the input is a list then all its elements are tokenized one-by-one.
Return value is the tokenized list. In there is an error, returns an error atom which error code is ERROR_INCOMPLETE_PAIR, error position points the position in the word (0-based) and the error source is the word itself.
Definition at line 275 of file parser.c.
word | word containing source text |
Trims a shell comment from the beginning of the word. Shell comment can be only the first line if its first two characters are #!
. If a shell comment is trimmed, then the result is a subword from the first character on the second line, otherwise the input word is returned as is but with increased reference count.
Definition at line 1055 of file parser.c.
input | flat list |
Processes all (...) of a flat list by making them as sublists. Returns ERROR_INCOMPLETE_PAIR if the parentheses are not paired well.
Definition at line 1167 of file parser.c.
source | word containing the source |
input | contents between TO and END |
parent | context var where creation is done |
Defines new user-defined command or function. The input
contains the contents of the function – these are all tokens between TO
and END
. Var creation is done in several steps:
: and are on a single line
: or double quotes "
.
: and are on the same line.Definition at line 1310 of file parser.c.
input | list with tokenized source code |
parent | context var where preparsing is done |
level | current level of nesting return source without TO ... END definitions |
Pre-parses a flat tokenized list by extracting all local TO
... END
definitions and creating corresponding local functions. Returns the remaining source code.
input | unparsed list |
parent | parent var in which parsing is done |
top_level | flag whether parsing is at its top-level |
Parses a list into a tree (aka LISP notation). The list is supposed to be tokenized as commands. The parent
variable provides a context of variables which can be referenced from the parsed input.
running_compiled_code && bug #3442773
Definition at line 1632 of file parser.c.
func | var atom for the parse context |
Parses completely a function. Its source is stored in its body as word, subword, data-tokenized list or command-tokenized list. Building algorithm:
TO
... ENDs
and create them as subfunctionsDefinition at line 2278 of file parser.c.