cdvmDDe (1158399), страница 2
Текст из файла (страница 2)
LXR "REAL" -- floating point constant
LXS "STRING" -- string constant
CPP "CPP" -- preprocessor directive as string
2.4.2Delimiters and operators
SEMIC ";"
COMMA ","
LBA "("
LBS "{"
LBK "["
RBA ")"
RBK "]"
RBS "}"
POINT "."
QUEST "?"
COLON ":"
DIV "/"
ADIV "/="
COMM "/*" -- C comment beginning
CPPCOMM "//" -- C++ comment beginning
MOD "%"
AMOD "%="
ADD "+"
AADD "+="
INC "++"
SUB "-"
ASUB "-="
DEC "--"
ARROW "->"
MUL "*"
AMUL "*="
ASSIGN "="
EQU "=="
LT "<"
LE "<="
LSH "<<"
ALSH "<<="
GT ">"
GE ">="
RSH ">>"
ARSH ">>="
BNOT "~"
NOT "!"
NEQ "!="
BAND "&"
AAND "&="
AND "&&"
BOR "|"
AOR "|="
OR "||"
BXOR "^"
AXOR "^="
2.4.3Keywords
RETURN "return"
IF "if"
ELSE "else"
WHILE "while"
DO "do"
FOR "for"
BREAK "break"
CONTINUE "continue"
SWITCH "switch"
CASE "case"
DEFAULT "default"
GOTO "goto"
SIZEOF "sizeof"
TYPEDEF "typedef"
EXTERN "extern"
STATIC "static"
REGISTER "register"
AUTO "auto"
CONST "const"
INT "int"
SHORT "short"
LONG "long"
VOID "void"
CHAR "char"
SIGNED "signed"
UNSIGNED "unsigned"
FLOAT "float"
DOUBLE "double"
STRUCT "struct"
UNION "union"
ENUM "enum"
2.4.4C-DVM keywords and identifiers
LX_DVM "DVM"
PROCESSORS "PROCESSORS"
DISTRIBUTE "DISTRIBUTE"
BLOCK "BLOCK"
GENBLOCK "GENBLOCK"
ONTO "ONTO"
ALIGN "ALIGN"
WITH "WITH"
TEMPLATE "TEMPLATE"
SHADOW "SHADOW"
LX_SG "SHADOW_GROUP"
LX_RG "REDUCTION_GROUP"
LX_RMG "REMOTE_GROUP"
TASK "TASK"
REDISTRIBUTE "REDISTRIBUTE"
REALIGN "REALIGN"
NEW "NEW"
LX_CRTEMP "CREATE_TEMPLATE"
PARALLEL "PARALLEL"
ON "ON"
REDUCTION "REDUCTION"
SHRENEW "SHADOW_RENEW"
ACROSS "ACROSS"
LX_CRSG "CREATE_SHADOW_GROUP"
CORNER "CORNER"
SHSTART "SHADOW_START"
SHWAIT "SHADOW_WAIT"
SUM "SUM"
PROD "PRODUCT"
MAX "MAX"
MIN "MIN"
LX_OR "OR"
LX_AND "AND"
MAXLOC "MAXLOC"
MINLOC "MINLOC"
RSTART "REDUCTION_START"
RWAIT "REDUCTION_WAIT"
REMOTE "REMOTE_ACCESS"
INDIRECT "INDIRECT_ACCESS"
PREFETCH "PREFETCH"
RESET "RESET"
MAP "MAP"
LX_TASKREG "TASK_REGION"
INTERVAL "INTERVAL"
DEBUG "DEBUG"
LX_NUMBER_OF_PROC "NUMBER_OF_PROCESSORS"
LX_FOR "FOR"
LX_DO "DO"
LX_main "main"
LX_malloc "malloc"
LX_free "free"
optD0 "d0"
optD1 "d1"
optD2 "d2"
optD3 "d3"
optD4 "d4"
optE0 "e0"
optE1 "e1"
optE2 "e2"
optE3 "e3"
optE4 "e4"
2.5The Parser
Purpose of the parser is evident:
-
to analyze context-free structure of the program;
-
to report errors, if they were encountered;
-
to build the parsing tree;
-
to invoke a semantic functions for built nodes.
The method of parsing is straitforward top-down descent with backtracking in not numerous doubtful cases. The structure of resulting tree is described in the following section.
The parser is implemented as a recursive function Parse, which uses an internal representation of the source syntax stored in the linked memory as a syntax tree. The syntax tree is built by the function STXinit using functions:
-
STXterm for a terminal element creation;
-
STXelem for a non-terminal creation;
-
STXrule for a syntax rule;
-
STXgroup for a group of syntax rules;
-
STXgrlist for a list of the groups.
The parser also uses the following functions:
-
ParsErr reports an error;
-
cmpLX compares the current token with terminal element of syntax rule;
-
SkipNext tests "lookforward" rules and skips the next rule if necessary;
-
ISWF is the main semantic function; it is invoked twice for every node.
2.6The parsing tree structure
The following table describes the structure of the parsing tree in such a manner. For all node codes (on the left) a fragment of source code where A and B denote subconstructs corresponding to subtrees, hanging on the fields A and B respectively, is presented. AB referes to the subtree hanging on the field A of the node hanging on the field B of the initial node. Where partitioning of a source code to subconstructs is not clear it is commented. Here only "free" structure is described, i.e. dependences and constrains following from syntax are not mentioned.
2.6.1Terminals, lists and braces
TOKEN: -- A is the position in the string memory
DLM: -- A is the internal code of delimiter
KWD: -- A is the internal code of keyword
LXI: -- A is reference to a token node
LXN: -- A is reference to a token node
LXC: -- A is reference to a token node
LXR: -- A is reference to a token node
LXS: -- A is reference to a token node
CPP: -- A is preprocessor directive as a string
COMMA: A , B -- comma-list
LXX: A [B-tail] -- B-list
XXlist: A [B-tail] -- B-list
XXslist: A [B-tail] -- B-list
LBA: "(" [A] ")"
LBS: "{" [A ] "}" -- compound statement
LBK: [A] "[" [B] "]" -- indexing
2.6.2Declarations (of C)
LXX: [AA-DVM_directive] BA-decl [ B-next ]
XXdecl: [AA-storage_class] BA-type B-declarator-list
XXtype: [AA-storage_class] BA-type B-abstract-declarator
Memory class (one or more B-linked nodes):
STATIC: static [B]
AUTO: auto [B]
REGISTER: register [B]
EXTERN: extern [B]
TYPEDEF: typedef [B]
CONST: const [B]
Types (simple types are B-linked):
STRUCT: struct [A] ["{" AB-fields "}"]
UNION: union [A] ["{" AB-fields "}"]
ENUM: enum [A] ["{" B "}"]
VOID: void
TYPEDEF: B - typedef-name
UNSIGNED: unsigned [B]
SIGNED: signed [B]
CHAR: char [B]
SHORT: short [B]
LONG: long [B]
INT: int [B]
FLOAT: float [B]
DOUBLE: double [B]
Declarators:
0: AA-declarator [BA-initializer] B-list-tail
LXaster: * [B-"const"] A
LXfun: A "(" [B] ")"
Initializers:
ASS: = A
COLON: : A
Declarator list tail:
XXbody: "{" [A] "}" [B -- ";"]
XXclist: , A
SEMIC: ; -- end of list
2.6.3Statements (of C)
XXoper: A
IF: if "(" AA ")" BA [else B]
WHILE: while "(" A ")" B
DO: do B while "(" A ")" ;
FOR: for "(" AA ; ABA ; BBA ")" B
SWITCH: switch "(" A ")" "{" B "}"
GOTO: goto A ;
LXskip: ;
RETURN: return [A] ;
LX_FOR: FOR "(" AA , BA ")" B
LX_DO: DO "(" AA-variable , BA ")" B
CONTINUE: continue ;
BREAK: break ;
COLON: A :
XXexpr: A ;
DEFAULT: default: [B]
CASE: case A : [B]
2.6.4Expressions (of C)
LBK: A "[" B "]"
POINT: A . B
ARROW: A -> B A
SS: A = B
AADD: A += B
ASUB: A -= B
AMUL: A *= B
ADIV: A /= B
AMOD: A %= B
ARSH: A >>= B
ALSH: A <<= B
AAND: A &= B
AXOR: A ^= B
AOR: A |= B
QUEST: A ? AB : BB
OR: A || B
AND: A && B
BOR: A | B
BXOR: A ^ B
BAND: A & B
EQU: A == B
NEQ: A != B















